Skip to content

Instantly share code, notes, and snippets.

@tillig
Last active July 9, 2019 22:16
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 tillig/2b4fcb13c94abd5ef17aa727f41fe040 to your computer and use it in GitHub Desktop.
Save tillig/2b4fcb13c94abd5ef17aa727f41fe040 to your computer and use it in GitHub Desktop.
Helpful snippets for working with kubectl

Queries

Get all pod names in a namespace:

kubectl get pods -n mynamespace -o jsonpath='{.items..metadata.name}'

Delete

Delete all running pods in a namespace:

kubectl delete pod $(kubectl get pods -n mynamespace -o jsonpath='{.items..metadata.name}') -n mynamespace

Operations

Get a shell in a running container

kubectl exec -it pod-name -n pod-namespace -- /bin/bash

Get a shell in the first pod for a given app

kubectl exec -it $(kubectl get pods -n pod-namespace -l=app=my-app -o jsonpath='{.items[0]..metadata.name}') -n pod-namespace -- /bin/bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment