Skip to content

Latest commit

 

History

History
93 lines (78 loc) · 3.67 KB

health-checks.adoc

File metadata and controls

93 lines (78 loc) · 3.67 KB

Health Checks

Duration: 10:00

During rolling update, a pod is removed as soon as a newer version of pod is up and ready to serve. By default, without health checks, Kubernetes will route traffic to the new pod as soon as the pods starts. But, it’s most likely that your application will take sometime to start, and if you route traffic to the application that isn’t ready to serve, your users (and/or consuming services) will see errors. To avoid this, Kubernetes comes with two types of checks: Liveness Probe, and Readiness Probe.

After a container starts, it is not marked as Healthy until the Liveness Probe succeeds. However, if the number of Liveness Probe failures exceeds a configurable failure threshold, Kubernetes will mark the pod unhealthy and attempt to restart the pod.

When a pod is Healthy doesn’t mean it’s ready to serve. You may want to warm up requests/cache, and/or transfer state from other instances. You can further mark when the pod is Ready to serve by using a Readiness Probe.

Let’s add a Liveness Probe to our Helloworld Service by editing the ReplicationController:

[vagrant@rhel-cdk kubernetes]$ kubectl edit rc helloworld-service-vertx

In the editor, add a Liveness Probe:

apiVersion: v1
kind: ReplicationController
…​
spec:
…​
  template:
    …​
    spec:
      …​
      containers:
      - image: rafabene/microservices-helloworld-vertx:…​
        livenessProbe:
          initialDelaySeconds: 5
          timeoutSeconds: 1
          httpGet:
            path: /api/hello/Kubernetes
            port: 8080
      …​
Note
You can configure both Liveness Probe and Readiness Probe by checking via a HTTP GET request, a HTTPS GET request, TCP port connectivity, or even a shell script! See the Liveness and Readiness guide for more information.

You can add a Readiness Probe in the similar way:

[vagrant@rhel-cdk kubernetes]$ kubectl edit rc helloworld-service-vertx

In the editor, add a Readiness Probe:

apiVersion: v1
kind: ReplicationController
…​
spec:
…​
  template:
    …​
    spec:
      …​
      containers:
      - image: rafabene/microservices-helloworld-vertx:…​
        readinessProbe:
          initialDelaySeconds: 5
          timeoutSeconds: 1
          httpGet:
            path: /api/hello/Kubernetes
            port: 8080
      …​
Note
In a production scenario, the Liveness Probe and the Readiness Probe will probably be different REST endpoints or scripts.
Important
Since we modified the template of the ReplicationController, only the new created Pods will have a health check associated to them.