Setting up Self-Healing Apps in Kubernetes

1.5 hours
  • 2 Learning Objectives

About this Hands-on Lab

Kubernetes includes powerful features for building self-healing application clusters. By default, if the application running in a container crashes completely, Kubernetes will automatically restart the container. However, application health can be more complicated than simply whether or not an application process is still running. This activity will guide you through the process of building more sophisticated problem detection for an app running on Kubernetes. That will allow you to strengthen the self-healing capabilities of your application infrastructure on Kubernetes.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set up a Jenkins Project for the App and Deploy It to the Kubernetes Cluster

To do this, you will need to do the following:

  • Fork the GitHub source code at https://github.com/linuxacademy/cicd-pipeline-train-schedule-selfhealing.
  • Set up credentials in Jenkins for GitHub, Docker Hub, and the Kubernetes cluster.
  • Create a project to build from your GitHub fork, run a build, and approve production deployment to deploy the app to the cluster.
Create and Deploy a Liveness Probe to Detect Error Responses from the App and Restart Unhealthy Containers

To do this, you will need to do the following:

  • Modify the Kubernetes template in your GitHub fork to add a liveness probe.
    livenessProbe:
    httpGet:
    path: /
    port: 8080
    initialDelaySeconds: 15
    timeoutSeconds: 1
    periodSeconds: 10

    Check the example-solution branch of the GitHub repo for an example of how this code can be used: https://github.com/linuxacademy/cicd-pipeline-train-schedule-selfhealing/blob/example-solution/train-schedule-kube.yml.

  • Deploy the application again by running a build and approving the deployment.
  • Test the probe by breaking the app and watching Kubernetes automatically restart the container.

Additional Resources

Your team has built a continuous delivery process for the train schedule app. They are using a Jenkins pipeline to deploy the app to a Kubernetes cluster. However, a few recent deployments have caused problems for the app. App containers are periodically entering an unhealthy state which causes the application to return HTTP 500 errors to users.

The team has asked you to address this problem by implementing some behavior to allow Kubernetes to detect when a container has become unhealthy so the container can be automatically restarted.

To do this, you will need to do the following:

Set up a Jenkins project for the app and deploy it to the Kubernetes cluster:

  • Fork the GitHub source code at https://github.com/linuxacademy/cicd-pipeline-train-schedule-selfhealing.
  • Set up credentials in Jenkins for GitHub, Docker Hub, and the Kubernetes cluster.
  • Create a project to build from your GitHub fork, run a build, and approve production deployment to deploy the app to the cluster.

Create and deploy a liveness probe to detect error responses from the app and restart unhealthy containers:

  • Modify the Kubernetes template in your GitHub fork to add a liveness probe.
  • Deploy the application again by running a build and approving the deployment.
  • Test the probe by breaking the app and watching Kubernetes automatically restart the container.

Note: The train-schedule app includes an endpoint designed to simulate the app becoming unhealthy so that you can trigger an instance of the app to break at will. Once deployed, if you access that endpoint in your browser at <Kubernetes Node Public IP>:8080/break, all future requests to that container will return 500 error codes until it is restarted. You can use this to test self-healing functionality once you have implemented it.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?