YAML and kubectl apply

View saved

Why YAML

Files live in git, review cleanly, and recreate environments consistently. Prefer apply over one-off imperative creates for anything you keep.

Minimal Deployment snippet

Save as web.yaml (illustrative):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: nginx
          image: nginx:1.27
          ports:
            - containerPort: 80

Apply and diff

Create or update from file.

kubectl apply -f web.yaml
kubectl get deploy web
kubectl delete -f web.yaml

Validate before apply

Dry-run helps catch schema mistakes.

kubectl apply -f web.yaml --dry-run=client -o yaml

Comments

One comment per signed-in account. Comments are saved with this page’s URL.