Challenge, Easy,  on  Kubernetes

Set and Use Secrets in a Kubernetes Deployment

Scenario

You are working with a Kubernetes Deployment in the orbit namespace.

An existing Deployment named config-deployment is already running.

A Secret YAML file has been prepared for you on the dev-machine at:

/opt/course/extra-config-secret.yaml

Tasks

  1. Create a Secret named config-secret in the orbit namespace with:
    • username=appuser
    • password=apppass
  2. Expose those Secret values as environment variables in config-deployment:
    • CONFIG_SECRET_USERNAME → key username
    • CONFIG_SECRET_PASSWORD → key password
  3. Apply the second Secret from the YAML file already present on the dev-machine at /opt/course/extra-config-secret.yaml.
  4. Mount that Secret as a volume inside the Deployment. The mount path inside the pod is /tmp/extra-config.
  5. Ensure the Deployment rolls out successfully with all changes applied.

Hint 1 — Inspect the existing Deployment

Before making any changes, check what is already running in the orbit namespace. Look at the Deployment spec and its current pod state to understand the baseline.

kubectl get all -n orbit
kubectl describe deployment config-deployment -n orbit

Documentation

Hint 2 — Create a Secret imperatively

kubectl can create Secrets directly from the command line without a YAML file. Look into the kubectl create secret generic command and its --from-literal flag to pass key-value pairs inline.

Don't forget to target the correct namespace.

Documentation

Hint 3 — Expose Secret keys as environment variables in a Deployment

Kubernetes lets you reference individual Secret keys as environment variables inside a container using secretKeyRef under the env field.

Export the current Deployment spec to a file, edit it to add the env entries referencing config-secret, then reapply with kubectl apply.

Check the Kubernetes docs for the exact structure of valueFrom.secretKeyRef.

Documentation

Hint 4 — Apply the second Secret from a YAML file

A Secret manifest has already been prepared for you on the dev-machine at:

/opt/course/extra-config-secret.yaml

Inspect the file to understand its structure, then use kubectl apply to create the Secret in the cluster. Confirm it lands in the correct namespace.

Documentation

Hint 5 — Mount a Secret as a volume inside the Deployment

To make Secret data available as files inside a container, you need two things in the Deployment spec:

  • A volume entry under .spec.template.spec that references the Secret by name
  • A volumeMount entry under the container that maps that volume to a path

The target mount path inside the container is:

/tmp/extra-config

This path is inside the running pod, not on the dev-machine.

After applying the changes, use kubectl rollout status to confirm the Deployment updated successfully, then exec into the pod to verify the files are present.

Documentation


⚒ Test Cases