← All notes

Kubernetes securityContext - run as non-root, drop capabilities, read-only root filesystem

Answer: Include the securityContext field in the Pod specification for settings that apply to all Containers, and in a Container manifest for settings that apply only to that container. A security context defines privilege and access control settings for a Pod or Container.

Example

apiVersion: v1
kind: Pod
metadata:
  name: security-context-demo
spec:
  securityContext:
    runAsUser: 1000
    runAsGroup: 3000
    fsGroup: 2000
    seccompProfile:
      type: RuntimeDefault
  volumes:
  - name: sec-ctx-vol
    emptyDir: {}
  containers:
  - name: sec-ctx-demo
    image: busybox:1.28
    command: ["sh", "-c", "sleep 1h"]
    volumeMounts:
    - name: sec-ctx-vol
      mountPath: /data/demo
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]
        add: ["NET_BIND_SERVICE"]

Pod-level fields

Container-level fields

seccomp

seccompProfile.type can be RuntimeDefault, Unconfined, or Localhost; localhostProfile is only set with Localhost and is a path relative to the kubelet's seccomp directory.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Configure a Security Context for a Pod or Container; kubernetes/website (GitHub), security-context.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Configure a Security Context for a Pod or Container; kubernetes/website (GitHub), security-context.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.

Cite this

Permanent ID: iil:note:6ncacjv4

iinventedlight. 2026. "Kubernetes securityContext - run as non-root, drop capabilities, read-only root filesystem." iinventedlight Library, iil:note:6ncacjv4, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-security-context/. License: CC-BY-4.0.

@misc{iil_note_6ncacjv4,
  author = {{iinventedlight}},
  title = {{Kubernetes securityContext - run as non-root, drop capabilities, read-only root filesystem}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/kubernetes-security-context/},
  note = {Permanent ID iil:note:6ncacjv4. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-security-context.md.