Jeff
Jeff Cloud Systems Architect
1 min read

Copy Kubernetes Secret to Another Namespace

Copy Kubernetes Secret to Another Namespace

Copy Kubernetes Secret to Another Namespace


Sometimes you just want to share a secret between namespaces, for example, a Docker Registry Credential.

Replace CurrentNameSpace and NewNameSpace with your respective namespaces. Also, change the SecretName, pretty simple

Kubernetes <1.18
kubectl get secret SecretName -n CurrentNameSpace --export -o yaml |\
kubectl apply -n NewNameSpace -f -
Kubernetes >1.18

--export flag was removed in version 1.18

kubectl get secret SecretName -n CurrentNameSpace -o yaml |\
sed 's/namespace: CurrentNameSpace/namespace: NewNameSpace/g' |\
kubectl create -f -

That's it