Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Basics Kubernetes Kubernetes: From Zero to Production Module 1 - Kubernetes Fundamentals yaml

The Declarative Model - YAML in Kubernetes

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • How the declarative model works
  • YAML manifest structure
  • kubectl apply vs create

Kubernetes is declarative: you describe the desired state in YAML, and K8s works to make the actual state match it. If a Pod dies, K8s creates a new one to match the desired count.

YAML Manifest Structure

pod.yamlyaml
apiVersion: v1
kind: Pod
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80
FieldWhat it does
apiVersionK8s API version (v1, apps/v1, etc.)
kindObject type (Pod, Deployment, Service)
metadataName, labels, annotations
specDesired state (containers, ports, volumes)

Applying YAML

Terminalbash
# Apply (create or update)
kubectl apply -f pod.yaml

# Create (fails if already exists)
kubectl create -f pod.yaml

# Delete
kubectl delete -f pod.yaml

# View the Pod
kubectl get pods
apply vs create
Use kubectl apply (declarative - creates or updates). Avoid kubectl create (imperative - fails if object exists). apply is the K8s way.

Practical Exercise

Create pod.yaml with the example above
Run: kubectl apply -f pod.yaml
Check: kubectl get pods
Run: kubectl describe pod my-app
Clean up: kubectl delete -f pod.yaml

Key Takeaways

  • K8s is declarative: describe desired state in YAML, K8s makes it happen.
  • YAML has 4 sections: apiVersion, kind, metadata, spec.
  • kubectl apply -f file.yaml: create or update.
  • kubectl delete -f file.yaml: remove.
  • Always use apply (declarative), not create (imperative).
Previously: Lesson 05 covered architecture.
Today: You learned: K8s is declarative - you describe what you want, K8s makes it happen.
Next: Module 1 complete! Module 2 begins with lesson 07.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments