<p>I have the following <code>configmap</code> where I want to retrieve the IPs using jsonpath how can that be done?</p>
<pre><code>apiVersion: v1
data:
  domain.yaml: |
    dns:
      - 127.0.0.1
      - 127.0.0.2
</code></pre>
<p>I have tried the following which does not work: <code>kubectl get cm domain -o jsonpath={.domain.yaml.dns[0]}</code></p>

user3580316
<p>this is not quite simple, as the</p>
<pre><code>dns:
- 127.0.0.1
- 127.0.0.2
</code></pre>
<p>is interpreted as a single json value.</p>
<p>for example <code>kubectl get cm testcm -o jsonpath='{.data}'</code> returns the following output <code>{&quot;domain.yaml&quot;:&quot;dns:\n  - 127.0.0.1\n  - 127.0.0.2\n&quot;}</code>
as you can see it has &quot;domain.yaml&quot; as key, and the rest is a simple string value.</p>
<p>in order to get the ips, we can use jq and cut magic. For example</p>
<pre><code>kubectl get cm testcm -o jsonpath='{.data.*}' | cut -d$'\n' -f2 | sed 's/  - //g' 
</code></pre>
<p>would return <code>127.0.0.1</code></p>
