Replicate secrets across namespaces
Kubernetes secrets are namespaced resources, which means they are only available in the namespace where they are created. In order to use the same secret in multiple namespaces, we need to replicate it, keeping the secret in sync across namespaces.
We are going to use the kubernetes-replicator tool for this purpose.
Usage
Replicate
my-secretfrom namespacemy-nsto any namespace with labelkey=value.
-
Label the secret with the annotation
replicator.v1.mittwald.de/replicate-to-matching="key=value":apiVersion: v1kind: Secretmetadata:name: my-secretnamespace: my-nsannotations:replicator.v1.mittwald.de/replicate-to-matching: "key=value"(...) -
Add the label to the target namespace in the global directory:
apiVersion: v1kind: Namespacemetadata:name: other-nslabels:key: value(...) -
Push the changes.
-
Check secret is replicated:
kubectl get secret my-secret -n other-ns