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
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
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.
Have an update or suggestion for this article? You can edit it here and send me a pull request.