Rolling deployments with Kubernetes
How to deploy a new version of an image into a Kubernetes cluster
In a previous post I worked through getting a Kubernetes cluster up and running on a local machine using minikube. Within this cluster I have one deployment of a simple Hello World Go application.
kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-go 1 1 1 1 1d
How then do you deploy a new image? It is a simple case of updating an image within a deployment.
kubectl set image deployment/hello-go hello-go=shapeshed/hello-go:latest
The status of a rollout can be checked as follows
kubectl set image rollout status deployment/hello-go
Waiting for rollout to finish: 0 of 1 updated replicas are available...
deployment "hello-go" successfully rolled out
If for whatever reason you need to rollback just update the image to an older version.
kubectl setkubectl set image deployment/hello-go hello-go=shapeshed/hello-go:22ee0304
Recording history ¶
Deployment history can be recorded by either adding --record
when a deployment
is created or by adding it to commands that modify a deployment. This provides
details on any amends made to a deployment and the command issued.
kubectl set image deployment/hello-go hello-go=shapeshed/hello-go:latest --record
Now the history of a deployment may be seen
kubctl rollout history deployment hello-go
REVISION CHANGE-CAUSE
1 kubectl set image deployment/hello-go hello-go=shapeshed/hello-go:22ee0304 --record
2 kubectl set image deployment/hello-go hello-go=shapeshed/hello-go:latest --record
A deployment may be rolled back as follows
kubectl rollout undo deployment hello-go
Summary ¶
I have worked with most deployment tools - from FTP to Capistranoto Git post-receive hooks. Kubernetes offers a super simple way to update a deployment that can easily be integrated into Continuous Deployment workflows. Given that it is just containers that are being deployed there is a guaranteed idempotent version of an application. That makes Continuous Deployment far less risky and increases the possibility of shipping code to customers faster. A win all round.
Further reading ¶
- Kubernetes Deployments documentation
- Kubernetes - Rolling updates with deployment
- How to rollout or rollback a deployment on a Kubernetes cluster?
- Rolling Updates and Rollbacks using Kubernetes Deployments
Tags
Can you help make this article better? You can edit it here and send me a pull request.
See Also
-
Getting started with Kubernetes
How to get started with using Kubernetes on a local machine using minikube -
Listening to BBC Radio with mpv
The BBC publishes high quality 320 kbps HLS AAC streams that can be used to listen to radio from the command-line using mpv. Here are the URLs and some aliases to start listening quickly. -
Linux and Unix more command tutorial with examples
Tutorial on using more, a UNIX and Linux command for viewing the contents of a file or files one screen at a time. Examples of viewing a file, viewing multiple files, searching using regular expressions and opening the file in a text editor.