Step‑by‑Step Guide to Deploying and Managing a Kubernetes Web Application
This tutorial walks you through creating a Deployment YAML, customizing it, launching the pod, exposing it via a Service, performing rolling updates, rolling back, scaling replicas, and finally cleaning up, all with concrete kubectl commands and screenshots.
1. Create a YAML template
kubectl create deployment web --image=nginx --dry-run -o yaml > web.yaml2. Edit the template
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- image: zhangfan5391621/java-demo
name: java3. Deploy the pod
kubectl apply -f web.yaml
kubectl logs web-dc77dd8db-hhrxz # check logskubectl get deploy # view deployments4. Create a Service
kubectl expose --name=web deployment web --port=80 --target-port=8080 --type=NodePort
kubectl get service # view service portsAccess the application via any node IP and the assigned NodePort (e.g., 30909).
5. Upgrade the service (rolling update)
kubectl set image deployment web java=nginx
# or edit the service directly if configuration changes
http://192.168.106.103:30909/ # access the updated version6. Roll back the deployment
kubectl rollout history deployment web # view revision historykubectl rollout undo deployment web # revert to previous version
# optionally specify a revision: --revision=37. Scale replicas up or down
kubectl scale deployment web --replicas=5 # expand to 5 pods
kubectl scale deployment web --replicas=2 # shrink to 2 podsAfter scaling, the number of running replicas reflects the new count.
8. Delete the Service and Deployment
kubectl delete deployment/web
kubectl delete svc/webSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
