Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a pod spec with a hardened securityContext.

IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 10001
    fsGroup: 10001
    seccompProfile: { type: RuntimeDefault }
  automountServiceAccountToken: false
  containers:
    - name: app
      image: myapp:1.0
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities: { drop: ["ALL"] }
      volumeMounts:
        - { name: tmp, mountPath: /tmp }
  volumes:
    - name: tmp
      emptyDir: {}

Key trick → This passes the Pod Security Standards "restricted" profile. With a read-only root filesystem, give the app an emptyDir for /tmp or it crashes on its first temp file.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks