1

kubectl exec does not work with xargs. may be am missing right syntax.

I have like 10 nodes to pull the container info.. like run command as cat /etc/nginx/nginx.conf but my first command itself is failing.

kubectl get nodes -l nodeGroup=test -o wide | awk '{print $1}' | xargs -l1 -- sh -c 'kubectl exec -ti -n kube-system nginx-proxy-$1 sh' --

OR

kubectl get nodes -l nodeGroup=test -o wide | awk '{print $1}' | xargs -l1 -- sh -c 'kubectl exec -ti -n kube-system nginx-proxy-$1 /bin/bash' --

output:

Unable to use a TTY - input is not a terminal or the right kind of file

when i run the same individually, it works. any hint how to loop over it with xargs am using same terminal. below works but above with xargs does not.

▶ kubectl exec -ti -n kube-system                nginx-proxy-node1 sh
# 

AhmFM
  • 1,552
  • 3
  • 23
  • 53

1 Answers1

1

Instead of

... | xargs -l1 -- sh -c 'kubectl exec -ti -n kube-system nginx-proxy-$1 sh' --

Try this

... | xargs -I{} -- sh -c 'kubectl exec -ti -n kube-system nginx-proxy-{} sh' --
LeadingEdger
  • 604
  • 4
  • 7
  • `Unable to use a TTY - input is not a terminal or the right kind of file` still the error – AhmFM Jul 06 '20 at 17:43
  • See https://stackoverflow.com/questions/60826194/kubectl-exec-fails-with-the-error-unable-to-use-a-tty-input-is-not-a-terminal – LeadingEdger Jul 06 '20 at 18:06