🐳 Containerization & DevOps 2026
Docker & Kubernetes Deployment Guide
Learn how to containerize applications using Docker multi-stage builds and automate container orchestration at scale with Kubernetes clusters and kubectl commands.
1. Multi-Stage Dockerfile Best Practices
Building lightweight, production-ready Docker images requires Multi-Stage Builds. Separate your compilation stage (e.g. Maven/JDK) from the final minimal runtime image (e.g. JRE Alpine) to reduce image size from 800MB to under 150MB.
# Stage 1: Build Java Spring Boot Application
FROM maven:3.9.6-eclipse-temurin-17 AS builder
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests
# Stage 2: Production JRE Lightweight Image
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY --from=builder /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
2. Kubernetes Objects & Cluster Architecture
A. Kubernetes Deployment Manifest (deployment.yaml)
A Deployment manages replica sets of identical Pods, automatically replacing failed containers and supporting zero-downtime rolling updates.
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-app
spec:
replicas: 3
selector:
matchLabels:
app: spring-boot
template:
metadata:
labels:
app: spring-boot
spec:
containers:
- name: spring-boot
image: manishkumar/spring-boot-app:v1.0
ports:
- containerPort: 8080
B. Kubernetes Service & LoadBalancer (service.yaml)
A Service provides a stable virtual IP address and DNS name to route network traffic to healthy Pods.
apiVersion: v1
kind: Service
metadata:
name: spring-boot-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: spring-boot
C. Essential kubectl Cheat Sheet
# Get Pods, Deployments & Services
kubectl get pods -o wide
kubectl get deployments
kubectl get services
# View Container Logs & Describe Pod Details
kubectl logs -f
kubectl describe pod
# Scale Deployment Replicas
kubectl scale deployment spring-boot-app --replicas=5
Kubernetes FAQ
Q1. How does Kubernetes achieve high availability?
Kubernetes monitors container health using Liveness and Readiness probes, automatically restarting crashed containers and rescheduling Pods across available worker nodes.
Q2. What is AWS EKS?
AWS Elastic Kubernetes Service (EKS) is a managed Kubernetes service that handles control plane management, master node backups, and security patching automatically.
Written by Manish Kumar
DevOps Engineer & AWS Solution Architect based in Ghaziabad, UP. Specialized in Linux server administration, Docker CI/CD pipelines, Jenkins automation, and Kubernetes orchestration.