Self-healing Applications

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

A self-healing application in the context of Kubernetes:

  • Automatically recovers containers from an unhealthy state
  • Ensures at least a single copy of the application is running at all times
  • Maintain a consistent network identity

Users can create a simple self-healing application using a controller to maintain a desired state (at least one running pod) and a service to maintain a consistent network identity in the face of pod deletion/recreation.

$ kubectl create deploy apache-prod --image httpd

deployment.apps/apache-prod created

$ kubectl expose deploy apache-prod --port 80

service/apache-prod exposed

$

This creates a Deployment, which ensures at least a single copy of the application runs at all times and a Service that maintains the consistent network identity.

A liveness probe configured in the Deployment spec provides the pod’s managing kubelet with a way to check if the application is alive.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: apache-prod
  name: apache-prod
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: apache-prod
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: apache-prod
    spec:
      containers:
      - image: httpd
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 1
          httpGet:
            path: /
            port: 80
            scheme: HTTP
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: httpd
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always

If this probe’s livenessProbe ever returns a failure, the kubelet tells the container runtime to restart the container and bring the application back from an unhealthy state.

Learn more about: