1
votes

I am trying to enable Readiness probe on my deployment yaml file as below but I am getting Readiness probe failed: HTTP probe failed with statuscode: 401, I verified by decoding the secret and my authorization code is correct.

spec:
  containers:
  - name: mycontainer
    image: myimage
    env:
      - name: MY_SECRET
        valueFrom:
          secretKeyRef:
            name: actuator-token
            key: token
    livenessProbe:
        httpGet:
          path: test/actuator/health
          port: 9001
          httpHeaders:
          - name: Authorization
            value: $MY_SECRET

UPDATES

If I hardcode the token in value field.. it works fine.

Any help is highly appreciated.

1
Once refrence for you to look at .. dimitr.im/spring-boot-kubernetes And can you confirm how you created the secret .. steps you have used to define the secret and also verify what is the actual value for env varaibe MY_SECRET when pod is running .. - DT.
could you show the output of kubectl get secrets actuator-token -o yaml. By the way, what's the kubernetes version? - BMW

1 Answers

1
votes

The secret is only accessible inside the container, so the usual liveness probe (which is run from within a k8s internal container) can't resolve this, read up here.

One workaround is to run your livenessProbe as a command in the pod itself:

 livenessProbe:
    exec:
      command:
      - bash 
      - "-c" 
      - | 
        curl http://localhost:9001/test/actuator/health --header "Authorization: $MY_TOKEN"

you may need to mess around with the curl syntax to get it working properly