Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Security Kubernetes Kubernetes: From Zero to Production Module 7 - Security

Pod Security Context - Running Secure Pods

Reviewed & accurate
AI Summary

What You Will Learn

Intermediate

  • How to configure security context
  • Run as non-root
  • Drop capabilities and set read-only filesystem
Terminalyaml
spec:
  securityContext:
    runAsNonRoot: true       # Reject if image runs as root
    runAsUser: 1000          # Run as user 1000
    fsGroup: 2000            # Set file group
  containers:
  - name: app
    image: my-app
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]
        add: ["NET_BIND_SERVICE"]
Run as non-root in production
By default, containers run as root. This is a security risk. Always set runAsNonRoot: true and runAsUser to a non-zero UID in production.

Practical Exercise

Create a Pod with runAsNonRoot: true
Try running an image that uses root - should fail
Set readOnlyRootFilesystem: true
Add capabilities: drop: ['ALL']
Verify with kubectl describe pod

Key Takeaways

  • SecurityContext: controls Pod/container security.
  • runAsNonRoot: true + runAsUser: UID (non-root).
  • readOnlyRootFilesystem: true (immutable filesystem).
  • capabilities: drop ALL, add only what is needed.
  • Always run as non-root in production.
Previously: Lesson 37 covered ServiceAccounts.
Today: You learned: Run Pods securely with security context.
Next: Lesson 39 covers best practices.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments