One liner to copy all secrets from one namespace to another in Kubernetes

less than 1 minute read

If you ever need to copy all secrets from one namespace to another, execute the following one liner:

$ for i in `kubectl get secrets | awk '{print $1}'`; do  kubectl get secret $1 -n <source-namespace> -o yaml | sed s/"namespace: <source-namespace>"/"namespace: <target-namespace>"/ | kubectl apply -n <target-namespace> -f -  ; done

Updated:

Comments