Skip to main content
This walkthrough shows the commands and YAML edits needed to complete the Kubernetes security context lab: inspecting the user inside a container, overriding Pod-level user settings at the container level, and adding Linux capabilities such as SYS_TIME and NET_ADMIN. Each step preserves the original sequence and provides validation commands.
Use kubectl exec to run whoami or id -u inside a container to determine which user or UID the process is running as. whoami prints a username (if one exists for the UID), while id -u prints the numeric UID.

1) Which user is used to execute the sleep process inside the ubuntu-sleeper Pod?

First confirm the Pod exists, then exec into it:
Expected output when the container runs as root:
If there is no passwd entry for the numeric UID, whoami may not return a username—use id -u instead:
Answer: Root

2) Edit the ubuntu-sleeper Pod so the sleep process runs with UID 1010

Steps to change the Pod to run as UID 1010:
  1. Export the Pod manifest to a file so you can make the required change:
  1. Edit ubuntu-sleeper.yaml. Add (or update) the Pod-level securityContext.runAsUser under spec:
  1. Delete and recreate the Pod. Many Pod fields cannot be updated in-place, so recreate the Pod after editing the manifest.
Using --force and immediate deletion can leave the old process running on the node briefly. Prefer graceful deletion when possible.
  1. Validate the numeric UID inside the container:
Expected output:

3) Given multi-pod.yaml: with what user are processes in the web container started?

Inspect the manifest. The Pod-level securityContext sets runAsUser: 1001, but the web container has its own container-level securityContext:
Because container-level settings override Pod-level settings, the web container runs as UID 1002. Answer: 1002
Container-level securityContext overrides Pod-level securityContext for properties such as runAsUser.

4) With what user are processes in the sidecar container started?

The sidecar container has no container-level securityContext, so it inherits the Pod-level runAsUser: 1001. Answer: 1001

5) Update the ubuntu-sleeper Pod to run as root and add the SYS_TIME capability

To run as root and grant the SYS_TIME capability to the container:
  1. Edit ubuntu-sleeper.yaml. You can either remove runAsUser so the container uses the default (root), or explicitly set it to 0. Add a container-level securityContext.capabilities.add list that includes SYS_TIME. Example (remove Pod-level runAsUser to rely on the default root):
  1. Recreate the Pod:
  1. Validate capability and UID as needed. Checking effective capabilities often requires tools inside the image (e.g., capsh), or you can verify that operations requiring SYS_TIME succeed.

6) Add the NET_ADMIN capability to the Pod

To add NET_ADMIN, include it in the container capabilities.add list alongside SYS_TIME. Example:
Apply the change by recreating the Pod:

Quick answers summary


Validation tips and references

That completes the lab solution for security contexts: determining the effective UID, using container-level overrides, and adding capabilities such as SYS_TIME and NET_ADMIN.

Watch Video