0
0
Kubernetesdevops~5 mins

Using Secrets as environment variables in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Kubernetes Secret?
A Kubernetes Secret is a way to store and manage sensitive information, like passwords or tokens, separately from application code.
Click to reveal answer
beginner
How do you use a Secret as an environment variable in a Pod?
You define an environment variable in the Pod spec that references the Secret's key using env: with valueFrom.secretKeyRef.
Click to reveal answer
intermediate
Example YAML snippet to set environment variable from Secret key 'password' named 'mysecret'.
env:
  - name: DB_PASSWORD
    valueFrom:
      secretKeyRef:
        name: mysecret
        key: password
Click to reveal answer
beginner
Why should you use Secrets instead of plain environment variables for sensitive data?
Secrets keep sensitive data separate from code and can be encrypted, reducing risk of accidental exposure and improving security.
Click to reveal answer
beginner
What command creates a Secret from literal values?
Use kubectl create secret generic mysecret --from-literal=password=mypassword to create a Secret named 'mysecret' with a password.
Click to reveal answer
How do you reference a Secret key as an environment variable in a Pod spec?
AUsing <code>valueFrom.secretKeyRef</code>
BUsing <code>configMapKeyRef</code>
CUsing <code>envFrom.secretRef</code>
DUsing <code>volumeMounts</code>
Which command creates a Secret from a literal value?
Akubectl create secret generic mysecret --from-literal=password=mypassword
Bkubectl create configmap mysecret --from-literal=password=mypassword
Ckubectl apply -f secret.yaml
Dkubectl get secret mysecret
Why use Secrets instead of plain environment variables for sensitive data?
ASecrets use less memory
BSecrets are faster to load
CSecrets are encrypted and safer
DSecrets are easier to debug
What is the default encoding for data stored in Kubernetes Secrets?
AUTF-8
BBase64
CHexadecimal
DPlain text
Which Kubernetes object is best for storing sensitive environment variables?
APod
BConfigMap
CService
DSecret
Explain how to use a Kubernetes Secret as an environment variable in a Pod.
Think about how environment variables are set in the Pod YAML.
You got /4 concepts.
    Describe why using Secrets is important for managing sensitive data in Kubernetes.
    Consider the risks of putting passwords directly in code or config.
    You got /4 concepts.