kubectl: Getting the pod name in a subshell for use in commands
What I learned today — 28 May 2018
1 min readMay 28, 2018
Pods are ephemeral, and if you have a command you need to run often, or something you want to check into a wiki, you can avoid first getting the pod name by using labels and a jsonpath
output to get it in a sub-shell.
In this example I get the logs of my Team City server based on the pod labels:
kubectl logs $(kubectl get pods -lapp=teamcity,type=server --output jsonpath='{.items[0].metadata.name}') --since 5m -f