Sub topic 1
Kubernetes Building Blocks You Will Reuse on EKS
This chapter recaps the Kubernetes objects that every later chapter builds on. EKS runs standard Kubernetes, so nothing here is AWS-specific. It gives you a shared vocabulary before the EKS architecture chapter.
Prerequisites
This chapter assumes you have:
- Basic Kubernetes concepts: pods, deployments, services and namespaces.
- Comfort using
kubectland reading YAML manifests. - Familiarity with IAM, VPC and EC2.
- Command line and AWS CLI basics.
The Working Model
Kubernetes is a declarative system. You describe the state you want in a manifest, and controllers keep working until the cluster matches it. Each object has a spec (what you want) and a status (what exists now). Most debugging comes down to comparing the two.
The objects you will meet most often on EKS:
| Object | Purpose | Where it returns on EKS |
|---|---|---|
| Pod | One or more containers sharing a network identity | Gets a VPC IP address through the VPC CNI |
| Deployment | Keeps N replicas of a pod running and handles rolling updates | Your application workloads |
| Service | Stable virtual IP and DNS name in front of pods | Load balancers are created from Services |
| Ingress | HTTP routing rules | Becomes an Application Load Balancer |
| Namespace | Scope for names, quotas and access rules | RBAC and Pod Identity bind to namespaces |
| ServiceAccount | Identity for a pod | IRSA and Pod Identity attach IAM roles to it |
| PersistentVolumeClaim | Request for storage | Backed by EBS or EFS |
How the Objects Connect
A Deployment creates a ReplicaSet, which creates pods. A Service finds pods by matching labels, not by name. This label match is the most common place for mistakes.
A Minimal Example
This manifest creates a Deployment and a Service. You will reuse it in the chapter on deploying an application.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:stable
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80Three fields must agree for this to work:
spec.selector.matchLabelsin the Deployment must matchtemplate.metadata.labels.- The Service
selectormust match those same pod labels. targetPortmust match the port the container actually listens on.
Apply it and inspect the result:
kubectl apply -f web.yaml
kubectl get deploy,pods,svc -l app=web
kubectl get endpoints webIf the Service has no endpoints, no pod matches its selector or no matching pod is ready.
Common Errors
- Selector mismatch. The Service shows
<none>for endpoints. Comparekubectl get pods --show-labelswith the Service selector. - Pending pods. The scheduler found no node with enough CPU or memory. Run
kubectl describe podand read the Events section. - ImagePullBackOff. The image name or tag is wrong, or the node cannot reach the registry.
- Wrong namespace.
kubectluses thedefaultnamespace unless you pass-nor change your context.
Exercise
A Service named web has no endpoints, although two pods from the Deployment are Running. What is the first thing to check?
Show answer
Compare the Service selector with the pod labels (kubectl get pods --show-labels). A Service only routes to pods whose labels match its selector. A readiness probe failure or a wrong targetPort are the next things to check.