secretGenerator

Generate Secret resources.

Each entry in the argument list results in the creation of one Secret resource (it’s a generator of N secrets).

This works like the configMapGenerator.

  1. apiVersion: kustomize.config.k8s.io/v1beta1
  2. kind: Kustomization
  3. secretGenerator:
  4. - name: app-tls
  5. files:
  6. - secret/tls.cert
  7. - secret/tls.key
  8. type: "kubernetes.io/tls"
  9. - name: app-tls-namespaced
  10. # you can define a namespace to generate
  11. # a secret in, defaults to: "default"
  12. namespace: apps
  13. files:
  14. - tls.crt=catsecret/tls.cert
  15. - tls.key=secret/tls.key
  16. type: "kubernetes.io/tls"
  17. - name: env_file_secret
  18. envs:
  19. - env.txt
  20. type: Opaque
  21. - name: secret-with-annotation
  22. files:
  23. - app-config.yaml
  24. type: Opaque
  25. options:
  26. annotations:
  27. app_config: "true"
  28. labels:
  29. app.kubernetes.io/name: "app2"

Secret Resources may be generated much like ConfigMaps can. This includes generating them from literals, files or environment files.

Secret Syntax

Secret type is set using the type field.

Example

File Input

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. secretGenerator:
  5. - name: app-tls
  6. files:
  7. - "tls.cert"
  8. - "tls.key"
  9. type: "kubernetes.io/tls"
  1. # tls.cert
  2. LS0tLS1CRUd...tCg==
  1. # tls.key
  2. LS0tLS1CRUd...0tLQo=

Build Output

  1. apiVersion: v1
  2. data:
  3. tls.cert: TFMwdExTMUNSVWQuLi50Q2c9PQ==
  4. tls.key: TFMwdExTMUNSVWQuLi4wdExRbz0=
  5. kind: Secret
  6. metadata:
  7. name: app-tls-c888dfbhf8
  8. type: kubernetes.io/tls

Important

It is important to note that the secrets are base64 encoded