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

ServiceAccounts - Identity for Pods

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • What ServiceAccounts are
  • How to create and use them
  • RBAC with ServiceAccounts

A ServiceAccount is an identity for Pods. When a Pod needs to talk to the K8s API (e.g., to list other Pods), it uses a ServiceAccount.

Terminalbash
# Create a ServiceAccount
kubectl create serviceaccount my-app-sa

# Use in a Pod
spec:
  serviceAccountName: my-app-sa
  containers:
  - name: app
    image: my-app
Default ServiceAccount
Every Pod gets the 'default' ServiceAccount if none is specified. It has minimal permissions. For apps that need API access, create a dedicated ServiceAccount with specific RBAC.

Practical Exercise

Create a ServiceAccount: kubectl create sa my-sa
Create a Pod with serviceAccountName: my-sa
Exec in: kubectl exec -it pod -- cat /var/run/secrets/kubernetes.io/serviceaccount/token
Create a Role + RoleBinding for this ServiceAccount
Test: the Pod can now access the API

Key Takeaways

  • ServiceAccount = identity for Pods.
  • Every Pod gets 'default' SA if not specified.
  • Create dedicated SA for apps that access K8s API.
  • Combine with RBAC (Role + RoleBinding).
  • Token is mounted at /var/run/secrets/kubernetes.io/serviceaccount/.
Previously: Lesson 36 covered RBAC.
Today: You learned: Identity for Pods to access the K8s API.
Next: Lesson 38 covers security context.
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