In this lab, we're going to look at rolling updates and rollbacks.
Rolling updates mainly.
I'm going forward.
I'm going to try and use the alias K for kubectl.
I've already set alias K for kubectl, so I'm going to try
and use that going forward.
We have deployed a simple web application.
Inspect the PODs and services.
Let's do
get POD,
so there seems to be a set of frontend PODs.
Most likely there is a deployment.
There's a frontend deployment, which deploys for PODs.
Then wait for the application to fully deploy and view the application
using the link called Webapp Portal.
There is a link here you can click to view the application
and opens it up in a new window.
It just says, "Hello frontend.”
A moment.
Let's look at the first or second question.
What is the current color of the web application?
If you look here, it is blue in color.
It's blue.
Now, run the script named curl-test to send multiple requests
to the web application.
We have curl-test here, so I'll run that.
As you can see, all it does is it paints the application
and returns to color.
The color is blue, and it just keeps running that
for a few seconds.
That's done.
We're going to use this script to run tests to simulate accessing
the web application by either multiple users
or sending multiple requests to the web application.
We'll use that to basically just do a small round of tests on the application.
Inspect the deployment and identify the number
of PODs deployed by it.
We just looked at that and we saw that it creates four PODs.
It's four, that's the answer here.
Now, what container image is used to deploy the application?
Let's look at the deployment
in more detail
and frontend.
Here we have the POD template.
We have containers, image.
The image is kodekloud/webapp-color:V1.
It's this one right here.
That's the image we've used to deploy the application.
Inspect the deployment and identify the current strategy.
If you look at this, we have the strategy type given here,
and that is rolling update.
The rolling update is the current strategy.
If you were to upgrade the application now
one POD at a time
and brings up the new POD.
It does not take all of it down and bring the new ones up.
Answer here is all PODs are taken down before upgrading.
No, that's not the correct one.
PODs are upgraded a few at a time, so that's the correct one.
Let us try that.
Upgrade the application by setting the image on the deployment
to kodekloud/webapp-color:v2.
We're going to update the image.
Now, one way to do that is you could do kubectl edit
and deployment and frontend,
and then go here and change the image.
Another way to do that is just using the kubectl set command.
You could do a set image, run the help to find that out.
That's kubectl set image.
You can say deployment, deployment name,
and then the container name, and the image.
Let's try that.
That's kubectl set image or the deployment.
The deployment name is frontend and the container name,
we need to find out the container name.
Let's do deploy frontend.
The container name is simple-webapp.
Let's do that again.
Kubectl set image, deploy, frontend,
container name
is simple-webapp
equals
test image, and that's updated.
Let's make sure it's updated.
I'm going to describe command again when we see that the image is set to v2.
Success.
Let's run the curl test again and see what we're seeing.
We're still seeing blue but we see green occasionally.
There's a lot of blue and there's some green.
Green is the new version that we have deployed
and blue is the older version and now we have a lot of green.
If you look at this, there was a lot of blue at first
and then there's some green, and then there's green and blue
at one point of time.
Then we just have green.
That's how it's updated, the application deployment.
That's the rolling update.
Up to how many PODs can be down for upgrade at a time?
Consider the current strategy settings.
If you look at this, the strategy type is rolling update
which we've already seen.
There's rolling update strategy, the additional details here.
25% max unavailable.
That means it's going to take down
only 25% of the PODs at a time before bringing the new ones up.
You have four replicas,
and 25% of that is just one.
Let's select one.
Change the deployment strategy to Recreate.
Delete and re-create the deployment if necessary.
Let's go ahead and try and change the deployment strategy.
Let's do a kubectl edit,
deployment, frontend.
We'll just go here and we'll just change
this strategy type to Recreate.
The Recreate does not require the rolling update parameter,
so we're just going to get rid of this.
Let's verify.
We see the strategy is changed to Recreate.
The next one is to upgrade the application by setting the image
on the deployment to v3.
Currently, we have v2
and we have got to change it to v3.
Let's use the same command, the kubectl set image deploy command,
and we'll now change this to 3.
Okay, so that's updated.
Next, let's run the curl-test again.
When we run this this time, unlike the previous time,
we see a lot of failures.
Some of the requests are failing
and this is because it took down
some of the PODs as part of the upgrade
because we're doing a recreate.
Let's just give it some time.
If you look at the application here,
it says, "Bad gateway.”
Now we can see it started to respond.
We have the red color is coming up and when we refresh this,
you see that we have application v3 and the red color is coming up.
Okay, so that's the end of this lab.