odo deploy
odo
can be used to deploy components in a similar manner they would be deployed by a CI/CD system,
by first building the images of the containers to deploy, then by deploying the Kubernetes resources
necessary to deploy the components.
When running the command odo deploy
, odo
searches for the default command of kind deploy
in the devfile, and executes this command.
The kind deploy
is supported by the devfile format starting from version 2.2.0.
The deploy
command is typically a composite command, composed of several apply and exec commands:
an
apply
command referencing animage
component that, when applied, will build the image of the container to deploy, and push it to its registry,an
apply
command referencing akubernetes
component that, when applied, will create a Kubernetes resource in the cluster.an
exec
command referencing a container component that, when applied, will run the command defined bycommandLine
inside a container started by a Kubernetes Job; read more about it here.With the following example
devfile.yaml
file, a container image will be built by using theDockerfile
present in the directory, the image will be pushed to its registry and a Kubernetes Deployment will be created in the cluster, using this freshly built image.
schemaVersion: 2.2.0
[...]
variables:
CONTAINER_IMAGE: quay.io/phmartin/myimage
commands:
- id: build-image
apply:
component: outerloop-build
- id: deployk8s
apply:
component: outerloop-deploy
- id: deploy-db
exec:
commandLine: helm repo add bitnami https://charts.bitnami.com/bitnami && helm install my-db bitnami/postgresql
component: tools
- id: deploy
composite:
commands:
- build-image
- deployk8s
- deploy-db
group:
kind: deploy
isDefault: true
components:
- name: outerloop-build
image:
imageName: "{{CONTAINER_IMAGE}}"
dockerfile:
uri: ./Dockerfile
buildContext: ${PROJECTS_ROOT}
- name: outerloop-deploy
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: my-component
spec:
replicas: 1
selector:
matchLabels:
app: node-app
template:
metadata:
labels:
app: node-app
spec:
containers:
- name: main
image: {{CONTAINER_IMAGE}}
- name: tools
container:
image: quay.io/tkral/devbox-demo-devbox
The uri
for the Dockerfile could also be an HTTP or HTTPS URL.
Depending upon the container registry specified in the devfile.yaml
, the access for container image
pushed by odo deploy
may be private by default. For example: images pushed to Quay.io. Change the
image visibility appropriately in order to run odo deploy
successfully.
Running the command
odo deploy
Example
Substituting variables
The Devfile can define variables to make the Devfile parameterizable. The Devfile can define values for these variables, and you
can override the values for variables from the command line when running odo deploy
, using the --var
and --var-file
options.
See Substituting variables in odo
dev for more information.