Skip to main content

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-secret from namespace my-ns to any namespace with label key=value.

  1. Label the secret with the annotation replicator.v1.mittwald.de/replicate-to-matching="key=value":

    apiVersion: v1
    kind: Secret
    metadata:
    name: my-secret
    namespace: my-ns
    annotations:
    replicator.v1.mittwald.de/replicate-to-matching: "key=value"
    (...)
  2. Add the label to the target namespace in the global directory:

    apiVersion: v1
    kind: Namespace
    metadata:
    name: other-ns
    labels:
    key: value
    (...)
  3. Push the changes.

  4. Check secret is replicated:

    kubectl get secret my-secret -n other-ns