Components
Adding kubernetes component
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.
Prerequisites
Procedure
Define a component using the type
kubernetes.The content can be provided through the
referenceattribute, which points to the file with the component content.Adding kubernetes component using the reference attribute
devfile.yamlcomponents: - name: mysql kubernetes: reference: petclinic.yaml selector: app.kubernetes.io/name: mysql app.kubernetes.io/component: database app.kubernetes.io/part-of: petclinicAlternatively, 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:Adding kubernetes component using the referenceContent attribute
devfile.yamlcomponents: - name: mysql kubernetes: reference: petclinic.yaml referenceContent: | kind: List items: - apiVersion: v1 kind: Pod metadata: name: ws spec: containers: ... etcOverriding 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:
Overriding container entrypoints
devfile.yamlcomponents: - 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:
containerNamethe name of the containerparentNamethe name of the parent object that (indirectly) contains the containers to overrideparentSelectorthe 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:
Overriding container environment variables
devfile.yamlcomponents: - 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:Specifying mount-source option
devfile.yamlcomponents: - 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.