Search code examples
kubernetesdatadog

How to use wget with headers in liveness probe in a yaml file in kubernetes?


I am trying to use wget in my liveness probe in Kubernetes. Here is the code:

apiVersion: v1
kind: Pod
metadata:
  namespace: test
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: busybox
    image: busybox
    command:
      - sleep
      - "99999999"
    livenessProbe:
      exec:
        command:
        - wget
        - -O- 
        - --header=
        - "DD-APPLICATION-KEY: abcde"
        - --header= 
        - "DD-API-KEY: a123456"
        - https://api.datadoghq.com/api/v1/monitor/1234567 | grep \"overall_state\":\"OK\"
      initialDelaySeconds: 10
      periodSeconds: 10

But I am facing the following error when I use describe command in the pod:

Liveness probe failed: wget: bad port ' abcde'

My goal is to check an alert in Datadog. If the alert is red the pod will restart.

The wget command works in the terminal. It looks like the YAML file is facing some problems using the headers.


Solution

  • Try this:

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        test: liveness
      name: liveness-exec
    spec:
      containers:
        - name: busybox
          image: busybox
          command:
            - /bin/sh
            - -c
            - |
              while true
              do
                sleep 15s
              done
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - |
                  wget -O- \
                  --header "DD-APPLICATION-KEY: abcde" \
                  --header "DD-API-KEY: a123456" \
                  http://10.0.1.1:8000/api/v1/monitor/1234567 \
                  | grep '"overall_state":"OK"'
            initialDelaySeconds: 10
            periodSeconds: 10
    

    YAML syntax includes pipe (|) for literal block scalar and so incorporating a shell pipe (|) is more complicated.

    An easy out is to use the above syntax for both (!) command's which uses literal block scalars for the shell content.

    I don't have access to DataDog but this should work.