4

When I create secret with Rancher and select it should be visible in all namespaces, it creates a secret without namespace tag and with namespaceId: null.

How to create such a secret without Rancher? When I use kubectl, it always binds it to the namespace from the command context.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
9ilsdx 9rvj 0lo
  • 7,955
  • 10
  • 38
  • 77
  • I prefer to `create if not exist`, this is something that works like charm in ci/cd. for example docker secret `(kubectl get secret gitlab-com --namespace=${NAMESPACE} || kubectl --namespace=${NAMESPACE} create secret docker-registry gitlab-com --docker-server=$CI_REGISTRY --docker-username=$GITLAB_REG_USER --docker-password=$GITLAB_REG_PASSWORD --docker-email=DOCKER_EMAIL)` – Adiii Jan 07 '21 at 17:51

1 Answers1

5

kubectl currently does not support creating secrets across namespaces.

They are available to a single namespace. Rancher supports it creating secrets at the project level. it will replicate the secret to all namespaces in the project (present and future). also, functionality is not in the rancher cli yet.

there are some work around option available to replicate the secret and configmap across the namespace in Kuberenetes.

You can check this out open source projects:

  1. https://github.com/zakkg3/ClusterSecret
  2. https://github.com/mittwald/kubernetes-replicator
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • How does this replication work? Does it work only with the namespaces created in the rancher, or also those, created directly with kubectl? – 9ilsdx 9rvj 0lo Jan 07 '21 at 15:01
  • created with kubectl and having annotation inline if you read the documentation there is push and pull-based options. – Harsh Manvar Jan 07 '21 at 18:15
  • any update on this ? please feel free to update the status of question by accepting answer if helpful or do upvote if found it helpful please. – Harsh Manvar Mar 18 '23 at 03:54