codegurukool.com · Free coding tutorials & online compiler

Home › Kubernetes Tutorial › Live project: Deploy a web app

Live project: Deploy a web app

Run a web app with 3 copies and a Service.

Deploy a small web app the way real teams do: a Deployment plus a Service in one file.

What you will build

Steps

  1. Save the code as app.yaml. The --- line separates the two objects.
  2. Start a cluster with minikube start.
  3. Run kubectl apply -f app.yaml.
  4. Run kubectl get pods and wait for 3 Pods to be Running.
  5. Run minikube service hello-web to open the app in your browser.

Run it

Kubernetes needs a cluster, so this page shows the expected output.

Challenge

Example code

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-web
  template:
    metadata:
      labels:
        app: hello-web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: hello-web
spec:
  type: NodePort
  selector:
    app: hello-web
  ports:
    - port: 80
      targetPort: 80

Run this code in the online editor

← Clean up