The need for advanced Kubernetes resources
In the last chapter, we looked at pods, the basic building blocks of Kubernetes that provide everything for your containers to run within a Kubernetes environment. However, pods on their own are not that effective. The reason is that while they define a container application and its specification, they do not replicate, auto-heal, or maintain a particular state. When you delete a pod, the pod is gone. You cannot maintain multiple versions of your code or roll out and roll back releases using a pod. You also cannot autoscale your application with traffic with pods alone. Pods do not allow you to expose your containers to the outside world, and they do not provide traffic management capabilities such as load balancing, content and path-based routing, storing persistent data to externally attached storage, and so on. To solve these problems, Kubernetes provides us with specific advanced resources, such as Deployments, Services, Ingresses, PersistentVolumes and claims, and StatefulSets. Let’s start with Kubernetes Deployments in the next section.
Kubernetes Deployments
Let’s understand Kubernetes Deployments using a simple analogy.
Imagine you’re a chef preparing a particular dish in your kitchen. You want to make sure that it is consistently perfect every time you serve it, and you want to be able to change the recipe without causing a chaotic mess.
In the world of Kubernetes, a “Deployment” is like your sous chef. It helps you create and manage copies of your pods effortlessly.
Here’s how it works:
- Creating consistency: You want to serve your dish to many guests. Therefore, instead of cooking each plate separately, you prepare a bunch of them at once. All of them should taste the same and strictly as intended. A Kubernetes Deployment does the same for your pod. It creates multiple identical copies of your pod, ensuring they all have the same setup.
- Updating safely: Now, imagine you have a new twist for your dish. You want to try it out, but you want your guests only to eat something if it turns out right. Similarly, when you want to update your app in Kubernetes, the Deployment resource slowly and carefully replaces old copies with new ones individually, so your app is always available, and your guests (or users) don’t notice any hiccups.
- Rolling back gracefully: Sometimes, experiments don’t go as planned, and you must revert to the original recipe. Just as in your kitchen, Kubernetes lets you roll back to the previous version of your pod if things don’t work out with the new one.
- Scaling easily: Imagine your restaurant suddenly gets a rush of customers, and you need more plates for your special dish. A Kubernetes Deployment helps with that, too. It can quickly create more copies of your pod to handle the increased demand and remove them when things quieten down.
- Managing multiple kitchens: If you have multiple restaurants, you’d want your signature dish to taste the same in all of them. Similarly, if you’re using Kubernetes across different environments such as testing, development, and production, Deployments help keep things consistent.
In essence, Kubernetes Deployments help manage your pod, like a sous chef manages the dishes served from a kitchen. They ensure consistency, safety, and flexibility, ensuring your application runs smoothly and can be updated without causing a mess in your software kitchen .
Container application Deployments within Kubernetes are done through Deployment resources. Deployment resources employ ReplicaSet resources behind the scenes, so it would be good to look at ReplicaSet resources before we move on to understand Deployment resources.