Introduction
this is part 40 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.
And I will cover lot of tools as we move on.
Prepare images for this Lab
first let's delete every thing we done so far
kubectl delete deployment myapp-deployment
kubectl delete rs myapp-replicaset
let's recreate a new container from scratch will be hosted on my dockerhub. It's same as old one but now we need to do some edits to the image. here how we can build and push to dockerhub.
I am going to build them as tags 1.0 and 2.0
1.0 is same as old one , 2.0 will have some edits on image.
So we can see how to switch between two versions.
it's not my API so it doesn't have an docker-compose file.
We can add one but meh let's just build it without docker-compose because it's doesn't have a lot to do with it.
if you already have the DevOps folder just pull it and you will get the new files.
if not go and clone the repo
Lab 2
Now after we have our image with tag 1.0 and 2.0 we can start.
You don't need to build them , because I already do they are on my docker hub as public just follow the steps , Kubernetes will download them for you when you run the yml file.
first let's look what we have in the folder of today lab
v1 and v2 contain the source code of the simple-api , v2 have different message than v1 that will shown.
app_040_v1.yml app_040_v2.yml are the Kubernetes configs the only difference between 1 and 2 it's the version in image here a look at v1
let's create our deployment now.
kubectl create -f app_040_v1.yml --record
you know the process from the older part , he going to create 6 pods and...
take a break while the pods are creating
kubectl get pods
all my pods are ready , so we are good to move on
kubectl port-forward deployments/myapp-deployment 8080
this trick will start our app , 8080 is the port we specify in the source code.
Now we can see in browser we have our v1 running.
kubectl apply -f app_040_v2.yml
this is how we update the version from v1 to v2
kubectl describe deployments myapp-deployment
here we can see we have the new version 2.0
kubectl port-forward deployments/myapp-deployment 8080
now let's go to browser and refresh our page and see what happens.
voila we have now the v2 live!
little talk about DevOps
I edit the app in this lab , the moment between the commit and the customer see the updates is the DevOps Engineer. In advanced parts when we push our code all those stuff will be automated , it's called Contentious Integration and Contentious Delivery as shortcut CI/CD.
In our case the task will be after commit he will send the version to the docker hub then Kubernetes will handle the new image.
The automation here will be described in a script written by you (the DevOps).
Basically this is the core of the DevOps.
Back to lab
let's say now we don't like this version we need to roll back to v1.
let's look at the history and decide what we need to rollback
kubectl rollout history deployment/myapp-deployment
I need the revision 1 , so I will go back to it using :
kubectl rollout undo deployment/myapp-deployment --to-revision 1
now let's check what version it is
kubectl describe deployments myapp-deployment
here we can see now the version is back to 1
kubectl port-forward deployments/myapp-deployment 8080
now let's go to browser and refresh our page and see what happens.
It's the old version again!
Top comments (0)