-1

Below is the Pod resource type for deploying a container:

apiVersion: v1
kind: Pod
metadata:
  name: my-container
  labels:
    app: myapp
    rel: stable
spec:
  containers:
  - name: my-container
    image: myimage:latest
    resources:
      limits:
        memory: "128Mi" #128 MB
        cpu: "200m" #200 millicpu (.2 cpu or 20% of the cpu)
    ports:
    - containerPort: 80
    livenessProbe:
      httpGet:
        path: /health-check
        port: 80
      initialDelaySeconds: 15
      timeoutSeconds: 2 # Default is 1
      periodSeconds: 5 # Default is 10
      failureThreshold: 1 # Default is 3
    readinessProbe:
      httpGet:
        path: /health-check
        port: 80
      initialDelaySeconds: 3
      periodSeconds: 5 # Default is 10
      failureThreshold: 1 # Default is 3

the /health-check end point returns http status 200 status with below json:

{
    "details": {
        "app": {
            "framework": "gin",
            "name": "my-app-local",
            "version": "v1"
        },
        "databases": [
            {
                "database": "my_db",
                "host": "localhost",
                "name": "mysql",
                "status": "Normal"
            }
        ]
    },
    "status": "Normal"
}

Given above Pod yaml, how does kubelet read the status value for "databases" & "app"? as part of livenessProbe or readinessProbe, to ensure container is running fine.

overexchange
  • 15,768
  • 30
  • 152
  • 347

1 Answers1

1

It does not work like that, it checks the return code of http requests. Here is snippet from the documentation(port 80 in this case):

To perform a probe, the kubelet sends an HTTP GET request to the server that is running in the container and listening on port 8080.

If the handler for the server's /healthz path returns a success code, the kubelet considers the container to be alive and healthy. If the handler returns a failure code, the kubelet kills the container and restarts it. Any code greater than or equal to 200 and less than 400 indicates success. Any other code indicates failure

If you really need to read json response,then do curl and use jq or grep to find the status in json response. For jq something like jq '.details.databases[].status'

livenessProbe:
  exec:
    command:
    - sh
    - -c
    - curl --silent http://localhost:80/healthz | grep .......
        
P....
  • 17,421
  • 2
  • 32
  • 52