Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Application Deployment (20%)

Deployment Updates

Below is a quick example of creating a deployment and then updating its image. This will force a rolling deployment to start. You can then roll it back.

$ kubectl run nginx --image=nginx  --replicas=3
deployment.apps "nginx" created

Okay, now force a rolling update by updating its image.

$ kubectl set image deploy/nginx nginx=nginx:1.9.1
deployment.apps "nginx" image updated

Now you can check the status of the roll out.

$ kubectl rollout status deploy/nginx
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 2 of 3 updated replicas are available...
deployment "nginx" successfully rolled out

Now, if you want to roll it back:

$ kubectl rollout undo deploy/nginx
$ kubectl rollout status deploy/nginx
Waiting for rollout to finish: 1 old replicas are pending termination...
Waiting for rollout to finish: 2 of 3 updated replicas are available...
deployment "nginx" successfully rolled out

This is all describe well on kubernetes.io by searching for β€˜deployment’ and reading the overview there. Kubernetes Deployments

Kustomize

  • Kustomize is a solution similar to helm. We can create β€œtemplate” kubernetes configs (the base) and then create β€œoverlays” to provide environment-specific configuration values
  • Create a base directory with the templates and an overlays directory with a child directory for each environment
  • No weird templating languages (like handlebars), just pure yaml manifests
β”œβ”€β”€ base
β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”œβ”€β”€ ingress.yaml
β”‚   └── service.yaml
└── overlays
    β”œβ”€β”€ dev
    β”‚   └── spec.yaml
    β”œβ”€β”€ prod
    β”‚   └── spec.yaml
    └── staging
        └── spec.yaml
  • There is a kustomization.yaml file where you can configure kustomze. The kustomize.yaml contains a list of the resources that you want kustomize to manage, the list of cusotmizations (transformations) that you want kustomize to manage (there are MANY). Each child directory can have its own kustomization.yaml file (the β€˜root’ kustomization.yaml file will just have links to the child kustomization.yaml files)
  • After you have updated the kustomize.yaml file, run: kustomize build <directory name>
  • Kustomize does not actually deploy the resources, it just prints them to stdout. You can pipe the kustomize output to kubectl or deploy another way: kustomize build <dirname> | kubectl apply -f -
  • To delete resources created by kustomize, use: kubectl delete -k <dirName>

Tasks from Kubernetes Doc

See also: Application Design and Build β€” Pod Design for labels/selectors/annotations used alongside deployments.