Course contentsShow
← Cloud and Infrastructure
Lesson 1390 of 2,98928. Kubernetes SecurityFree lesson

Container Security Context

Learn container-level security settings that override or complement pod-level security configurations.

Container Security Context

What you'll learn: How to apply security settings at the individual container level to override or refine the pod-level security policies you've already configured.

Why Container-Level Security?

In the previous lesson, you learned about Pod Security Context—settings that apply to all containers in a pod. But what if one specific container needs different security rules? Maybe your application container should run as a regular user, but a sidecar logging container needs elevated privileges to access system logs.

Container Security Context gives you this fine-grained control. Settings defined at the container level override the pod-level defaults for that specific container only.

Key Container Security Settings

Within a container spec, you can define a securityContext block that includes:

  • runAsUser / runAsGroup: Override which user/group ID this container runs as
  • allowPrivilegeEscalation: Prevent the container from gaining more privileges than its parent process
  • readOnlyRootFilesystem: Force the container's root filesystem to be read-only (great for security!)
  • capabilities: Add or drop specific Linux capabilities (like NET_ADMIN or SYS_TIME)
  • privileged: Run the container in privileged mode (access to host resources—use sparingly!)

The Override Pattern

Think of it like dress code policies: the company (pod) sets a baseline dress code, but individual departments (containers) can have stricter rules. Marketing might require business formal while engineering stays business casual. Container settings always win when they conflict with pod settings.

Key Takeaway: Container Security Context provides granular security controls for individual containers, overriding pod-level settings and enabling you to apply principle of least privilege on a per-container basis.