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
basedirectory with the templates and anoverlaysdirectory 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.yamlfile where you can configurekustomze. Thekustomize.yamlcontains a list of the resources that you wantkustomizeto manage, the list of cusotmizations (transformations) that you wantkustomizeto manage (there are MANY). Each child directory can have its ownkustomization.yamlfile (the βrootβkustomization.yamlfile will just have links to the childkustomization.yamlfiles) - After you have updated the
kustomize.yamlfile, run:kustomize build <directory name> - Kustomize does not actually deploy the resources, it just prints them to
stdout. You can pipe the kustomize output tokubectlor 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.