Building Self-Healing Containers in Kubernetes

30 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Kubernetes offers several features that can be used together to create self-healing applications in a variety of scenarios. In this lab, you will be able to practice your skills at using features such as probes and restart policies to create a container application that is automatically healed when it stops working.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Set a Restart Policy to Restart the Container When It Is Down

Find the beebox-shipping-data pod located in the default namespace. Modify this pod so its restartPolicy will restart the container whenever it fails.

Note: You may need to delete and re-create the pod in order to make this change.

Create a Liveness Probe to Detect When the Application Has Crashed

Add a liveness probe to the container that checks the container status by making an HTTP request to the container every 5 seconds. The request should check the / (root) path on port 8080.

Note: You may need to delete and re-create the pod in order to make this change.

Additional Resources

You are working for BeeBox, a company that provides regular shipments of bees to customers. The company is in the process of deploying some applications to Kubernetes that handle data processing related to shipping.

One of these application components is a pod called beebox-shipping-data located in the default namespace. Unfortunately, the application running in this pod has been crashing repeatedly. While the developers are looking into why this application is crashing, you have been asked to implement a self-healing solution in Kubernetes to quickly recover whenever the application crashes.

Luckily, the application can be fixed when it crashes simply by restarting the container. Modify the pod configuration so the application will automatically restart when it crashes. You can detect an application crash when requests to port 8080 on the container return an HTTP 500 status code.

Note: The kubeclt --export no longer works in the lab environment. An alternative would be:

kubectl get pod beebox-shipping-data -o yaml > beebox-shipping-data.yml

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?