Link Search Menu Expand Document

Secret

secret-key-ref.yaml

---
apiVersion: v1
kind: Secret
metadata:
  name: simple-secret-secret-key-ref-secret
type: Opaque
stringData:
  config.yaml: |-
    password: apassword
    username: ausername
---
apiVersion: v1
kind: Pod
metadata:
  name: simple-secret-secret-key-ref-pod
spec:
  containers:
    - command:
        - sleep
        - "3600"
      image: busybox
      name: simple-secret-secret-key-ref-container
      env:
        - name: simple-secret-secret-key-ref-env
          valueFrom:
            secretKeyRef:
              name: simple-secret-secret-key-ref-secret
              key: config.yaml
      # this volume mount is not required, but demonstrates that the secret can
      # be mounted both as an env var and as a file
      volumeMounts:
        - name: simple-secret-secret-key-ref-volume
          mountPath: "/etc/simple-secret"
  volumes:
    - name: simple-secret-secret-key-ref-volume
      secret:
        secretName: simple-secret-secret-key-ref-secret

simple-secret.yaml

---
apiVersion: v1
kind: Secret
metadata:
  name: simple-secret-secret
type: Opaque
stringData:
  config.yaml: |-
    password: apassword
    username: ausername
---
apiVersion: v1
kind: Secret
metadata:
  name: simple-secret-secret-2
type: Opaque
stringData:
  config.yaml: |-
    password: apassword
    username: ausername
---
apiVersion: v1
kind: Pod
metadata:
  name: simple-secret-pod
spec:
  containers:
    - command:
        - sleep
        - "3600"
      image: busybox
      name: simple-secret-container
      volumeMounts:
        - name: simple-secret-volume
          mountPath: "/etc/simple-secret"
        - name: simple-secret-volume
          mountPath: "/etc/simple-secret2"
  volumes:
    - name: simple-secret-volume
      secret:
        secretName: simple-secret-secret