Adding kubernetes
component to a devfile
This section describes how to add a kubernetes
component to a devfile. A complex component type that allows to apply configuration from a list of Kubernetes or OpenShift components.
-
Define a component using the type
kubernetes
. -
The content can be provided through the
reference
attribute, which points to the file with the component content.Example 1. Addingkubernetes
component using thereference
attributecomponents: - name: mysql kubernetes: reference: petclinic.yaml selector: app.kubernetes.io/name: mysql app.kubernetes.io/component: database app.kubernetes.io/part-of: petclinic
-
Alternatively, to post a devfile with such components to REST API, the contents of the Kubernetes or OpenShift list can be embedded into the devfile using the
referenceContent
field:Example 2. Addingkubernetes
component using thereferenceContent
attributecomponents: - name: mysql kubernetes: reference: petclinic.yaml referenceContent: | kind: List items: - apiVersion: v1 kind: Pod metadata: name: ws spec: containers: ... etc
-
Overriding container entrypoints. As with the
container
component, it is possible to override the entrypoint of the containers contained in the Kubernetes or OpenShift list using thecommand
andargs
properties (as understood by Kubernetes).There can be more containers in the list (contained in Pods or Pod templates of deployments). It is therefore necessary to select which containers to apply the entrypoint changes to as follows:
Example 3. Overriding container entrypointscomponents: - name: appDeployment kubernetes: reference: app-deployment.yaml entrypoints: - parentName: mysqlServer command: ['sleep'] args: ['infinity'] - parentSelector: app: prometheus args: ['-f', '/opt/app/prometheus-config.yaml']
The
entrypoints
list contains constraints for picking the containers along with thecommand
andargs
parameters to apply to them. In the example above, the constraint isparentName: mysqlServer
, which will cause the command to be applied to all containers defined in any parent object calledmysqlServer
. The parent object is assumed to be a top level object in the list defined in the referenced file, which isapp-deployment.yaml
in the example above.Other types of constraints (and their combinations) are possible:
containerName
-
the name of the container
parentName
-
the name of the parent object that (indirectly) contains the containers to override
parentSelector
-
the set of labels the parent object needs to have
A combination of these constraints can be used to precisely locate the containers inside the referenced Kubernetes list.
-
Overriding container environment variables
To provision or override entrypoints in a Kubernetes or OpensShift component, configure it in the following way:
Example 4. Overriding container environment variablescomponents: - name: appDeployment kubernetes: reference: app-deployment.yaml env: - name: ENV_VAR value: value
This is useful for temporary content or without access to editing the referenced content. The specified environment variables are provisioned into each init container and containers inside all Pods and Deployments.
-
Specifying mount-source option
To specify a project sources directory mount into container(s), use the
mountSources
parameter:Example 5. Specifying mount-source optioncomponents: - name: appDeployment kubernetes: reference: app-deployment.yaml mountSources: true
If enabled, project sources mounts will be applied to every container of the given component. This parameter is also applicable for
plugin
type components.