Service Accounts in K8s (Kubernetes)

  • What is a service account in K8s
  • Why do we need it?
  • Example on the same
Pods requiring resources
Service accounts
MyK8sCluster> kubectl get sa
NAME SECRETS AGE
default 1 191d

kubectl get sa -A => Provides all service accounts in a cluster
# sample_sa.yml
apiVersion: v1
kind: ServiceAccount
metadata:
name: sample-service-account
namespace: sample-ns
MyK8sCluster> kubectl apply -f sa.yml
serviceaccount/sample-service-account created
MyK8sCluster> kubectl get sa --namespace=sample-ns
NAME SECRETS AGE
default 1 111s
sample-service-account 1 82s
apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: sample-ns
spec:
serviceAccountName: sample-service-account
containers:
- name : "mycontainer"
image: nginx

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sandeep Baldawa

Sandeep Baldawa

whoami >> Slack, Prev — Springpath (Acquired by Cisco), VMware, Backend Engineer, Build & Release, Infra, Devops & Cybersecurity Enthusiast