Kubernetes Security Context

created:

updated:

tags: kubernetes security

Security Contexts

We can configure security at a pod level. This will allow the settings to carry over to all the containers within the pod.

  • If you have security settings on a container, then the container setting will override the pod-level setting.

How to configure Security Context

# pod-definition yaml file
apiVersion: v1
kind: Pod
metadata:
  name: web-pod
spec:
  securityContext:
    runAsUser: 1000

  containers:
    - name: ubuntu
      image: ubuntu
      command: ["sleep", "3600"]
      # container-specific setting
      securityContext:
        runAsUser: 1001
        capabilities:
          # Capabilities are only supported at the container level (not at the pod level)
          add: ["MAC_ADMIN"]

References