Skip to content

Instantly share code, notes, and snippets.

@georgettica
Last active November 17, 2021 16:11
Show Gist options
  • Save georgettica/da323a0205a584ceba53ac1b9bb16ba7 to your computer and use it in GitHub Desktop.
Save georgettica/da323a0205a584ceba53ac1b9bb16ba7 to your computer and use it in GitHub Desktop.
recieve the pods from a deployment (useful for commands that need the pod names)
#!/bin/bash
set -eEuo pipefail
ns= # deployment namespace
name= # deployment name
# shellcheck disable=SC2016
deploy_pod_labels_raw=$(kubectl get --namespace "${ns}" deployments.apps/"${name}" --output go-template='{{ range $k, $v :=.spec.selector.matchLabels }}{{$k}}={{$v}},{{ end }}')
deploy_pod_labels=$(echo "${deploy_pod_labels_raw}" | rev | cut --delimiter=',' --fields='2-' | rev)
kubectl get --namespace "${ns}" pod --selector "${deploy_pod_labels}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment