By now you saw some examples by Kubernetes
and letting Kubernetes manage deployments
for us could be useful.
Now let me show you how we could actually change our code
and update our deployment, and then even roll back
to another of deployment if we wanted to
because it's really, really easy.
Let's say we changed our source code here
and I have more exclamation marks and a new paragraph.
This is new like this new, like this
So I changed my source code and I saved that file.
Now, of course, we need to rebuild our image.
This doesn't change.
That's always the case because our code is in the image.
And if our container somewhere, no matter
on which machine should be updated
the image needs to be updated first.
So I will update my academind/kub-first app image
with Docker build by rebuilding it
and using that latest source code.
And now we want to update our deployment to
take this new image this updated image into account.
To update, a deployment, lets first of all,
check whether the deployment is still there.
Yes, it is this first step deployment here.
And to update it
we can now run the cube control set command
and we can run it with image to set a new image
for a specific deployment by targeting deployment slash
and then the name of your deployment in my case first app.
So with that
I'm saying Kubernedes that I want to set a new image
for a deployment, and after the slash
the name of the deployment,
this is the syntax for updating an image.
But of course
we now need to let Kuberenetes know what our new image is.
Of course you could say
well, we specify that when we created the deployment
of course, it should always use the same image,
and whilst this could be a logic you use
it would also be pretty unflexible.
If you ever want to switch
to a different image with a different name
or a different tech, you couldn't do that.
That's why now in addition to what you wrote thus far,
we need to let kubernetes know which current container
and image to update with which future image.
So for that we use the current container name, which
in case you're not sure you can
find in this web console it's kub-first app.
So simply the image name we used before.
So kub first app
and we set this now equal to the new image we want to use,
and that would be academind/kub-first app of course.
Now of course, just like before this will pull the image
from Docker hub, so first of all,
we need to push our updated image to Docker hub
with Docker push.
So we built the image now we need to push it,
and once that pushing finished, we can run the command
I just showed you.
So it is finished, now execute cube control set image
deployment/first app old image name=new image,
this will update the deployment.
Now, once you executed this command
if you get your deployments though
you'll not notice any difference here,
and if you visit your application
you'll also not notice any difference here.
Now, the reason for that is
that actually new images will only be downloaded
if they have a different tech.
Now, there are ways of changing this,
but it is a good idea to update your tags
and kind of version your images anyways
once you are working with a production setup,
so therefore what do you want to do here
is when we build our image
with Docker build command, we want to give it a tag
and it could simply be an incrementing version number.
So let's now give it version two, for example.
So I have column two after my name.
Now we can push this new image with that tag at the end
and now this latest image version will be pushed
to my repository. With that done,
we can repeat this set image command, to kub control
set image command, and now specify this tag at the end.
So column two here, this will now ensure
that Kubernetes detects that it's a different tag
and used before, and it will then re download this image
and restart your containers based on that.
So now you can see, we get this image updated confirmation.
You can view the current updating status
by executing kub control, rollout status deployment/
and then the name of your deployment in our case first app.
And you'll see here, it was rolled out successfully.
And if you go back to your browser and you reload here
maybe not immediately,
but after some time you should see the updated output here.
And if you go to your Kubernetes dashboard here
and you have a look at your pods
and you inspect this pod here
under events, you can see that this new image was polled
and that a new container was created, based on that image.
You can also see that
this is the image we're currently using here.
So that's how we could now update the image,
and therefore the source code
off a container running as part of a pod managed
by Kubernedes with this kub control set image command.
Just keep in mind that you need to change your text
to trigger kubernetes, to re download the image.