Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl exec into a container without using the random guid at the end of the pod name

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?

like image 754
Johnny Metz Avatar asked Aug 28 '20 03:08

Johnny Metz


1 Answers

You can exec into a pod using the deployment
You can use the following command:

kubectl exec -it deploy/<deployment-name> -- bash
like image 103
Ahmed Akrout Avatar answered Oct 07 '22 04:10

Ahmed Akrout