Search code examples
kubernetesdeploymentkubernetes-health-checkkubernetes-deploymentlivenessprobe

Kubernetes liveness probe httpGet schema not working correctly


I am deploying some web app on kubernetes and I want to set liveness probe for this application. When I configure my deployment with liveness probe, kubelet start health check. I was defined httpGet with scheme "HTTP" parameter but kubelet using https schema randomly.

This is my liveness probe configuration:

livenessProbe:
  failureThreshold: 4
  httpGet:
    path: /
    port: 80
    scheme: HTTP
  initialDelaySeconds: 40
  periodSeconds: 5
  successThreshold: 1
  timeoutSeconds: 2

This is result from kubelet:

kubectl describe pod greenlight-7877dc58b7-6s78l

output:

Warning Unhealthy 31s (x4 over 46s) kubelet Liveness probe failed: Get "https://10.244.4.182/": dial tcp 10.244.4.182:443: connect: connection refused

Kubernetes version: v1.19.9

Thanx for help!


Solution

  • Since you are explicitly stating livenessProbe to use HTTP, it's probably your application that redirects traffic to HTTPS. Make sure that your application returns a 200 OK on basepath /, and not a redirection (any of 3xx codes).

    You can either fix that, or use TCP probe

    apiVersion: v1
    kind: Pod
    metadata:
      name: goproxy
      labels:
        app: goproxy
    spec:
      containers:
      - name: goproxy
        image: k8s.gcr.io/goproxy:0.1
        ports:
        - containerPort: 8080
        readinessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 10
        livenessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 15
          periodSeconds: 20