Look at a real-world example of Kubernetes Services.
Although everything you’ve learned so far is cool and interesting, the important questions are: How does it bring value? and How does it keep businesses running and make them more agile and resilient?
Let’s take a minute to run through a common real-world example: making updates to applications.
We all know that updating applications is a fact of life – bug fixes, new features, performance improvements, etc.
The figure below shows a simple application deployed on a Kubernetes cluster as a bunch of Pods managed by a Deployment. As part of it, there’s a Service selecting on Pods with labels that match app=biz1
and zone=prod
(notice how the Pods have both of the labels listed in the label selector). The application is up and running.
Now, assume you need to push a new version, but you need to do it without causing downtime. To do this, you can add Pods running the new version of the app as shown in the figure below.
Behind the scenes, the updated Pods are labeled so that they match the existing label selector. The Service is now load balancing requests across both versions of the app (version=4.1
and version=4.2
). This happens because the Service’s label selector is being constantly evaluated, and its Endpoint object is constantly being updated with new matching Pods.
Once you’re happy with the updated version, forcing all traffic to use it is as simple as updating the Service’s label selector to include the label version=4.2
. Suddenly, the older Pods no longer match, and the Service will only forward traffic to the new version given in the figure below.
However, the old version still exists, you’re just not sending traffic to it anymore. This means that if you experience an issue with the new version, you can switch back to the previous version by simply changing the label selector on the Service to select on version=4.1
instead of version=4.2
like shown in the figure below.
Now everybody’s getting the old version.
This functionality can be used for all kinds of things – blue-greens, canaries, you name it. So simple, yet so powerful.
Clean up the lab with the following commands. These will delete the Deployments and Services used in the examples.
$ kubectl delete -f deploy.yml$ kubectl delete -f svc.yml
Get hands-on with 1400+ tech skills courses.