Kubernetes Components
Understanding the core objects that make up a Kubernetes application: Pods, Services, Deployments, ConfigMaps, and more.
Pod
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web-pod
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
# A Pod runs one or more closely related containers
# Pods are ephemeral โ they can be replaced at any time
Deployment
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
# Deployment ensures 3 replicas are always running
# RollingUpdate provides zero-downtime deployments
Service
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web
type: LoadBalancer
ports:
- port: 80
targetPort: 80
# Service types:
# ClusterIP โ Internal only (default)
# NodePort โ Expose on node IP
# LoadBalancer โ Cloud load balancer
Other Key Objects
ConfigMap โ Store non-sensitive configuration
Secret โ Store sensitive data (base64 encoded)
Ingress โ HTTP routing and TLS termination
PersistentVolume โ Durable storage for stateful apps
Namespace โ Isolate resources within a cluster
ServiceAccount โ Identity for pods to access APIs