secrets

Creating confidential information in a cluster

Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys. Storing confidential information in a Secret is safer and more flexible than putting it verbatim in a Pod definition or in a container image.

Note

Secrets can be created by using any one of the subcommands depending on use case.

  • docker-registry
  • generic
  • tls

docker-registry

  • Create a secret for use with a Docker registry
  1. kubectl create secret docker-registry NAME --docker-username=user --docker-password=password --docker-email=email [--docker-server=string] [--from-literal=key1=value1] [--dry-run=server|client|none]

Example

Command

  1. kubectl create secret docker-registry my-secret --docker-username=kubectluser --docker-password=somepassword --docker-email=kubectl@kubectl.com --from-literal=token=GGH132YYu8asbbAA

Output

  1. $ kubectl get secrets
  2. NAME TYPE DATA AGE
  3. my-secret Opaque 1 14s

generic

  • Create a secret from a local file, directory or literal value
  1. $ kubectl create generic NAME [--type=string] [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run=server|client|none]

Example

Input File

  1. // file-name: simplesecret.txt
  2. kjbfkadbfkabjnaAdjna

Command

  1. kubectl create secret generic my-secret --from-file=simplesecret.txt

Output

  1. $ kubectl get secrets
  2. NAME TYPE DATA AGE
  3. my-secret Opaque 1 14s

tls

  • Create a secret from tls certificate and key
  1. $ kubectl create secret tls NAME --cert=path/to/cert/file --key=path/to/key/file [--dry-run=server|client|none]

Example

Input File

  1. # tls.cert
  2. LS0tLS1CRUd...tCg==
  1. # tls.key
  2. LS0tLS1CRUd...0tLQo=

Command

  1. kubectl create secret tls my-secret --cert=tls.cert --ket=tls.key

Output

  1. $ kubectl get secrets
  2. NAME TYPE DATA AGE
  3. my-secret Opaque 1 14s