Cloud Native 4 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step‑by‑Step Guide to Deploying and Managing a Kubernetes Web Application

1. Create a YAML template

kubectl create deployment web --image=nginx --dry-run -o yaml > web.yaml

2. 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: java

3. Deploy the pod

kubectl apply -f web.yaml
kubectl logs web-dc77dd8db-hhrxz # check logs
kubectl get deploy # view deployments

4. Create a Service

kubectl expose --name=web deployment web --port=80 --target-port=8080 --type=NodePort
kubectl get service # view service ports

Access 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 version

6. Roll back the deployment

kubectl rollout history deployment web # view revision history
kubectl rollout undo deployment web # revert to previous version
# optionally specify a revision: --revision=3

7. Scale replicas up or down

kubectl scale deployment web --replicas=5 # expand to 5 pods
kubectl scale deployment web --replicas=2 # shrink to 2 pods

After scaling, the number of running replicas reflects the new count.

8. Delete the Service and Deployment

kubectl delete deployment/web
kubectl delete svc/web
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DeploymentKubernetesServiceScaleRolling Update
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.