mkHun
mkHun

Reputation: 5927

How to give the input for the kubectl command?

Actually I am trying to make the following command in one command

kubectl get pods| grep -oP 'mag[^\s]+'

output
mag121111

After that I will run the following command

kubectl exec -itmag121111 bash

Now I am trying as following

 kubectl get pods| grep -oP 'mag[^\s]+' | kubectl exec -it bash

Upvotes: 1

Views: 997

Answers (4)

Harsimranjit Singh Kler
Harsimranjit Singh Kler

Reputation: 2302

This works for me

kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --container magname -- /bin/bash

here magname is actual pod name

Upvotes: 1

Ijaz Ahmad
Ijaz Ahmad

Reputation: 12100

kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --/bin/bash

OR

kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --bash

Upvotes: 1

Dinesh Balasubramanian
Dinesh Balasubramanian

Reputation: 21728

You can use kube-fzf. It makes exec into a pod(container) and portforward super easy.

Refer this for execpod

Upvotes: 1

Harsh Manvar
Harsh Manvar

Reputation: 30093

kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') -- /bin/bash

Upvotes: 1

Related Questions