Health Checking of Istio Services

Kubernetes liveness and readiness probes describes several ways to configure liveness and readiness probes:

  1. Command
  2. HTTP request
  3. TCP probe
  4. gRPC probe

The command approach works with no changes required, but HTTP requests, TCP probes, and gRPC probes require Istio to make changes to the pod configuration.

The health check requests to the liveness-http service are sent by Kubelet. This becomes a problem when mutual TLS is enabled, because the Kubelet does not have an Istio issued certificate. Therefore the health check requests will fail.

TCP probe checks need special handling, because Istio redirects all incoming traffic into the sidecar, and so all TCP ports appear open. The Kubelet simply checks if some process is listening on the specified port, and so the probe will always succeed as long as the sidecar is running.

Istio solves both these problems by rewriting the application PodSpec readiness/liveness probe, so that the probe request is sent to the sidecar agent.

Liveness probe rewrite example

To demonstrate how the readiness/liveness probe is rewritten at the application PodSpec level, let us use the liveness-http-same-port sample.

First create and label a namespace for the example:

  1. $ kubectl create namespace istio-io-health-rewrite
  2. $ kubectl label namespace istio-io-health-rewrite istio-injection=enabled

And deploy the sample application:

  1. $ kubectl apply -f - <<EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: liveness-http
  6. namespace: istio-io-health-rewrite
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: liveness-http
  11. version: v1
  12. template:
  13. metadata:
  14. labels:
  15. app: liveness-http
  16. version: v1
  17. spec:
  18. containers:
  19. - name: liveness-http
  20. image: docker.io/istio/health:example
  21. ports:
  22. - containerPort: 8001
  23. livenessProbe:
  24. httpGet:
  25. path: /foo
  26. port: 8001
  27. initialDelaySeconds: 5
  28. periodSeconds: 5
  29. EOF

Once deployed, you can inspect the pod’s application container to see the changed path:

  1. $ kubectl get pod "$LIVENESS_POD" -n istio-io-health-rewrite -o json | jq '.spec.containers[0].livenessProbe.httpGet'
  2. {
  3. "path": "/app-health/liveness-http/livez",
  4. "port": 15020,
  5. "scheme": "HTTP"
  6. }

The original livenessProbe path is now mapped against the new path in the sidecar container environment variable ISTIO_KUBE_APP_PROBERS:

  1. $ kubectl get pod "$LIVENESS_POD" -n istio-io-health-rewrite -o=jsonpath="{.spec.containers[1].env[?(@.name=='ISTIO_KUBE_APP_PROBERS')]}"
  2. {
  3. "name":"ISTIO_KUBE_APP_PROBERS",
  4. "value":"{\"/app-health/liveness-http/livez\":{\"httpGet\":{\"path\":\"/foo\",\"port\":8001,\"scheme\":\"HTTP\"},\"timeoutSeconds\":1}}"
  5. }

For HTTP and gRPC requests, the sidecar agent redirects the request to the application and strips the response body, only returning the response code. For TCP probes, the sidecar agent will then do the port check while avoiding the traffic redirection.

The rewriting of problematic probes is enabled by default in all built-in Istio configuration profiles but can be disabled as described below.

Liveness and readiness probes using the command approach

Istio provides a liveness sample that implements this approach. To demonstrate it working with mutual TLS enabled, first create a namespace for the example:

  1. $ kubectl create ns istio-io-health

To configure strict mutual TLS, run:

  1. $ kubectl apply -f - <<EOF
  2. apiVersion: security.istio.io/v1beta1
  3. kind: PeerAuthentication
  4. metadata:
  5. name: "default"
  6. namespace: "istio-io-health"
  7. spec:
  8. mtls:
  9. mode: STRICT
  10. EOF

Next, change directory to the root of the Istio installation and run the following command to deploy the sample service:

Zip

  1. $ kubectl -n istio-io-health apply -f <(istioctl kube-inject -f @samples/health-check/liveness-command.yaml@)

To confirm that the liveness probes are working, check the status of the sample pod to verify that it is running.

  1. $ kubectl -n istio-io-health get pod
  2. NAME READY STATUS RESTARTS AGE
  3. liveness-6857c8775f-zdv9r 2/2 Running 0 4m

Liveness and readiness probes using the HTTP, TCP, and gRPC approach

As stated previously, Istio uses probe rewrite to implement HTTP, TCP, and gRPC probes by default. You can disable this feature either for specific pods, or globally.

Disable the probe rewrite for a pod

You can annotate the pod with sidecar.istio.io/rewriteAppHTTPProbers: "false" to disable the probe rewrite option. Make sure you add the annotation to the pod resource because it will be ignored anywhere else (for example, on an enclosing deployment resource).

  1. kubectl apply -f - <<EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: liveness-http
  6. spec:
  7. selector:
  8. matchLabels:
  9. app: liveness-http
  10. version: v1
  11. template:
  12. metadata:
  13. labels:
  14. app: liveness-http
  15. version: v1
  16. annotations:
  17. sidecar.istio.io/rewriteAppHTTPProbers: "false"
  18. spec:
  19. containers:
  20. - name: liveness-http
  21. image: docker.io/istio/health:example
  22. ports:
  23. - containerPort: 8001
  24. livenessProbe:
  25. httpGet:
  26. path: /foo
  27. port: 8001
  28. initialDelaySeconds: 5
  29. periodSeconds: 5
  30. EOF
  1. kubectl apply -f - <<EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: liveness-grpc
  6. spec:
  7. selector:
  8. matchLabels:
  9. app: liveness-grpc
  10. version: v1
  11. template:
  12. metadata:
  13. labels:
  14. app: liveness-grpc
  15. version: v1
  16. annotations:
  17. sidecar.istio.io/rewriteAppHTTPProbers: "false"
  18. spec:
  19. containers:
  20. - name: etcd
  21. image: registry.k8s.io/etcd:3.5.1-0
  22. command: ["--listen-client-urls", "http://0.0.0.0:2379", "--advertise-client-urls", "http://127.0.0.1:2379", "--log-level", "debug"]
  23. ports:
  24. - containerPort: 2379
  25. livenessProbe:
  26. grpc:
  27. port: 2379
  28. initialDelaySeconds: 10
  29. periodSeconds: 5
  30. EOF

This approach allows you to disable the health check probe rewrite gradually on individual deployments, without reinstalling Istio.

Disable the probe rewrite globally

Install Istio using --set values.sidecarInjectorWebhook.rewriteAppHTTPProbe=false to disable the probe rewrite globally. Alternatively, update the configuration map for the Istio sidecar injector:

  1. $ kubectl get cm istio-sidecar-injector -n istio-system -o yaml | sed -e 's/"rewriteAppHTTPProbe": true/"rewriteAppHTTPProbe": false/' | kubectl apply -f -

Cleanup

Remove the namespaces used for the examples:

  1. $ kubectl delete ns istio-io-health istio-io-health-rewrite