We saw that when a pod dies, either because we manually kill it or because something unexpected happens, Kubernetes will not automatically reschedule it.
That’s one of the reasons why we will almost never run pods directly. We will almost always want to manage pods with another Kubernetes resource called Deployment. Other than making sure our pods are rescheduled when they die, deployments will also help us with several other things:
We can use deployments to scale our applications by increasing or decreasing the number of replicas we have running. So far, we have only run one replica of our application.
Deployments can handle the rollout of new versions of our application, so we can go from v1 to v2 without any downtime.
They also allow us to easily rollback bad releases, as well as preventing bad releases from going through altogether (in some cases).
Before we start talking about how Deployments work, let’s take a look at the application we will run.
So far, we have only used the nginx image because it was super simple and convenient to demonstrate how to run an application in Kubernetes.
Now we are going to run our own application so we can more easily control different versions and introduce the behavior we want to test our use cases.
I wrote this very simple application in Ruby, but you can change it if you want and use any other tool you prefer. As long as it’s packaged as a docker image, everything will work the same way.
Here’s the application code: