Skip to content

Instantly share code, notes, and snippets.

@kv109
Created June 22, 2018 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kv109/2cade0131f8c177308dd01d4e97986b3 to your computer and use it in GitHub Desktop.
Save kv109/2cade0131f8c177308dd01d4e97986b3 to your computer and use it in GitHub Desktop.
export pod names in kubernetes
  1. Create a export-pod-name.sh file with the following content:
POD_NAME=$(kubectl get pods --sort-by=.metadata.creationTimestamp --selector=YOUR-SELECTOR-KEY=YOUR-SELECTOR-VALUE -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | tail -n1)
# Example:
# POD_NAME=$(kubectl get pods --sort-by=.metadata.creationTimestamp --selector=app=nginx -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | tail -n1)

export POD_NAME=$POD_NAME
  1. Run script (notice the dot at the beginning!)
. export-pod-name.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment