Copy Secrets between namespace in Kubernetes

Chandrapurnima Bhatnagar
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”.

Pic credit: Hooq

I always prefer playing around with clusters from the terminal and sometimes Lens.

  1. First, log in to the source Kubernetes cluster.
    az login
  2. If you have AKS ( managed service by azure).
    az aks get-credentials — resource-group <resource-group-name> — name <cluster-name>
  3. 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 -
  4. 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 !! 🎉

--

--