Copy Secrets between namespace in Kubernetes
1 min readApr 11, 2022
If you are reading this, I assume you already know the problem statement. If you are reading this because you got notified about my blog post, here is the background.
A few days ago, I stumbled upon a problem where I needed to “copy secrets between namespace in Kubernetes”.
I always prefer playing around with clusters from the terminal and sometimes Lens.
- First, log in to the source Kubernetes cluster.
az login - If you have AKS ( managed service by azure).
az aks get-credentials — resource-group <resource-group-name> — name <cluster-name> - I wanted to copy all secrets from namespace marvel-dev to dc-dev namespace.
kubectl get secrets — field-selector type=Opaque -o yaml -n marvel-dec| sed “s/namespace: .*/namespace: dc-dev/” | kubectl apply — force -f - - Now you can check the secrets in dc-dev namespace.
kubectl get secrets
That’s all for this post.
Hope it helps you. If you face any challenges, please reach out to me via comments.
Happy Learning.
Cheers !! 🎉