Finally, we know that no app rules forever; eventually, a new version will replace the old. In our case, say a new version of our hello-node pod is created and we want to use it to replace all of our old pods. Well as we discussed previously, Kubernetes has us covered as we can make this upgrade with no downtime using a rolling update.
As there is no new version of hello-node, this would give an error message if entered.
However, if there were an updated version, you would apply it by entering:
kubectl set image deployments/hello-node hello-node=myContainers/hello-node:v2
To break this down, we first mark that we’d like to set a new image, then specify the type we’re going to adapt, deployments, then which deployment, hello-node. After the first mention of our deployment, we’ve told the command what we’d like to edit, at which point we then provide the new image, myContainers/hello-node:v2.
Kubernetes will then take each of our old pods down one by one and replace them with our upgraded version. This takes a moment and does get longer depending on the number of pods which must be upgraded. To check if the upgrade rollout is successful, we would enter:
kubectl rollout status deployments/hello-node
Which, if completed, would return:
deployment "hello-node" successfully rolled out
With that, we’ve finished our creation and exploration of a Kubernetes basic program. To conclude your masterpiece, now simply enter the two lines:
kubectl delete service hello-node
kubectl delete deployment hello-node
This will clean up your system and leave your system ready for your next Kubernetes project!