Skip to content

Instantly share code, notes, and snippets.

@ekanant
Last active March 22, 2023 16:07
Show Gist options
  • Select an option

  • Save ekanant/6f7f63a87e3e36238cf65ea255ed9122 to your computer and use it in GitHub Desktop.

Select an option

Save ekanant/6f7f63a87e3e36238cf65ea255ed9122 to your computer and use it in GitHub Desktop.
Shell script for backup kubernetes everything by namespace
namespaces=("namespace_a" "namespace_b")
for n in "${namespaces[@]}"
do
echo "Process for namespace=${n}"
# Backup kubernetes namespace
echo "Backup namespace"
kubectl get namespaces "${n}" -o yaml > "ns-${n}.yaml"
# Backup kubernetes deployment
echo "Backup deployment"
kubectl get deployment -n "${n}" -o yaml > "deployment-${n}.yaml"
# Backup kubernetes service
echo "Backup services"
kubectl get services -n "${n}" -o yaml > "svc-${n}.yaml"
# Backup kubernetes ingress
echo "Backup ingress"
kubectl get ingress -n "${n}" -o yaml > "ingress-${n}.yaml"
# Backup kubernetes secret
echo "Backup secret"
kubectl get secret -n ${n} -o yaml > "secret-${n}.yaml"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment