Overview

Deployments, finally we have reached to the last major object in Kubernetes. Deployments take everything we have being doing so far and encapusaltes it. What I mean is the following:

Of course you can have more than 1 pod in replica set. Yes, it is replica set when under Deployment, not replication controller. But the purpose is the same.

So let's create our Deployment now:

Configuration

To create a deployment again we have two ways:

Iterative - With kubectl create and so on

Declarative - Using YML / JSON file, I will be using this one.

As I am bored with the iterative way, let's clean our env and create a deployment. I won't delete my service as I will use it later.

Create Deployment (Declarative)

First, let's create our YML file:

Create Deployment YML file

Bare in mind that the deployment have been moved from extensions/v1beta1 → apps/v1 and forward :) Also a little syntax changes compared to the old one, but nothing serious.

Once we have the YAML file, we can continue as follows:

Create deployment

Again, we can check if our app is working:

Replica Sets

As already mentioned, deployments operate with Replicat Sets, NOT replication Controllers. Eventhough that is a new objects, it inherits a lot of stuff from the replication controller. You can check the Replica sets, almost the same as the replication controller and notice that we don't have Replication Controllers anymore…after I have deleted them in the past of course.

Check Replica Sets

Rolling-Updates

Now, we have deployed application, which is totally scalable and redundancy is provided as Hell :) But what if want to fix couple bugs, or present new version.

What we do then ? Well, let's edit our application, let's add “v2” into our awesome app:

Edit Software

Edit Source

You see that “v2” after “Working”, yes, I just added it now. Let's rebuild via docker, upload it and edit our edition to v2 :) The Rebuild part you can see in the Docker section, but I will put the output here as well:

Dockerize, Tag & Push

Dockerize, Tag & Push

aaaaand….we are done :) We have edited our awesome software and uploaded it to docker hub.

Let's now update the containers in the pods :)

Perform the Update

For that purpose, we have to edit the YAML file with couple more values like:

Strategy: RollingUpdate(default)

maxUnavailable: 1 - Never have more than 1 unavailable

maxSurge: 1 - Never have more than 1 additional. In our case, never have more than 11 pods

So, our YAML file should look as follows:

Updated YAML file

Once we have the file, you can start the process as so:

Rolling Update Status

You can see the progress of the Rolling Update as follows:

Rolling Update Status

We can also check the version which is currently being used:

Rolling Update Status