DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Kubernetes & Helm · revision

Kubernetes & Helm cheat sheet

Recall first: read each stage's one-line summary and try to remember its commands. Then open the stage to check yourself.

16 stages95 commands

01IntroductionYou declare the state you want and controllers keep fixing the difference. The control plane (API server, etcd, scheduler, controller manager) decides; the kubelet on each node runs the Pods.
  • kind create cluster --name academy

    Create a local practice cluster in Docker

  • kubectl apply -f web.yaml

    Send a desired state to the API server

  • kubectl create deployment web --image=nginx:1.27 --replicas=3

    Create a three-replica Deployment without writing YAML

  • kubectl rollout status deployment/web

    Wait until the Deployment's Pods are ready

  • kubectl get pods -w

    Watch Pods change, for example a deleted one being replaced

  • kind delete cluster --name academy

    Delete the local cluster

Remember

  • Deployment manages versions, ReplicaSet keeps the count, Pod runs the containers.
  • A deleted Pod is replaced in seconds; a dead node takes minutes (about 2 in the lab, up to 5 for an unreachable node).
  • A namespace scopes names, RBAC and quotas; it is not a network wall on its own.

Watch for Manifests describe your apps, not their data. Rebuilding a cluster from YAML does not bring back volumes or databases.

Open the lesson: Kubernetes: what it solves, and when you don't need it →
02Containers refresherBuild a small, non-root image with a fixed port, tag it with a real version, and push it to a private registry next to the cluster. On EKS the node role pulls from ECR with no stored password.
  • docker build -t shop-web:v1 --build-arg APP_VERSION=v1 .

    Build the image with its version baked in

  • aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true

    Create a private ECR repository that scans every push

  • aws ecr get-login-password | docker login --username AWS --password-stdin $REG

    Log Docker in to ECR with a short-lived token

  • aws ecr describe-images --repository-name shop-web

    List the pushed tags and their sizes

Remember

  • Never use latest in a manifest; tag with a version or commit SHA and never reuse a tag.
  • USER 10001 in the Dockerfile is what lets the image pass the restricted Pod Security standard later.
  • Other private registries need a dockerconfigjson Secret referenced as imagePullSecrets.

Watch for Untagged entries in ECR are build attestations and the multi-platform index, not junk to delete.

Open the lesson: Images and registries for Kubernetes →
03Setting upkind is free and local; EKS adds load balancers, EBS disks and node autoscaling. Connect kubectl with update-kubeconfig, check the nodes and system Pods, then run and reach a first Deployment.
  • aws eks update-kubeconfig --name academy --region ap-south-1

    Add the EKS cluster to ~/.kube/config

  • kubectl cluster-info

    Show the API server and CoreDNS addresses

  • kubectl get nodes -o wide

    List nodes with IPs, OS and container runtime

  • kubectl get pods -A

    List Pods in every namespace, including kube-system

  • kubectl create deployment hello --image=<your-registry>/shop-web:v1 --replicas=2

    Run the first app with two replicas

  • kubectl expose deployment hello --port=80 --target-port=8080

    Put a ClusterIP Service in front of the Pods

  • kubectl run curl --image=busybox:1.37 --restart=Never --rm -i --quiet -- wget -qO- http://hello/api

    Call the Service by name from a throwaway Pod

Remember

  • kubectl must be within one minor version of the cluster.
  • One Pod per node in kube-system means a DaemonSet; on EKS the API server and etcd are not visible as Pods.
  • EKS bills by the hour even when idle; destroy the cluster the same day.

Watch for Delete Services and Ingresses that created AWS load balancers before terraform destroy, or the load balancers are left billing.

Open the lesson: Setting up: a cluster, kubectl and your first deployment →
04Running applicationsNever run bare Pods for real work. Use a Deployment with probes and requests for stateless apps, a StatefulSet for things with identity and disks, and a Job or CronJob for work that finishes.
  • kubectl apply -f 04-deployment.yaml

    Create the shop-web Deployment with probes and resources

  • kubectl get replicaset -l app=shop-web

    See the ReplicaSet the Deployment created

  • kubectl scale deployment shop-web --replicas=5

    Change the desired count for an experiment

  • kubectl wait --for=condition=Complete job/report --timeout=120s

    Block until a Job finishes

  • kubectl logs -l job-name=report --prefix

    Read logs from every Job Pod, labelled by Pod

  • kubectl describe job report

    Find why a Job is not completing

Remember

  • selector.matchLabels must match template.metadata.labels.
  • Readiness controls traffic; liveness restarts the container.
  • Job: completions is the total, parallelism the concurrency, backoffLimit the failures allowed.

Watch for kubectl scale is for experiments. Change replicas in Git, or the next apply puts the old number back.

Open the lesson: Running applications: Pods, Deployments, Jobs →
05Services & networkingEvery Pod gets its own IP; a Service gives a stable name and IP over the ready ones. On EKS the AWS Load Balancer Controller turns a LoadBalancer Service into an NLB and an Ingress into an ALB.
  • kubectl get endpointslices -l kubernetes.io/service-name=shop-web

    List the Pod IPs currently behind the Service

  • kubectl run dns --image=busybox:1.37 --restart=Never --rm -i --quiet -- nslookup shop-web.default.svc.cluster.local

    Resolve a Service name through cluster DNS

  • helm repo add eks https://aws.github.io/eks-charts

    Add the chart repo for the AWS Load Balancer Controller

  • kubectl apply -f 05-ingress.yaml

    Create an Ingress that becomes an ALB

  • kubectl get ingress shop

    Read the load balancer address once it is ready

  • kubectl describe ingress shop

    Check each rule's backend Service and endpoints

  • kubectl port-forward service/shop-web 8080:80

    Reach a Service from your machine on kind

Remember

  • DNS name is <service>.<namespace>.svc.cluster.local; the short name works in the same namespace.
  • Only Pods passing readiness are listed in the EndpointSlice.
  • target-type ip sends load balancer traffic straight to Pod IPs, with draining during rollouts.

Watch for An Ingress rule pointing at a missing Service gives users a 503 while the controller still says Successfully reconciled.

Open the lesson: Services, Ingress and load balancing →
06ConfigurationConfigMaps hold settings and Secrets hold credentials, loaded as env vars or mounted files. A Secret is base64, not encryption, so protect it with RBAC, KMS encryption and an external store.
  • kubectl apply -f 06-config.yaml

    Create the ConfigMap and the Secret

  • kubectl set env deployment/shop-web --from=configmap/shop-config

    Load every ConfigMap key as an environment variable

  • kubectl get secret shop-secret -o yaml

    View the Secret as stored, annotations included

  • kubectl get secret shop-secret -o jsonpath="{.data.DATABASE_URL}" | base64 -d

    Decode a Secret value in one line

  • kubectl rollout restart deployment/shop-web

    Restart Pods so they read new env values

Remember

  • Env vars are read at container start; mounted ConfigMap files update eventually.
  • Grant get secrets to very few people and service accounts.
  • Keep real values in Secrets Manager or Vault, synced by the External Secrets Operator.

Watch for kubectl apply with stringData stores the plain-text value again in the last-applied-configuration annotation.

Open the lesson: Configuration: ConfigMaps and Secrets →
07Resource managementRequests reserve capacity for scheduling; limits cap use at runtime. Namespaces scope a team, a ResourceQuota caps its total, and a LimitRange fills in defaults for containers that set none.
  • kubectl apply -f 07-team-a.yaml

    Create a namespace with a quota and a limit range

  • kubectl describe resourcequota team-a-quota -n team-a

    See used versus hard limits for the namespace

  • kubectl get pod memory-hog -o jsonpath='{.status.containerStatuses[0].state.terminated}'

    Read the reason and exit code of a killed container

  • kubectl top nodes

    Show real CPU and memory use per node

  • kubectl top pods -A --sort-by=memory

    Find the Pods using the most memory

Remember

  • Over a CPU limit means throttled; over a memory limit means OOMKilled, exit code 137.
  • A node can look idle and still refuse Pods because its capacity is already requested.
  • Size requests from a week of real usage, not guesses.

Watch for A Deployment stuck below its replica count by a quota shows nothing on its Pods; the FailedCreate events are on the ReplicaSet.

Open the lesson: Resource management: requests, limits, namespaces, quotas →
08SecurityRBAC decides who may do what, NetworkPolicies decide which Pods may talk, and Pod Security admission decides what a Pod may do on its node. On EKS, IAM handles AWS and RBAC handles Kubernetes.
  • kubectl auth can-i list pods --as=system:serviceaccount:default:viewer

    Ask what an identity may do without trying it

  • kubectl auth can-i delete pods --as=system:serviceaccount:default:viewer

    Confirm a read-only account cannot delete

  • kubectl apply -f 08-netpol.yaml

    Apply default-deny plus an allow rule for role=frontend

  • kubectl run front --image=busybox:1.37 --labels=role=frontend --restart=Never --rm -i --quiet -- wget -qO- -T 5 http://shop-web/api

    Test the allowed path from a labelled Pod

  • kubectl label namespace secure pod-security.kubernetes.io/enforce=restricted

    Enforce the restricted Pod Security standard on a namespace

Remember

  • RBAC is deny by default; Role and RoleBinding are namespaced, Cluster* versions are not.
  • A connection blocked by a NetworkPolicy times out rather than being refused.
  • Start namespaces at enforce=baseline and warn=restricted, then tighten.

Watch for A default-deny policy also blocks the load balancer reaching your Pods, and policies are silently ignored if the CNI does not enforce them.

Open the lesson: Security: RBAC, network policies, Pod Security →
09Monitoring & loggingThree places to look: logs for what the app said, describe and events for what Kubernetes did, and metrics for what it used. Pending is a scheduling problem; CrashLoopBackOff is an app problem.
  • kubectl logs deployment/shop-web --tail=3 --timestamps

    Read the latest log lines from one of the Deployment's Pods

  • kubectl logs broken --previous

    Read the log of the container before the current one

  • kubectl describe pod broken

    See the exit code, restart count and events

  • kubectl get events -A --sort-by=.lastTimestamp

    Get a quick overview of everything going wrong

  • kubectl top pods -l app=shop-web --containers

    Show CPU and memory per container

  • kubectl describe pvc orphan

    Find why a claim is stuck Pending

Remember

  • Exit code 1 is the app, 137 is a kill (often OOM), 143 is a normal shutdown signal.
  • ErrImagePull then ImagePullBackOff: check the tag, the registry and pull permission.
  • metrics-server keeps only current values; history needs Prometheus.

Watch for kubectl logs deployment/... reads only one Pod. Use -l app=shop-web --prefix for all of them.

Open the lesson: Monitoring, logging and troubleshooting →
10AutoscalingThe HPA changes replica count from CPU as a percentage of the request. The Cluster Autoscaler adds nodes when Pods are Pending and removes nodes it can empty. Pods scale in seconds, nodes in minutes.
  • kubectl apply -f 10-hpa.yaml -f 10-load.yaml

    Create the HPA and start the load generator

  • kubectl get hpa shop-web

    Read current utilisation against target and replica count

  • kubectl describe hpa shop-web

    See SuccessfulRescale events and their reasons

  • helm install cluster-autoscaler autoscaler/cluster-autoscaler -n kube-system \ --set autoDiscovery.clusterName=academy --set awsRegion=ap-south-1 \ --set rbac.serviceAccount.name=cluster-autoscaler --wait

    Install the Cluster Autoscaler on EKS

  • kubectl get nodes -L topology.kubernetes.io/zone

    Watch nodes appear, with their zone

Remember

  • No CPU request or no metrics-server means TARGETS shows <unknown>.
  • Scale-down waits 5 minutes by default so a short dip does not cause flapping.
  • The Cluster Autoscaler counts requests, not real usage.

Watch for Do not let a VPA and an HPA both act on CPU for the same Deployment; they fight.

Open the lesson: Autoscaling: Pods and nodes →
11SchedulingThe scheduler filters nodes that cannot run a Pod, then scores the rest. Spread across zones with topologySpreadConstraints, reserve nodes with taints, and protect apps during drains with a PDB.
  • kubectl get pods -l app=spread -o custom-columns=POD:.metadata.name,NODE:.spec.nodeName

    See which node each Pod landed on

  • kubectl taint node ip-10-42-0-115.ap-south-1.compute.internal dedicated=batch:NoSchedule

    Keep Pods without a matching toleration off a node

  • kubectl get pdb shop-web

    Check how many disruptions the budget allows

  • kubectl drain $N --ignore-daemonsets --timeout=60s

    Cordon a node and evict its Pods

  • kubectl uncordon $N

    Let the scheduler use the node again

Remember

  • A toleration allows a Pod onto a tainted node; pair it with a node selector to send it there.
  • maxSkew 1 on the zone key keeps zones within one Pod of each other.
  • NoSchedule blocks new Pods; NoExecute also evicts running ones.

Watch for A PDB with minAvailable equal to the replica count allows zero disruptions, and the drain times out.

Open the lesson: Scheduling: where Pods run →
12StorageA PVC asks for storage, a StorageClass says how to make it, and the CSI driver creates the real disk. Data belongs to the claim, not the Pod. A StatefulSet gives each replica its own claim and name.
  • kubectl get csidrivers

    List the storage drivers installed in the cluster

  • kubectl get storageclass

    List the classes a claim can ask for

  • kubectl get pvc notes

    Check that a claim is Bound

  • kubectl get pv

    See the volumes, their reclaim policy and claim

  • kubectl exec db-0 -- cat /data/id

    Read a file from a StatefulSet replica's own disk

  • kubectl delete pvc -l app=db

    Remove the claims a StatefulSet left behind

Remember

  • WaitForFirstConsumer creates the EBS disk in the zone where the Pod lands.
  • EBS is ReadWriteOnce; EFS is ReadWriteMany.
  • reclaimPolicy Retain keeps the disk after the claim is deleted.

Watch for Deleting a StatefulSet keeps its PVCs, and deleting a PVC with reclaimPolicy Delete deletes the data.

Open the lesson: Storage: data that outlives Pods →
13HelmA chart is templates plus default values; an install is a release, and every change is a numbered revision. Render before you install, upgrade with --wait, and roll back to a known-good revision.
  • helm create shop

    Generate a starter chart

  • helm lint shop

    Check the chart for errors

  • helm template demo shop --set replicaCount=3

    Render the YAML locally without touching the cluster

  • helm install shop ./helm/shop --namespace shop --create-namespace --wait --timeout 4m

    Install the chart as a release

  • helm upgrade shop ./helm/shop -n shop --set image.tag=v2 --set replicaCount=3 --wait --timeout 4m

    Upgrade and wait until the new Pods are ready

  • helm history shop -n shop

    List revisions and their status

  • helm rollback shop 2 -n shop --wait --timeout 4m

    Roll back to revision 2 as a new revision

  • helm get values shop -n shop

    Show the values actually deployed

Remember

  • Later value sources win: -f files, then --set.
  • A rollback adds a revision; history is never rewritten.
  • Pin public charts with --version and read helm show values first.

Watch for Never put secrets in values files committed to Git.

Open the lesson: Helm: packaging Kubernetes apps →
14Deployment patternsRolling updates replace Pods only as new ones become ready. Blue-green switches a Service selector; a canary sends a share of traffic. GitOps makes Git the source of truth and Argo CD applies it.
  • kubectl set image deployment/shop-web web=<registry>/shop-web:v2

    Start a rolling update to a new image

  • kubectl rollout status deployment/shop-web --timeout=180s

    Wait for the rollout, or time out if it stalls

  • kubectl rollout undo deployment/shop-web

    Go back to the previous ReplicaSet

  • kubectl patch service shop -p '{"spec":{"selector":{"app":"shop","color":"green"}}}'

    Switch all traffic from blue to green

  • kubectl patch service shop -p '{"spec":{"selector":{"app":"shop","color":null}}}'

    Let the Service match both versions for a canary

  • kubectl scale deployment shop-blue --replicas=3

    Set the old version's share of a Pod-count canary

Remember

  • A readiness probe is what stops a crashing release from replacing healthy Pods.
  • Blue-green costs double capacity during the switch, and both versions share the database.
  • Pod-count canaries are coarse; use weighted routes, a mesh or Argo Rollouts for exact shares.

Watch for rollout undo changes the cluster, not your YAML. The next apply of the old file brings the bad image back.

Open the lesson: Deployment patterns: rolling, blue-green, canary, GitOps →
15Advanced topicsOn EKS, AWS runs the control plane and you see only the API endpoint. Nodes run the kubelet, containerd, kube-proxy and DaemonSet agents. CRDs add API types; operators act on them.
  • kubectl get --raw='/readyz?verbose'

    Check API server health, including etcd

  • kubectl get daemonsets -n kube-system

    List the agents that run on every node

  • kubectl api-resources | wc -l

    Count the resource types the API serves

  • kubectl wait --for=condition=Established crd/websites.academy.example.com

    Wait until a new CRD is served before creating resources

  • kubectl get crd websites.academy.example.com

    Confirm the CRD exists

  • kubectl config get-contexts

    See which cluster kubectl points at

Remember

  • The scheduler hands out Allocatable, which is capacity minus kubelet and OS reservations.
  • A t3.medium with the VPC CNI fits 17 Pods; Pod slots often run out before CPU.
  • A CRD only stores objects; an operator is the controller that acts on them.

Watch for Applying a CRD and its resources in one go can fail with "ensure CRDs are installed first". Apply the CRD, wait, then the resources.

Open the lesson: Advanced: inside the cluster, CRDs and many clusters →
16Capstone projectOne Helm chart carries every production setting from the course: config, probes, limits, a safe rolling update, security, a disruption budget, a network policy and autoscaling. Dev and prod differ only in their values files, and a probe Pod proves a release drops no requests.
  • helm lint ./shop -f shop/values-prod.yaml

    Check the chart with the prod values

  • helm template shop ./shop -f shop/values-prod.yaml | grep '^kind:' | sort | uniq -c

    Count the objects an environment renders

  • kind create cluster --config kind.yaml

    Create the three-node practice cluster

  • kind load docker-image shop-web:v1 shop-web:v2 shop-web:v3-broken busybox:1.37 --name capstone

    Copy local images into the kind nodes

  • kubectl label namespace shop pod-security.kubernetes.io/enforce=restricted

    Enforce the restricted Pod Security standard

  • helm upgrade shop ./shop -n shop -f shop/values-prod.yaml --set image.tag=v2 --wait

    Release v2 and wait for it to be ready

  • kubectl logs -n shop probe | sort | uniq -c

    Count versions and FAIL lines seen during the release

  • kind delete cluster --name capstone

    Delete the practice cluster

Remember

  • maxSurge 1 with maxUnavailable 0 keeps full capacity during a release.
  • With autoscaling on, leave replicas to the HPA, or every upgrade resets it.
  • A checksum annotation of the ConfigMap rolls Pods when a setting changes.

Watch for kind load fails the whole command if one image isn't in your local Docker. Pull busybox first.

Open the lesson: Capstone: a production-ready release of shop-web →
← Back to the Kubernetes & Helm course