Kubernetes secrets are only accessible in the namespace they're created in. A quick one-liner to copy a secret from namespaceA to namespaceB is:
kubectl get secrets <secret_name> --export --namespace=<namespaceA> -o yaml | kubectl apply --namespace=<namespaceB> -f -
An example I use to copy my Let's Encrypt cert from the default namespace to another namespace:
kubectl get secrets wc-k8s-prod-tls --export --namespace=default -o yaml | kubectl apply --namespace=monitoring -f -
Note: --export
has been deprecated, but it is a simple way to remove some of the auto-generated keys like resourceVersion
, uid
, selfLink
, etc.