Is there a way to share a configMap in kubernetes between namespaces?
Kubernetes version 1.13 and lower
They cannot be shared, because they cannot be accessed from a pods outside of its namespace. Names of resources need to be unique within a namespace, but not across namespaces.
Workaround it is to copy it over.
Copy secrets between namespaces
$ kubectl get secret <secret-name> --namespace=<source-namespace> --export -o yaml | kubectl apply --namespace=<destination-namespace> -f -
Copy configmaps between namespaces
$ kubectl get configmap <configmap-name> --namespace=<source-namespace> --export -o yaml | kubectl apply --namespace=<destination-namespace> -f -
Kubernetes version 1.14 and higher
Flag export
have been deprecated in 1.14 Deprecate --export flag from get command #73787Instead following command can be used:
kubectl get secret <secret-name> --namespace=<source-namespace> -o yaml | sed 's/namespace: <from-namespace>/namespace: <to-namespace>/' | kubectl create -f -
If someone still see a need for the flag, export script was written by @zoidbergwill that is doing that nicely.
Please use the following command to copy from one namespace to another
kubectl get configmap <configmap-name> -n <source-namespace> -o yaml | sed 's/namespace: <source-namespace>/namespace: <dest-namespace>/' | kubectl create -f -
kubectl get secret <secret-name> -n <source-namespace> -o yaml | sed 's/namespace: <source-namespace>/namespace: <dest-namespace>/' | kubectl create -f -