Kubernetes is a sophisticated cluster operating system that supports many ops tasks out of the box. The aim of this video is to show how Kubernetes deployments can be scaled horizontally, and how rolling updates can be performed easily.
- So, in this final video, we're going to talk about scaling deployments and performing rolling updates in Kubernetes. So, in this video we're going to take a look at Scaling, our go microservice deployment horizontally, up and down. And I'm going to show you how we can perform a rolling update of Kubernetes deployment to, well, deploy an updated version of our Go Microservice. So let's get started then.
So you remember, in the last video I showed you how you can write the deployment Yaml descriptor. So this is basically what it looks like. And I've extended it with a few additional things, which are important later. I've added the revision history limit, which basically tells Kuberneretes to keep how long the history should be for our rolling updates. I specified the min ready seconds, those take for a service to come up and when it's considered healthy.
Here I specified the scratitude when updating to rolling update with a few additional. So let's switch to our console again. So first of all, we need to deploy our deployment again. And in the second video, or in the second console in the left hand side. So we're going to watch for any pod changes, okay? So I'm going to issue the create command with our Q control and pass it the option minus minus record equals true.
So every change now is recorded in your history. So let's do that. So you see on the left hand side, two new parts are created, you see container created, you see them running and now they're healthy and running. So the finalist of all the parts should be two running parts now in our Cloud Native Go Microservice.
Good. So, let's assumed we want to scale our Microservice to maybe five instances because we expect additional load. So let's see how we do that. Well, we used the Q control command again. So Q control scale deployment cloud native go minus minus replicas equals five. So we expect Kubernetes to launch three new part instances, right? So let's see if it does that.
So on the left hand side, you see that there are three new containers in created. Now they're running, but not ready yet. And now they should all three be running soon. So that's it then. So let's get the full list of parts. So you see here, we said five replicas and as expected, we have five pods running.
Great! Now, let's assume we want to scale down again. You say Q control scale deployment maybe replicas three, so we wanted to reduce it by two. So again we issue this command. And on the left hand side you already see that two pods are being terminated. Don't forget the list of pods here. So you still have five in the list, but two are marked as being status terminating and they should be removed pretty soon from this list.
See here on the left hand side that they're terminating now. Let's see the list of parts again. Now we're down to three. So this is expected. So in case you're interested, we've been changing and I can used the Q control, you can watch at the roll log history. Let's display the roll of history for our cloud native go deployment. So this was the last one we changed and you see here the change caused is basically the last command we issued.
So let's start fresh over here. So this is horizontal scaling. So let's have a look at the services currently being deployed. So you see here, we have the cloud native go service with a note port. So let's open a browser and here we go, you have the response of our go microservice, now let's assume we have some sort of bug in our microservice and we need to update the deploy.
What I've already done is prepared a new docker image with a new version. So you see that coming up here. Currently we have version 101 deployed and what I want to do is deploy 102 and I want to do that in a rolling update fashion. Q control, set image for deployment cloud native go, and I want to set the image, typo, for the container cloud native go, 102.
So on the left hand side, keep watching for those pod changes again, right? So let's issue this one. So it's been updated and now we see here, we have one terminating, two create container creating, third container creating, new container start running and others are terminated again.
Now what exactly is going on under the hood. So first of all, let's have a look at the result. So you see here, there are two other instances that have been terminated and three are running. Now if I go back to my browser and issue a get request, you see that response now changed. So I'm pretty sure that my update worked, right? Now under the hood, quite a few things changed.
And those are the options that changed the behavior. So first of all, we performed the rolling update and what it does is spin up additional pods with the new image and then after some time, once they come up, once they're considered alive, it will then start terminating the old instances with the old image. And basically the max unavailable and max search options, they determine how this process is done. So with max search two, I'll tell it to, well basically, create two more of the new parts and then we'll terminate the old ones.
So if I have a look at this one here, those three running and want to roll back to the previous one, well it's only one simple command, Q control roll out undo deployment cloud native go. And basically what Kubernetes now does, it switches back to the old replica set and starts going back to those old containers, you see it here on the left hand side, container creating, we wait until the new ones are running.
So what we've just done is perform the rolling upgrade, upgraded to a later version and then undid the roll out. Okay, so that was it for rolling updates. We had an overview of the Kubernetes architecture, its main concepts and building blocks. Look how we can create, run, and access pods and containers locally in mini que cluster. We had a look how we can use labels and namespaces in Kubernetes, we wrote the decryptor, we specified liveness and readiness probes as well as CPU and memory constraints, and then finally we scaled our Kubernetes deployment horizontally up and down and we performed some simple rolling update of our deployments while to deploy new go microservice instances with bug fix behavior.
Well, that was it. I hope you liked it. I'll see you soon. Bye-bye. (typing sound)
This course was created and produced by Packt Publishing. We are honored to host this training in our library.
- Implementing Go HTTP Server
- JSON marshalling and unmarshalling of Go structs
- Implementing a simple REST API
- Using Docker workflows and commands
- Building a naïve Docker image
- Running a containerized Go microservice
- Kubernetes architecture and concepts
- Deploying a Go microservice to Kubernetes
- Implementing service descriptors
- Performing rolling updates