Following on from the previous post, if the code is updated, how do we release the new version to the K8S cluster? Earlier we created a Deployment with K8S. Deployment is very powerful and can specify the image version to implement pods that gradually replace Docker images without stopping.

  1. Update the code, such as updating the input line in server.js tores.send('Hello world222\n');
  2. Rebuild the image and push it to the repository
docker build -t finleyma/express:v2 .
docker push finleyma/express:v2
Copy the code

You can see the image of our new tag named V2 on docker Hub

Use the kubectl set image command to apply a rolling update to an existing Deployment named Express-Demo-Deployment via an image update

Kubectl set image deployment/[deployment name]=[image name :tag name]

kubectl set image deployment/express-demo-deployment express-demo=finleyma/express:v2

Monitor pods health, old pods are deleted and new ones are created, because even the name of pod is changed kubectl get PODs-w

Refresh the page again and the content has changed! The rolling update succeeded.

Deployment is very useful for publishing applications to A K8S cluster, and we can easily roll back to a historical version

Other commands

See kubectl describe Deployment/Express-Demo-Deployment for details

Verify publishing kubectl rollout status Deployment/Express-Demo-Deployment

reference

Kubernetes. IO/useful/docs/con…

Cloud.google.com/kubernetes-…