How to Deploy a Stateless Web App to Kubernetes (Step-by-Step)

This guide walks through deploying a complete, real-world stateless web application to Kubernetes — from container image to a publicly accessible HTTPS URL — tying together the concepts covered elsewhere in this category.

What "Stateless" Means Here

A stateless application doesn't store important data locally in the container itself (data lives in an external database or object storage instead) — this makes it safe to run multiple identical replicas and freely restart or reschedule any of them.

Prerequisites

  • A working Kubernetes cluster (see How to Install a Single-Node Kubernetes Cluster with k3s)
  • An Nginx Ingress Controller installed (see How to Expose Applications with a Kubernetes Ingress Controller)
  • Your application packaged as a container image, pushed to a registry (Docker Hub or similar)

Step 1 — Create the Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-web-app
  template:
    metadata:
      labels:
        app: my-web-app
    spec:
      containers:
      - name: my-web-app
        image: yourregistry/my-web-app:latest
        ports:
        - containerPort: 3000
        env:
        - name: NODE_ENV
          value: "production"
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 256Mi

Step 2 — Create the Service

apiVersion: v1
kind: Service
metadata:
  name: my-web-app-service
spec:
  selector:
    app: my-web-app
  ports:
  - port: 80
    targetPort: 3000

Step 3 — Create the Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-web-app-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: myapp.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-web-app-service
            port:
              number: 80

Step 4 — Apply Everything

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml

Step 5 — Verify Everything Is Running

kubectl get pods
kubectl get svc
kubectl get ingress

Step 6 — Point DNS and Test

Add an A record for myapp.example.com pointing to your node's IP, then visit the domain to confirm the application loads.

Step 7 — Add HTTPS (Recommended for Production)

Install cert-manager for automated Let's Encrypt certificate provisioning within the cluster, or terminate TLS at an external reverse proxy in front of the cluster — consult cert-manager's official documentation for the current installation steps.

Deploying an Update

kubectl set image deployment/my-web-app my-web-app=yourregistry/my-web-app:v2

Kubernetes performs a rolling update automatically, replacing Pods gradually with zero downtime — see How to Set Up Rolling Updates and Rollbacks in Kubernetes for more control over this process.

Storing Configuration Separately (Recommended)

Move environment-specific values out of the Deployment YAML into a ConfigMap or Secret — see Kubernetes ConfigMaps and Secrets: Managing Configuration Safely.

Common Errors

ImagePullBackOff — the image name/tag is incorrect, or the registry requires authentication that hasn't been configured; check with kubectl describe pod POD_NAME.

CrashLoopBackOff — the application is crashing on startup; check logs with kubectl logs POD_NAME to see the actual error.

Continue Reading

Browse more articles in Kubernetes & Container Orchestration.

  • kubernetes deployment tutorial, deploy app to kubernetes, kubernetes web app, kubernetes step by step
  • 0 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

What Is Kubernetes and When Do You Need It on a VPS?

Kubernetes is a container orchestration platform — it automates deploying, scaling, and...

How to Install a Single-Node Kubernetes Cluster with k3s

k3s is a lightweight, certified Kubernetes distribution designed to run efficiently on modest...

How to Install kubeadm and Set Up a Multi-Node Kubernetes Cluster

kubeadm is the official tool for bootstrapping a standard, full-featured Kubernetes cluster. This...

Kubernetes Pods, Deployments & Services Explained

Understanding these three core Kubernetes objects — Pods, Deployments, and Services —...

How to Expose Applications with a Kubernetes Ingress Controller (Nginx Ingress)

An Ingress lets you route external HTTP/HTTPS traffic to multiple services within your cluster...