ServiceAccount — identity for Pods to authenticate with the API server.
1apiVersion: v12kind: ServiceAccount3metadata:4 name: myapp-sa5 namespace: production6 annotations:7 eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/myapp-role8automountServiceAccountToken: true9---10# Deployment using ServiceAccount11apiVersion: apps/v112kind: Deployment13metadata:14 name: myapp15spec:16 template:17 spec:18 serviceAccountName: myapp-sa19 automountServiceAccountToken: false # Don't mount token20 containers:21 - name: app22 image: myapp:latest23---24# RoleBinding for ServiceAccount25apiVersion: rbac.authorization.k8s.io/v126kind: RoleBinding27metadata:28 name: myapp-binding29 namespace: production30roleRef:31 apiGroup: rbac.authorization.k8s.io32 kind: Role33 name: pod-reader34subjects:35- kind: ServiceAccount36 name: myapp-sa37 namespace: production
1# Commands2kubectl get sa -n production3kubectl create sa myapp-sa -n production4kubectl get secret -n production # Auto-created token5kubectl describe sa myapp-sa -n production67# AWS IAM integration (IRSA)8eksctl create iamserviceaccount \9 --name myapp-sa \10 --namespace production \11 --cluster mycluster \12 --role-name myapp-role \13 --attach-policy-arn arn:aws:iam::policy/MyPolicy
Cloud Integrations: