Typorithm · easy

Secret

secretkubernetessecretsenvsecurity
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Secret

0%

Config & Scaling

A Secret holds sensitive key/value data; stringData accepts plain text that is base64-encoded, and secretKeyRef injects a key as an env var. Secrets are base64, not encrypted at rest by default.

A Secret separates sensitive values from manifests and images, the way a ConfigMap does for non-secret config.

data fields are base64-encoded; stringData lets you supply plain text that Kubernetes encodes for you on creation.

Pods consume Secrets via env.valueFrom.secretKeyRef for one key, or by mounting a secret volume for whole files.

01

stringData is plain text; data is base64.

02

secretKeyRef injects one key as an env var.

03

Mount a secret volume for files.

apiVersion: v1
kind: Secret
metadata:
  name: db-secret
type: Opaque
stringData:
  DB_PASSWORD: "s3cr3t"
---
apiVersion: v1
kind: Pod
metadata:
  name: api
spec:
  containers:
    - name: api
      image: myapi:1.0
      env:
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: DB_PASSWORD

Read the implementation

Connect each part of the code to the concept before you type.

1. Secret object

A Secret stores sensitive key/value data such as passwords and tokens.

kind: Secret

2. Plain input

stringData lets you write plain text; Kubernetes base64-encodes it into the data field on creation.

stringData:
  DB_PASSWORD: "s3cr3t"

3. Inject a secret

env.valueFrom.secretKeyRef pulls a single key from the Secret into an environment variable.

secretKeyRef:
              name: db-secret
              key: DB_PASSWORD

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Secret: Lesson & Practice · Typorithm | ApplyDjinn