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
- A Deployment that runs 3 copies of the app
- A Service that gives them one address
Steps
- Save the code as
app.yaml. The---line separates the two objects. - Start a cluster with
minikube start. - Run
kubectl apply -f app.yaml. - Run
kubectl get podsand wait for 3 Pods to beRunning. - Run
minikube service hello-webto open the app in your browser.
Run it
Kubernetes needs a cluster, so this page shows the expected output.
Challenge
- Change
replicasto 5 and apply again. - Add a readiness probe from the probes lesson.
- Delete one Pod and watch Kubernetes create a new one.
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: 80Run this code in the online editor
← Clean up