You are on page 1of 4

Performing a Rolling Update of an

Application in Kubernetes
n this hands-on lab, we have been given a three-node cluster. Within that cluster, we
must deploy our application and then successfully update the application to a new
version without causing any downtime.

Log in to the Kube Master server using the credentials on the lab page (either in your
local terminal, using the Instant Terminal feature, or using the public IPs), and work
through the objectives listed.

Create and roll out version 1 of the application, and verify a successful deployment.

1. Use the following YAML named kubeserve-deployment.yaml to create your


deployment:
2. apiVersion: apps/v1
3. kind: Deployment
4. metadata:
5. name: kubeserve
6. spec:
7. replicas: 3
8. selector:
9. matchLabels:
10. app: kubeserve
11. template:
12. metadata:
13. name: kubeserve
14. labels:
15. app: kubeserve
16. spec:
17. containers:
18. - image: linuxacademycontent/kubeserve:v1
name: app

19. Create the deployment:

kubectl apply -f kubeserve-deployment.yaml --record

20. Verify the deployment was successful:

kubectl rollout status deployments kubeserve

21. Verify the app is at the correct version:

kubectl describe deployment kubeserve


Scale up the application to create high availability.

1. Scale up your application to five replicas:

kubectl scale deployment kubeserve --replicas=5


2. Verify the additional replicas have been created:

kubectl get pods


Create a service, so users can access the application.

1. Create a service for your deployment:

kubectl expose deployment kubeserve --port 80 --target-port 80


--type NodePort

2. Verify the service is present, and collect the cluster IP:

kubectl get services

3. Verify the service is responding:

curl http://<ip-address-of-the-service>
Perform a rolling update to version 2 of the application, and verify its success.

1. Start another terminal session to the same Kube Master server. There, use this
curl loop command to see the version change as you perform the rolling update:

while true; do curl http://<ip-address-of-the-service>; done

2. Perform the update in the original terminal session (while the curl loop is
running in the new terminal session):

kubectl set image deployments/kubeserve


app=linuxacademycontent/kubeserve:v2 --v 6

3. View the additional ReplicaSet created during the update:

kubectl get replicasets

4. Verify all pods are up and running:

kubectl get pods

5. View the rollout history:

kubectl rollout history deployment kubeserve


Conclusion

Congratulations on completing this lab!


Additional Information and Resources

You have been given a three-node cluster. Within that cluster, you must deploy your
application and then successfully update the application to a new version without
causing any downtime. You will use the image linuxacademycontent/kubeserve:v1,
which will serve as your application. You must perform the steps to verify your app
successfully rolled out initially; create a service for your deployment, so it can be used
by the end user; and then perform the update, verifying that the update did not
experience any service interruption for your end users. You must perform the following
tasks in order to complete this hands-on lab:

 Create and roll out a deployment, and verify the deployment was successful.
 Verify the application is using the correct version.
 Scale up your application to create high availability.
 Create a service from your deployment, so users can access your application.
 Perform a rolling update to version 2 of the application.
 Verify the app is now at version 2 and there was no downtime to end users.

Learning Objectives
check_circleCreate and roll out version 1 of the application, and verify a successful
deployment.keyboard_arrow_up

1. Use the following YAML named kubeserve-deployment.yaml to create your


deployment:
2. apiVersion: apps/v1
3. kind: Deployment
4. metadata:
5. name: kubeserve
6. spec:
7. replicas: 3
8. selector:
9. matchLabels:
10. app: kubeserve
11. template:
12. metadata:
13. name: kubeserve
14. labels:
15. app: kubeserve
16. spec:
17. containers:
18. - image: linuxacademycontent/kubeserve:v1
name: app

19. Use the following command to create the deployment:

kubectl apply -f kubeserve-deployment.yaml --record

20. Use the following command to verify the deployment was successful:

kubectl rollout status deployments kubeserve


21. Use the following command to verify the app is at the correct version:

kubectl describe deployment kubeserve


check_circleScale up the application to create high availability.keyboard_arrow_up

1. Use the following command to scale up your application to five replicas:

kubectl scale deployment kubeserve --replicas=5

2. Use the following command to verify the additional replicas have been created:

kubectl get pods


check_circleCreate a service, so users can access the application.keyboard_arrow_up

1. Use the following command to create a service for your deployment:

kubectl expose deployment kubeserve --port 80 --target-port 80


--type NodePort

2. Use the following command to verify the service is present and collect the
cluster IP:

kubectl get services

3. Use the following command to verify the service is responding:

curl http://<ip-address-of-the-service>
check_circlePerform a rolling update to version 2 of the application, and verify its
success.keyboard_arrow_up

1. Use this curl loop command to see the version change as you perform the rolling
update:

while true; do curl http://<ip-address-of-the-service>; done

2. Use this command to perform the update (while the curl loop is running):

kubectl set image deployments/kubeserve


app=linuxacademycontent/kubeserve:v2 --v 6

3. Use this command to view the additional ReplicaSet created during the update:

kubectl get replicasets

4. Use this command to verify all pods are up and running:

kubectl get pods

5. Use this command to view the rollout history:

kubectl rollout history deployment kubeserve

You might also like