<p>I am having an issue with passing a pipe character <code>|</code> in readiness probe command.</p>

<p>I want to have a probe command:</p>

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

<p>Here is how I have defined the probe:</p>

<pre><code># kubectl get pod my_pod -o yaml

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

<p>Readiness probe fails with a message:</p>

<blockquote>
  <p>Readiness probe failed: curl: <strong>option --quiet: is unknown curl</strong>: try 'curl --help' or 'curl --manual' for more information</p>
</blockquote>

<p>The error can be reproduce when command is executed without pipe character <code>|</code>:</p>

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

<p>For some reason pipe is not interpreted by Kubernetes.</p>

<p>Can you please help me with passing pipe in deployment?</p>

<p>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</p>

<pre class="lang-sh prettyprint-override"><code>curl '--silent' 'http://...' '|' 'grep' ...
</code></pre>

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

<p>You need to provide the shell wrapper yourself:</p>

<pre class="lang-yaml prettyprint-override"><code>readinessProbe:
  exec:
    command:
      - sh
      - -c
      - curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{\"status\"\:\"UP\".*}$'
</code></pre>

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

<pre class="lang-yaml prettyprint-override"><code>readinessProbe:
  exec:
    command:
      - sh
      - -c
      - &gt;-
         curl --silent http://localhost:8080/actuator/health |
         grep --quiet -e '^{\"status\"\:\"UP\".*}$'
</code></pre>
