1

I am new to Kubernetes. I have written a deployment for my python console application. this app is subscribed to NATS (message queue).

I have written command in liveness prob to check the connection_id(my app connection id) in the nats server is present. otherwise, restart the pod as the application is not running properly, in that case.

I have tried different commands. for example

        livenessProbe:
          exec:
            command:
            - sh
            - -c
            #- curl -s nats:8222/connz?cid=$(cat /tmp/cid) | python3 -c "import sys, json; print(json.load(sys.stdin)['connections'][0]['cid'])" | echo

            #- curl -s http://nats:8222/connz?cid=$(cat /tmp/cid) | grep "$(cat /tmp/cid)"
            - curl -s http://nats:8222/connz?cid=$(cat /tmp/cid) | grep "cid"
          initialDelaySeconds: 10
          periodSeconds: 10

and another few curl commands. then when I remove /tmp/cid file. it should fail, right? But it does not.

If I run this command curl -s http://nats:8222/connz?cid=$(cat /tmp/cid) | grep -c "\"cid\": $(cat /tmp/cid)"

I get io.k8s.api.core.v1.ExecAction.command: got "map", expected "string" this issue.

Any suggestion?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Sazzad
  • 773
  • 11
  • 22
  • one problem i got with the previous curl commands is when cid does not match nats give the full response. so grep cid always succeed. – Sazzad Aug 21 '20 at 05:55
  • 1
    `|` will not work in exec. You can read more by `k explain pod.spec.containers.livenessProbe.exec`. Can you post your complete yaml and what's the exit status when you hit `curl -s http://nats:8222/connz?cid=` from within the container shell? – Saurabh Aug 21 '20 at 06:10
  • but pipe worked. – Sazzad Aug 21 '20 at 06:42

1 Answers1

2
curl -s http://localhost:8222/connz?cid=$(cat /tmp/cid) | grep -c "cid.* $(cat /tmp/cid),"

This finally worked for me.

Stuck with the issue for 2 days :(

Ezequiel Muns
  • 7,492
  • 33
  • 57
Sazzad
  • 773
  • 11
  • 22