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
referenceattribute, which points to the file with the component content.Example 1. Addingkubernetescomponent using thereferenceattributecomponents: - 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
referenceContentfield:Example 2. Addingkubernetescomponent using thereferenceContentattributecomponents: - 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
containercomponent, it is possible to override the entrypoint of the containers contained in the Kubernetes or OpenShift list using thecommandandargsproperties (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
entrypointslist contains constraints for picking the containers along with thecommandandargsparameters 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.yamlin 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: valueThis 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
mountSourcesparameter:Example 5. Specifying mount-source optioncomponents: - name: appDeployment kubernetes: reference: app-deployment.yaml mountSources: trueIf enabled, project sources mounts will be applied to every container of the given component. This parameter is also applicable for
plugintype components.