What You Will Learn
Beginner
- YAML manifest structure in detail
- Common object types
- Best practices for managing YAML
deployment.yamlyaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "500m"YAML Structure
| Section | What it does |
|---|---|
apiVersion | API version (v1, apps/v1, networking.k8s.io/v1) |
kind | Object type (Pod, Deployment, Service, ConfigMap) |
metadata | Name, namespace, labels |
spec | Desired state (containers, replicas, ports) |
Labels are important
Labels (key-value pairs) identify resources. The Deployment selector matches Pod labels. Services use selectors to route traffic to matching Pods.Practical Exercise
Write a Deployment YAML with 3 replicas
Apply: kubectl apply -f deployment.yaml
Check: kubectl get deployments
Check: kubectl get pods - should show 3 Pods
Update replicas to 5, apply again - watch it scale
Key Takeaways
- YAML: apiVersion, kind, metadata, spec.
- Labels connect objects: Deployment selector matches Pod labels.
- Service selector routes to matching Pods.
- Always version your YAML in git.
- kubectl apply -f: create or update. delete -f: remove.
Comments
Comments
Post a Comment