简体   繁体   中英

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
kubectl exec -it $(kubectl get pods| grep -oP 'mag[^\s]+') --/bin/bash

要么

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

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

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

Refer this for execpod

This works for me

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

here magname is actual pod name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM