Created
September 10, 2026 17:41
-
-
Save mrgreyves/863eb52d60c5b20e1197fa5c7e236ce7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # | |
| # find-exec-probes.sh | |
| # | |
| # Находит все поды (во всех namespace или в указанном), у которых | |
| # есть хотя бы одна exec-проба (livenessProbe, readinessProbe или | |
| # startupProbe с exec.command) в любом контейнере (включая init-контейнеры). | |
| # | |
| # Использование: | |
| # ./find-exec-probes.sh # все namespace | |
| # ./find-exec-probes.sh -n my-ns # конкретный namespace | |
| # ./find-exec-probes.sh -A # явно все namespace (по умолчанию так и есть) | |
| set -euo pipefail | |
| NAMESPACE_ARGS=(--all-namespaces) | |
| while getopts ":n:A" opt; do | |
| case "$opt" in | |
| n) NAMESPACE_ARGS=(-n "$OPTARG") ;; | |
| A) NAMESPACE_ARGS=(--all-namespaces) ;; | |
| *) echo "Usage: $0 [-n namespace | -A]" >&2; exit 1 ;; | |
| esac | |
| done | |
| command -v kubectl >/dev/null 2>&1 || { echo "kubectl не найден в PATH" >&2; exit 1; } | |
| command -v jq >/dev/null 2>&1 || { echo "jq не найден в PATH" >&2; exit 1; } | |
| kubectl get pods "${NAMESPACE_ARGS[@]}" -o json | jq -r ' | |
| .items[] | |
| | . as $pod | |
| | ( | |
| ($pod.spec.containers // []) | |
| + ($pod.spec.initContainers // []) | |
| + ($pod.spec.ephemeralContainers // []) | |
| ) as $containers | |
| | ($containers[] | |
| | select( | |
| (.livenessProbe.exec.command? != null) or | |
| (.readinessProbe.exec.command? != null) or | |
| (.startupProbe.exec.command? != null) | |
| ) | |
| | .name | |
| ) as $cname | |
| | "\($pod.metadata.namespace)\t\($pod.metadata.name)\t\($cname)" | |
| ' | sort -u | awk 'BEGIN { | |
| printf "%-25s %-45s %s\n", "NAMESPACE", "POD", "CONTAINER" | |
| printf "%-25s %-45s %s\n", "---------", "---", "---------" | |
| } | |
| { | |
| printf "%-25s %-45s %s\n", $1, $2, $3 | |
| }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment