Roadmaps / DevOps & Cloud / Lab 5

Lab 5 of 8 · Kubernetes

Run your app on a local Kubernetes cluster

Create a free local cluster with kind, deploy two copies of your app, watch Kubernetes heal it, and scale it.

Time
60–90 minutes
Cost
Free: the cluster runs inside Docker on your computer.

What you learn

Kubernetes runs many copies of containers, restarts them when they fail and spreads traffic between them. It is the standard platform for running services, and increasingly for serving AI models.

  • Clusters, pods, deployments and services
  • Readiness checks and resource limits
  • Self-healing and scaling
  • kubectl for inspecting and fixing problems

In the AI era: GPU workloads and model servers (for example vLLM and KServe) are usually run on Kubernetes. Requests and limits, which you set in this lab, are how teams control what AI workloads cost.

Before you start

  • Finish lab 2 (you need the ai-status-app:1.0 image).

  • Install kind and kubectl. Check with kind version and kubectl version --client.

Step by step

  1. 1 Create a cluster

    kind runs a whole Kubernetes cluster inside a Docker container.

    Run this
    kind create cluster --name devops-lab
    kubectl get nodes
    You should see:

    One node named devops-lab-control-plane with status Ready.

  2. 2 Load your image into the cluster

    The cluster cannot see images on your computer until you load them.

    Run this
    kind load docker-image ai-status-app:1.0 --name devops-lab
  3. 3 Describe the deployment and service

    The Deployment keeps two copies running and only sends traffic to a copy once /health answers. The Service gives them one stable address.

    File: k8s/app.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ai-status-app
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: ai-status-app
      template:
        metadata:
          labels:
            app: ai-status-app
        spec:
          containers:
            - name: app
              image: ai-status-app:1.0
              imagePullPolicy: IfNotPresent
              ports:
                - containerPort: 8000
              readinessProbe:
                httpGet:
                  path: /health
                  port: 8000
              resources:
                requests:
                  cpu: 50m
                  memory: 64Mi
                limits:
                  cpu: 250m
                  memory: 256Mi
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: ai-status-app
    spec:
      selector:
        app: ai-status-app
      ports:
        - port: 80
          targetPort: 8000
    
  4. 4 Deploy it

    Wait until both pods show 1/1 Running, then press Ctrl+C to stop watching.

    Run this
    kubectl apply -f k8s/app.yaml
    kubectl get pods -w
    You should see:

    Two ai-status-app-... pods, 1/1 Running.

  5. 5 Reach the app

    Port-forward connects your computer to the service. Leave it running and use a second terminal for curl.

    Run this
    kubectl port-forward service/ai-status-app 8080:80
    # in a second terminal:
    curl http://localhost:8080/health
    You should see:

    {"status":"ok"}.

  6. 6 Watch it heal

    Delete one pod. Kubernetes notices there is one copy too few and starts a new one.

    Run this
    kubectl delete pod "$(kubectl get pods -l app=ai-status-app -o name | head -n 1 | cut -d/ -f2)"
    kubectl get pods
    You should see:

    A brand-new pod with a young AGE, and two pods running again.

  7. 7 Scale and inspect

    describe and logs are the first two commands to run when a pod misbehaves.

    Run this
    kubectl scale deployment ai-status-app --replicas=3
    kubectl get pods
    kubectl describe deployment ai-status-app | head -n 20
    kubectl logs deployment/ai-status-app
    You should see:

    Three pods, and 3 desired | 3 updated | 3 total | 3 available in the description.

  8. 8 Commit, then delete the cluster

    Delete the cluster when you are done; you can recreate it in a minute.

    Run this
    git add k8s
    git commit -m "Add Kubernetes deployment and service"
    git push
    kind delete cluster --name devops-lab

You are done when

  • You saw Kubernetes replace a deleted pod by itself.

  • You scaled the deployment and read kubectl describe and kubectl logs.

  • k8s/app.yaml is on GitHub.

Finished? Get your proof page

We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.