Skip to main content

Performing a Rolling Update of an Application in Kubernetes

Hands-On Lab

 

Photo of Chad Crowell

Chad Crowell

DevOps Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

In this hands-on lab, you will be presented with a three-node cluster. You will need to deploy your application, so you can begin serving your end users. You will deploy the image from linuxacademycontent/kubeserve:v1 and then verify the deployment was successful. Once your application is running and serving clients, you will perform a rolling update, making sure the rollout is successful and there is no downtime for your end users. You will make use of the kubectl command line tool to perform all operations, in combination with the set image command to perform the rolling update to the new version. When you have verified the end users are now using version 2 of the app versus version 1, you may consider this hands-on lab complete.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Performing a Rolling Update of an Application in Kubernetes

In 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:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: kubeserve
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: kubeserve
      template:
        metadata:
          name: kubeserve
          labels:
            app: kubeserve
        spec:
          containers:
          - image: linuxacademycontent/kubeserve:v1
            name: app
  2. Create the deployment:

    kubectl apply -f kubeserve-deployment.yaml --record
  3. Verify the deployment was successful:

    kubectl rollout status deployments kubeserve
  4. 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!