Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How to extract Kubernestes PODS mac addresses from annotations object

$
0
0

I am trying to extract the mac or ips addresses under metadata.annotations using either kubectl get po in json filter or using jq. other objects are easy to manipulate to get those values.

kubectl get po -o json -n multus|jq -r .itemsUnder annotations, there is duplication CNI info but it is ok. I like to extract those MAC addresses using jq. it seems to be tricky on this one.

[  {"apiVersion": "v1","kind": "Pod","metadata": {"annotations": {"k8s.v1.cni.cncf.io/network-status": "[{\n    \"name\": \"eps-cni\",\n    \"ips\": [\n        \"172.31.83.216\"\n    ],\n    \"default\": true,\n    \"dns\": {}\n},{\n    \"name\": \"ipvlan1-busybox1\",\n    \"interface\": \"net1\",\n    \"ips\": [\n        \"172.31.230.70\"\n    ],\n    \"mac\": \"0a:2d:40:c6:f8:ea\",\n    \"dns\": {}\n},{\n    \"name\": \"ipvlan2-busybox1\",\n    \"interface\": \"net2\",\n    \"ips\": [\n        \"172.31.232.70\"\n    ],\n    \"mac\": \"0a:52:8a:62:5d:f4\",\n    \"dns\": {}\n}]","k8s.v1.cni.cncf.io/networks": "ipvlan1-busybox1, ipvlan2-busybox1","k8s.v1.cni.cncf.io/networks-status": "[{\n    \"name\": \"eps-cni\",\n    \"ips\": [\n        \"172.31.83.216\"\n    ],\n    \"default\": true,\n    \"dns\": {}\n},{\n    \"name\": \"ipvlan1-busybox1\",\n    \"interface\": \"net1\",\n    \"ips\": [\n        \"172.31.230.70\"\n    ],\n    \"mac\": \"0a:2d:40:c6:f8:ea\",\n    \"dns\": {}\n},{\n    \"name\": \"ipvlan2-busybox1\",\n    \"interface\": \"net2\",\n    \"ips\": [\n        \"172.31.232.70\"\n    ],\n    \"mac\": \"0a:52:8a:62:5d:f4\",\n    \"dns\": {}\n}]","kubernetes.io/psp": "eps.privileged"      },"creationTimestamp": "2020-05-24T17:09:10Z","generateName": "busybox1-f476958bd-","labels": {"app": "busybox","pod-template-hash": "f476958bd"      },"name": "busybox1-f476958bd-hds4w","namespace": "multus","ownerReferences": [        {"apiVersion": "apps/v1","blockOwnerDeletion": true,"controller": true,"kind": "ReplicaSet","name": "busybox1-f476958bd","uid": "5daf9b52-e1b3-4df7-b5a1-028b48e7fcc0"        }      ],"resourceVersion": "965176","selfLink": "/api/v1/namespaces/multus/pods/busybox1-f476958bd-hds4w","uid": "0051b85d-9774-4f89-8658-f34065222bf0"    },

for basic jq,

[root@ip-172-31-103-214 ~]# kubectl get po -o json -n multus|jq -r '.items[] | .spec.volumes'[  {"name": "test-busybox1-token-f6bdj","secret": {"defaultMode": 420,"secretName": "test-busybox1-token-f6bdj"    }  }]

I can switch the get pod to yaml format then using normal grep cmd.

kubectl get po -o yaml  -n multus|egrep 'mac'|sort -u"mac": "0a:2d:40:c6:f8:ea","mac": "0a:52:8a:62:5d:f4",

Thanks


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>