Kubernetes yaml for secret

The simplest form of secret in Kubernetes is opaque secret. It creates a key-value pair for information such as passwords, tokens, and keys.

A yaml file for applying an opaque secret for a key password and value “aG9uZXkxMjM=” is below. The string “aG9uZXkxMjM=” is base64 encoding for “honey123”. The password “honey123” is stored in encoded format instead of plain text.

$ cat mysecret.yaml
apiVersion: v1
kind: Secret
  name: samplesecret
type: Opaque
  password: aG9uZXkxMjM=

Apply the file below using kubectl.

$ kubectl apply -f mysecret.yaml
secret/samplesecret created

You can get the listing of the secret using kubectl get.

$ kubectl get secret
NAME           TYPE     DATA   AGE
samplesecret   Opaque   1      10s

You can read the secret’s complete details using kubectl describe as shown below.

$ kubectl describe secret samplesecret
Name:         samplesecret
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

password:  8 bytes