Skip to content

Chapter 14 · Initiate Tutorials

YAML, Deployments, and Services

Manifests are how you write intent into the archive. Labels are how objects find each other in the dark.

Manifests

YAML is the interface for declarative intent.

A manifest describes an object: apiVersion, kind, metadata, and spec. The control plane stores desired state, and controllers reconcile reality toward it.

Apply and observe

shell

kubectl apply -f deployment.yaml
kubectl get deploy web -o wide

Labels and selectors

The hidden glue of Kubernetes.

Labels are key/value tags. Selectors are queries. A Service uses a selector to find Pods; a Deployment uses a selector to own Pods through a ReplicaSet. If you change labels casually, you can cause outages.

Deployment example

A minimal Deployment with probes and resources.

Deployment manifest

yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: nginx
          image: nginx:1.27
          ports:
            - containerPort: 80
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "500m"
              memory: "256Mi"
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 2
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 10
            periodSeconds: 10

Service example

ClusterIP routes to pods via the selector.

Service manifest

yaml

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: ClusterIP
  selector:
    app: web
  ports:
    - name: http
      port: 80
      targetPort: 80

Service types (quick map)

Choose the smallest exposure that solves the problem.

  • ClusterIP: internal-only stable address (default).
  • NodePort: exposes a port on each node (often a building block, rarely final).
  • LoadBalancer: cloud-provider or controller provisions an external load balancer.