When I started this blog, I decided to set the focus on quality, not quantity. Although the aim has not changed since then, I chose to publish posts at shorter intervals, that are not so time-consuming to write.
PS: I am still working on detailed (longer) blog posts, so be excited for updates! 😉
When working with Kubernetes, you may come across Secrets sooner or later to manage sensitive information. Secrets reside in a namespace and thus can only be referenced by Pods in the same namespace. In some scenarios however it may be necessary to share credentials across namespaces, e.g. when multiple applications want to
git clone a repository using the same SSH key.
Copy Secrets across namespaces
Basically, a Secret can be copied from one namespace to another by exporting it to
YAML in a first step and applying the output to the destination namespace then. By piping the export to the second
kubectl command, the Secret is copied in-place without the need to temporarily store a physical file.
1kubectl -n <src-namespace> get secret <secret> --export -o yaml | kubectl apply -n <dest-namespace> -f -
The above command is also applicable for other Kubernetes resources, e.g. ConfigMaps by slightly adopting the type in the statement. Please keep in mind, that changes to a Secret in one namespace are not automatically replicated to the other ones — so think of a process to keep the resources consistent and synchronized.