To exec into a container in a pod, I use the following two commands (note the template
flag in the first command trims the output to print just the name of the pods):
$ kubectl get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}'
app-api-6421cdf4fd-x9tbk
app-worker-432f86f54-fknxw
app-frontend-87dd65d49c-6b4mn
app-rabbit-413632c874-s2ptw
$ kubectl exec -it app-api-6421cdf4fd-x9tbk -- bash
It would be nice to exec into the container without having to discover the random guid at the end of the pod name every single time. How can I do this?
You can exec into a pod using the deployment
You can use the following command:
kubectl exec -it deploy/<deployment-name> -- bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With