Last active
November 17, 2021 16:11
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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