My pods have a dynamically generated ID appended to their names like i.e. my-app-name-7b587cd75b-dscsr
which is different on every deployment (next time it could be my-app-name-xcgv83bfsd-4kjsf
).
This makes using some commands really cumbersome, because every time I need to see the logs I have to list all pods first and copy-paste the changed name to the logs
command: kubectl -n [namespace] logs my-app-name-7b587cd75b-dscsr
.
Is there a way I can skip using the pod name or part of the name and do something like kubectl -n [namespace] logs my-pod-name-~
or kubectl -n [namespace] logs service/my-pod-name
like in port-forward
command?
I tried to inject grep
inside the logs
command to obtain the pod name and run logs
in a single command, but Cmder on Windows, as great as it is, doesn't seem to support $()
: kubectl -n [namespace] logs $(kubectl -n my-app-name get pod | grep my-app-name | sed 's/ .*//')
bash
thing, and it looks like you're Windows. There are several bash shells that run on Windows/WSL. YMMV. – Amitiekubectl logs -f deploy/DEPLOYMENT_NAME
to get the logs of pods – Utimer