Kubernetes liveness probe: webhook notification on failure

11/5/2019

I'm running a Kubernetes cluster on Google cloud. My cluster has a deployment that exposing the health-check interface (over HTTP). In my deployment yaml file, I configured:

livenessProbe:
  # an http probe
  httpGet:
    path: /hc
    port: 80
    scheme: HTTP
  initialDelaySeconds: 30
  timeoutSeconds: 60
  periodSeconds: 90

If my health check endpoint return anything but 200, the pod will be killed and restarted.

Currently, after pod restart, it just counts it on the "restart" counter but not notify anyone. I want to notify the sysadmin that this event has happened. I thought to notify with a webhook.

Is this possible? If not, what is my other notification alternative?

-- No1Lives4Ever
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

11/5/2019

The somewhat convoluted standard answer to this is Kubernetes -> kube-state-metrics -> Prometheus -> alertmanager -> webhook. This might sound like a lot for a simple task, but Prometheus and its related tools are used much more broadly for metrics and alerting. If you wanted a more narrow answer, you could check out Brigade perhaps? But probably just use kube-prometheus (which is Prom with a bunch of related components all setup for you).

-- coderanger
Source: StackOverflow

11/5/2019

You can add a preStop hook to your pod spec. The hook can either run a script or make an HTTP call before the pod shuts down. You can configure the hook to call an API which triggers a notification.

-- Patrick W
Source: StackOverflow