Write kubernetes secret into multiple namespaces

As my previous post, I’ve also came into a situation that I need to write the same secret into multiple namespaces.

In this case, rather than save into vaults, the secret saves in the namespaces. So I pushed the secret into one kubernetes namespace and I’m able to get it as follow

kubectl -n pipeline get secrets mypassword -o yaml

If I want to push the same same secret into another cluster. I can get it done in one command.

kubectl -n pipeline get secrets mypassword -o yaml | kubectl --kubeconfig ~/.kube/prod.config apply -n pipeline -f -

And if I have multiple namespaces within one cluster. I also can use one command to push into different namespaces.

kubectl -n pipeline get secrets mypassword -o yaml | sed 's/namespace: pipeline/namespace: production/' | kubectl --kubeconfig ~/.kube/prod.config apply -n pipeline -f -