Created
April 15, 2022 12:25
-
-
Save veyselsahin/0484de4d6e21b2ec55d81bb563b19edd to your computer and use it in GitHub Desktop.
kubernetes_export.sh kubernetes_context namespace
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
#!/usr/bin/env bash | |
set -e | |
CONTEXT="$1" | |
if [[ -z ${CONTEXT} ]]; then | |
echo "Usage: $0 KUBE-CONTEXT" | |
exit 1 | |
fi | |
NAMESPACES="$2" | |
RESOURCES="configmap secret" | |
#RESOURCES="configmap secret daemonset deployment service hpa" | |
for ns in ${NAMESPACES};do | |
for resource in ${RESOURCES};do | |
rsrcs=$(kubectl --context ${CONTEXT} -n ${ns} get -o json ${resource}|jq '.items[].metadata.name'|sed "s/\"//g") | |
for r in ${rsrcs};do | |
dir="${CONTEXT}/${ns}/${resource}" | |
mkdir -p "${dir}" | |
kubectl --context ${CONTEXT} -n ${ns} get -o yaml ${resource} ${r} > "${dir}/${r}.yaml" | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
kubernetes_export.sh kubernetes_context namespace
Example:
kubernetes_export.sh my_k8s_context monitoring