StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 1 · Pods & Containers

Command, Args & Environment

easyContainer Command OverridesEnvironment & Downward API100%1 of 1 solved

Problem statement

The container image starts with baked-in defaults: wrong mode, wrong flags, and none of the settings the environment needs. manifest.yaml declares the pod but changes none of that - it runs whatever the image decided.

About this exercise

A container image ships with a default process and default arguments. A Pod spec can replace both, independently - one field for the executable, another for what is passed to it - and that is how the same image serves as a server here and a one-shot task there.

Configuration reaches the container as environment variables, declared per container. There are two kinds, and both are in this exercise:

  • Literal values - a name and the value you type.
  • Downward API values - fields taken from the pod itself at start time, so the container can report its own name and namespace without anyone hardcoding them. The env schema has a field-reference form for this; kubectl explain pod.spec.containers.env documents it.

One property matters throughout: a pod's spec is immutable for these fields. Editing command, args or env in your manifest does nothing to a running pod - it has to be recreated for the change to take effect. The grader relies on that.

To see the truth from inside rather than from the spec: kubectl exec <pod> -- <command>, and /proc/1/cmdline holds the process the container actually started.

How this project is graded

The grader reads manifest.yaml, inspects the live pod, and runs commands inside the container to check what the process really received. It also applies a throwaway copy of your manifest under a different name to prove the values are not hardcoded - your own pod and file are never touched.

What you will build

In manifest.yaml, one Pod:

name:       configured-worker
namespace:  workloads
container:  name worker, image busybox:1.36
run:        override the image's command and arguments so the container
            starts a long-running process of your choosing
env:        MODE=batch
            REGION=eu-west-1
            POD_NAME       -> this pod's own name, from the pod
            POD_NAMESPACE  -> this pod's own namespace, from the pod

The pod must reach Running and stay ready while the grader inspects it.

Step 1 - run what you decide, not what the image decided

Override the container's command and its arguments, and keep the process alive.

command_and_args_are_overridden and overridden_process_is_what_actually_runs should pass

Step 2 - configuration in the environment

MODE and REGION must be readable inside the container with the values above.

literal_env_vars_present_inside_the_container should pass

Step 3 - the pod describes itself

POD_NAME and POD_NAMESPACE must report this pod's own identity, taken from the pod rather than typed in.

downward_api_reports_pod_name_and_namespace should pass

Step 4 - the values really come from the manifest

The grader applies a copy of your manifest under a different pod name and a different REGION, and expects the container to report both - which only works if the values live in the manifest rather than inside the command you wrote.

values_come_from_the_manifest_not_the_command should pass

When every test passes

You have:

  • Full control of what the container runs, independent of the image's defaults
  • Configuration supplied as environment, not baked into an image
  • A pod that knows its own identity without anyone hardcoding it
  • Configuration that follows the manifest wherever it is applied, not values baked into a command

You do not have yet:

  • Any say in what happens when the process ends - cleanly or by crashing. Restart policies are the next exercise.

Verify

Click Test after every step.

More in Pods & Containers

See the module
First Pod ManifestDeclare a pod with labels and a container port, apply it, and read what the cluster decided - phase, readiness, node and IP.25%1 of 4 solvedeasyRestart Policies & LifecycleGive a completing task and a crashing server the restart policies their lifecycles need, and read phases, restart counts and exit reasons from status.100%1 of 1 solvedeasyContained Workload Bring-UpBring up a server, a configured variant and a one-shot task from bare manifests, and report every workload's identity and outcome from live status.100%1 of 1 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.