<p>I'm trying to run remotely a kubernetes command using python and ssh. The command doesn't work if is run remote, but works if is run directly on the machine.</p>

<pre><code>"kubectl get po --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\t"}{.metadata.labels.k8s-app}{"\n"}{end}"
</code></pre>

<p>If it runs as it is, the recive error is </p>

<blockquote>
  <p><code>"Pods [NotFound] .items[*]}"</code></p>
</blockquote>

<p>If I replace <code>'</code> with <code>"</code> and viceversa the eror is "- </p>

<blockquote>
  <p>Expecting 'EOF'</p>
</blockquote>

<p>Taking in consideration that the command run on machine directly, something is interpreted when is passed remotely to the shell. I tried different combination but are not working.</p>

user3541631
<p>Posting this as community wiki <br></p>

<p>As @Orion pointed in comments it seems that your command is not full. I've tested it on mine GKE cluster.</p>

<pre><code>$ kubectl get po --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].
image}{"\t"}{.metadata.labels.k8s-app}{"\n"}{end}
&gt;
</code></pre>

<p>When you used <code>jsonpath=</code> you started it with sign <code>'</code>, however you did not close it. That's why Kubernetes is still expecting some values.
However, if you will end <code>jasonpath</code> with <code>'</code> you will receive output like:</p>

<pre><code>$ kubectl get po --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].
image}{"\t"}{.metadata.labels.k8s-app}{"\n"}{end}'
event-exporter-v0.2.4-5f88c66fb7-xwwh6  k8s.gcr.io/event-exporter:v0.2.4        event-exporter
fluentd-gcp-scaler-59b7b75cd7-pw9kf     k8s.gcr.io/fluentd-gcp-scaler:0.5.2     fluentd-gcp-scaler
fluentd-gcp-v3.2.0-6lxd9        gcr.io/stackdriver-agents/stackdriver-logging-agent:1.6.8       fluentd-gcp
fluentd-gcp-v3.2.0-zhtds        gcr.io/stackdriver-agents/stackdriver-logging-agent:1.6.8       fluentd-gcp
heapster-v1.6.1-9bbcd7f79-ld4z7 gcr.io/stackdriver-agents/heapster-amd64:v1.6.1 heapster
kube-dns-6987857fdb-l2dt8       k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.13       kube-dns
kube-dns-6987857fdb-r97b8       k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.13       kube-dns
kube-dns-autoscaler-bb58c6784-8vq5d     k8s.gcr.io/cluster-proportional-autoscaler-amd64:1.3.0  kube-dns-autoscaler
kube-proxy-gke-stc1-default-pool-094e5c74-6vk4  k8s.gcr.io/kube-proxy:v1.13.7-gke.8
kube-proxy-gke-stc1-default-pool-094e5c74-htr0  k8s.gcr.io/kube-proxy:v1.13.7-gke.8
l7-default-backend-fd59995cd-xz72d      k8s.gcr.io/defaultbackend-amd64:1.5     glbc
metrics-server-v0.3.1-57c75779f-t2rfb   k8s.gcr.io/metrics-server-amd64:v0.3.1  metrics-server
prometheus-to-sd-2jxr5  k8s.gcr.io/prometheus-to-sd:v0.5.2      prometheus-to-sd
prometheus-to-sd-xmfsl  k8s.gcr.io/prometheus-to-sd:v0.5.2      prometheus-to-sd
</code></pre>

<p>As you want to run exact command remotely you have to use <code>"</code> at beginning and the end, same with <code>jsonpatch</code>.</p>

<p>Based on information you have provided, solution for your problem should be below command:</p>

<pre><code>"kubectl get po --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\t"}{.metadata.labels.k8s-app}{"\n"}{end}'"
</code></pre>
