Skip to content

Core templates

What are Core templates?

You can create and use custom Core templates for your use cases.

With this feature, you will be able to customize the resources generated by Core to achieve your needs, creating some baselines that the users can use for their projects. For example, you could:

  • Set custom requests and limits
  • Harden the securityContext
  • Add tolerations for GPU usage

Templates can be used as profiles when creating pods, deployments, services and secrets with Core.

Create a template

In order to be used, the templates must be specified in a ConfigMap in the form of values of a key, while the key should be the name of the template file that will be mounted in Core.

Be aware that you must create and apply the ConfigMap yourself.

You can specify multiple templates in the form of key: value (filename: template) in the same ConfigMap.

The following is an example of a template for Core:

apiVersion: v1
kind: ConfigMap
metadata:
  name: core-templates
data:
  template-example.yaml: |-   # Name of the template file
    id: template1   
    name: template1
    description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In imperdiet lectus arcu, eget mattis dui varius vitae. Morbi lorem augue, volutpat nec mi sagittis, vulputate congue ligula. Maecenas ac luctus mauris. Ut maximus est convallis nisi porta, vel sodales lorem dictum. Praesent ullamcorper enim accumsan diam pharetra feugiat. Integer maximus tortor et nulla fermentum commodo. In vitae massa nec leo fermentum interdum. Integer consectetur dolor vitae accumsan vulputate. Curabitur placerat suscipit justo tempor placerat. Nam euismod suscipit ante non sollicitudin. Integer at cursus sem.
    runtimeClass: class1
    priorityClass: class1
    envs:
      - name: ENV1
        value: VALU123123
      - name: ENV2
        value: VALU123123    
    ---
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: pi
    spec:
      template:
        spec:
          containers:
            - name: pi
              image: perl:5.34.0
              command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
          restartPolicy: Never
      backoffLimit: 4

template-example.yaml is the key, and it is the name of the template file that will be mounted in Core. The actual template is the value of template-example.yaml, so, in this case:

id: template1   
name: template1
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In imperdiet lectus arcu, eget mattis dui varius vitae. Morbi lorem augue, volutpat nec mi sagittis, vulputate congue ligula. Maecenas ac luctus mauris. Ut maximus est convallis nisi porta, vel sodales lorem dictum. Praesent ullamcorper enim accumsan diam pharetra feugiat. Integer maximus tortor et nulla fermentum commodo. In vitae massa nec leo fermentum interdum. Integer consectetur dolor vitae accumsan vulputate. Curabitur placerat suscipit justo tempor placerat. Nam euismod suscipit ante non sollicitudin. Integer at cursus sem.
runtimeClass: class1
priorityClass: class1
envs:
  - name: ENV1
    value: VALU123123
  - name: ENV2
    value: VALU123123    
---
apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
        - name: pi
          image: perl:5.34.0
          command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4

As you can see, the template in the above example is composed of two parts:

  • The upper part (that will be refered to as Profile)
  • The bottom part (that will be refered to as Base Template)

The template merge process is mainly done in three steps:

1) The Base Template is used as the starting point for the resource (in this case, a Job). This part can be modified by the user.

2) Core appends it's own configuration to the resource

3) The Profile is applied, adding the specified fields to the resource; as a result, the job will have the runtimeClass, priorityClass and two variables specified in the Profile. This part cannot be modified by the user.

If you wish so, you can also decide to use a Profile without the Base Template if you want to set just certain values (for example, resources or tolerations).

Setting templates in the Values.yaml file

The following is a reference for the configuration of Core Templates in the Values.yaml file:

core:
  templates:   # Every item in the list must match a template you have created.
    - name: template-example
      path: /templates/template-example.yaml
  volumeMounts:
    - name:  templates
      mountPath:  /templates   # Directory in Core in which the template files will be saved
  volumes:
    - name:  templates   # Volume for the templates
      configMap:
        name: core-templates   # Must match the ConfigMap containing the templates

Now you can create resources with your template and profile from Core.

Supported fields

The following is a list of all the fields that you can set in the Profile section. You can find an in depth explanation of how to set these fields in the documentation about Kubernetes Resources

Field Format
envs List
secrets List
resources Object
volumes List
nodeSelector List
affinity Object
tolerations List
runtimeClass String
priorityClass String
imagePullPolicy String