<p>I am trying to use a heredoc to create a resource in Kubernetes as follows:</p>
<pre><code>cat &lt;&lt;EOF | kubectl apply -f -
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: max-pods
spec:
  validationFailureAction: audit
  background: false
  rules:
    - name: restrict-pod-count
      match:
        resources:
          kinds:
            - Pod
      context:
        - name: podcounts
          apiCall:
            urlPath: &quot;/api/v1/pods&quot;
            jmesPath: &quot;items[?spec.nodeName=='minikube'] | length(@)&quot;
      preconditions:
        any:
        - key: &quot;{{ request.operation }}&quot;
          operator: Equals
          value: &quot;CREATE&quot;
      validate:
        message: &quot;A maximum of 10 Pods are allowed on the Node `minikube`&quot;
        deny:
          conditions:
            any:
            - key: &quot;{{ podcounts }}&quot;
              operator: GreaterThan
              value: 10
EOF
</code></pre>
<p>If I write the YAML in a file and run <code>kubectl apply -f file.yaml</code>, it works as intended. But when I use it as shown above, it says:</p>
<pre><code>error: error parsing STDIN: error converting YAML to JSON: yaml: line 69: did not find expected '-' indicator
</code></pre>
<p>I am not extremely familiar with heredocs, so there should be something I am missing, but the error does not help me (the file does not have 69 lines...)</p>

Gaëtan
<p>Your validate.message contains an expression that would be expanded in the heredocs. You need to escape that like this:</p>
<pre><code>[...]
      message: &quot;A maximum of 10 Pods are allowed on the Node \`minikube\`&quot;
[...]
</code></pre>
<p>You could also use the heredoc delimiter with single quotes to disable the expansion. With that you could use your original version.</p>
<pre><code>cat &lt;&lt;'EOF' | kubectl apply -f -
[...]
EOF
</code></pre>
