nicolai’s space.:space:
Navigate back to the homepage

Kubernetes Tips - Copy Resources

March 9th, 2021 · 1 min read

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.

Join the mailing list

High-quality blog posts are like shiny Pokémon - they don't appear often. But when they do, be the first to receive the latest content with the ability to opt-out at anytime.

More articles from Nicolai

The Secrets of Speed Dating

This post explains, how we choose our partner and what it needs to get a second date by analyzing a dataset.

May 11th, 2020 · 10 min read

Levenshtein's Distance Equation

This post explains, how Levenshtein's distance equation works and why it's related to fuzzy string matching.

April 1st, 2020 · 3 min read
© 2017–2021 Nicolai
Link to $ to $ to $ to $ to $ to $
Sometimes, the questions are complicated – and the answers are simple.