Trying to insert output from this:

kubectl get pods | grep -Eo '^[^ ]+' | grep portal

Into this:

kubectl exec -it <here> portal bash


kubectl exec -it `kubectl get pods | grep -Eo '^[^ ]+' | grep portal ` portal bash

But no luck.

  • 3
    What does "no luck" mean? Did you get some kind of error? Does the command in the command substitution return the correct thing? What happens if you use ... -it "$(...)" ... instead of the backticks (quoting is difficult with backticks).
    – Kusalananda
    Jun 13 '19 at 16:18
  • @Kusalananda It says: Defaulting container name to portal-container. Use 'kubectl describe pod/portal-74767c88b-92sct' to see all of the containers in this pod. rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"portal\": executable file not found in $PATH" In both cases
    – Pavel M.
    Jun 13 '19 at 16:37
kubectl exec -it "$(kubectl get pods | grep -Eo '^[^ ]+' | grep portal)" bash

Or, even more:

kubectl exec -c portal-container -it "$(kubectl get pods | grep -Eo '^[^ ]+' | grep portal)" bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.