15 April 2019

Running kubectl against pods

playing alone with kubectl commands is not fun unless you introduce shell flavours in it. kubectl is quite a
cool utlity when you roam around in your k8s-cluster but still there are some limitation of it.
like how do you 'exec' to multiple pods in single command of kubectl, well simple answer is NO you cannot. unless you tweak the command to have some shell flavour in it using xargs
kubectl get pods -o name | xargs -I{} kubectl exec {} -- command

fetching first coloumn from output of multiple pods 
kubectl get pods -n ns | grep -v NAME | sed 's/\|/ /'|awk '{print $1}'

refining your output with more specific values use cut with range of characters
kubectl get pods -n ns | grep -v NAME | awk '{print $1}' | cut -c8-14

No comments:

Post a comment