Kubernetes 101: Deploying Your First App
While Docker allows us to run isolated containers on a single host, deploying microservices at scale across a cluster of servers requires orchestration. This is where Kubernetes (K8s) excels. Originally developed by Google, Kubernetes automates scheduling, load balancing, scaling, recovery, and configuration management for containerized workloads.
Let's dive into Kubernetes architecture and construct resources for a cluster deployment.
Kubernetes Node Layout
A standard Kubernetes cluster consists of two main layers:
- Control Plane (Master Node): Coordinates the cluster. It manages scheduling, states, APIs, configuration databases, and events.
- Worker Nodes: The execution units. They run individual workloads, configure networking, and enforce proxy load-balancing.
Key Components
Before deployment, you must understand three foundational resources:
- Pod: The smallest deployable unit. It represents a single running process in the cluster and holds one or more containers sharing IP and storage.
- Deployment: A controller that manages replicas of Pods. It handles rolling updates, scale operations, and self-healing (recreating crashed Pods).
- Service: An abstraction defining logical sets of Pods and access policies. It acts as an internal load-balancer with a stable IP.
Constructing a Deployment YAML Manifest
Create a manifest file named app-deployment.yaml to define your application and service:
apiVersion: apps/v1
kind: Deployment
metadata:
name: devops-web-app
labels:
app: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web-container
image: nginx:alpine
ports:
- containerPort: 80
resources:
limits:
cpu: "500m"
memory: "256Mi"
requests:
cpu: "250m"
memory: "128Mi"
---
apiVersion: v1
kind: Service
metadata:
name: devops-web-service
spec:
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Core Commands
Apply these commands to your CLI to interact with the resources:
- Apply Manifests:
kubectl apply -f app-deployment.yaml - View Pods Status:
kubectl get pods -o wide - Inspect Details:
kubectl describe service devops-web-service - Access Cluster Logs:
kubectl logs -l app=web --tail=50 - Manual Scaling:
kubectl scale deployment devops-web-app --replicas=5
Kubernetes provides outstanding reliability. If a server node crashes, K8s immediately schedules replacement pods on functional nodes to preserve uptime.
Written by Swapnil
DevOps & Infrastructure Engineer, focusing on container scaling, secure automated deployment pipelines, and cloud state architecture.