Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: How to pass pipe character in readiness probe command

I am having an issue with passing a pipe character | in readiness probe command.

I want to have a probe command:

curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{\"status\"\:\"UP\".*}$'

Here is how I have defined the probe:

# kubectl get pod my_pod -o yaml

readinessProbe:
  exec:
    command:
    - curl
    - --silent
    - http://localhost:8080/actuator/health
    - '|'
    - grep
    - --quiet
    - -e
    - '''^{\"status\"\:\"UP\".*}$'''

Readiness probe fails with a message:

Readiness probe failed: curl: option --quiet: is unknown curl: try 'curl --help' or 'curl --manual' for more information

The error can be reproduce when command is executed without pipe character |:

curl --silent http://localhost:8080/actuator/health grep --quiet -e '^{\"status\"\:\"UP\".*}$'

For some reason pipe is not interpreted by Kubernetes.

Can you please help me with passing pipe in deployment?

like image 589
Michal Foksa Avatar asked Nov 19 '19 10:11

Michal Foksa


People also ask

How do you check readiness probe in Kubernetes?

There is no separate endpoint for readiness probes, but we can access events using the kubectl describe pods <POD_NAME> command, for example, to get the current status. Use kubectl get pods command to see the pods' status. Pods and their status and ready states will be displayed, our pod is running as expected.

How do you fix a readiness probe failure?

To increase the readiness probe failure threshold, configure the Managed controller item and update the value of "Readiness Failure Threshold". By default, it is set to 100 (100 times). You may increase it to, for example, 300 .

What happens if your application failed the readiness probe?

If the readiness probe fails, the endpoints controller removes the Pod's IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure . If a container does not provide a readiness probe, the default state is Success .

What is difference between readiness and liveness probe in Kubernetes?

Readiness probes are configured similarly to liveness probes. The only difference is that you use the readinessProbe field instead of the livenessProbe field. Configuration for HTTP and TCP readiness probes also remains identical to liveness probes.


1 Answers

Kubernetes doesn't run a shell to process commands on its own; it just runs them directly. The closest equivalent in a shell would be

curl '--silent' 'http://...' '|' 'grep' ...

That is, | here doesn't split two separate commands, because that's shell syntax; without a shell it becomes another parameter to curl, as do all of the words after it.

You need to provide the shell wrapper yourself:

readinessProbe:
  exec:
    command:
      - sh
      - -c
      - curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{\"status\"\:\"UP\".*}$'

You can use alternate YAML syntax to make this a little more readable. (> means to fold following lines into a single string; - means to strip leading and trailing whitespace.

readinessProbe:
  exec:
    command:
      - sh
      - -c
      - >-
         curl --silent http://localhost:8080/actuator/health |
         grep --quiet -e '^{\"status\"\:\"UP\".*}$'
like image 70
David Maze Avatar answered Oct 18 '22 11:10

David Maze