Kubernetes for Beginners: Pods, Deployments, and Services Explained
A beginner-friendly introduction to Kubernetes — what it is, core concepts (pods, deployments, services, ingress), and how to deploy your first application.
What is Kubernetes?
Kubernetes (K8s) is a container orchestration platform that automates deploying, scaling, and managing containerized applications. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF).
Think of Kubernetes as a system that:
- Runs your Docker containers across multiple servers
- Restarts containers that crash
- Scales up/down based on load
- Routes traffic to healthy containers
- Manages configuration and secrets
Core Concepts
Pods
A Pod is the smallest deployable unit in Kubernetes. It runs one or more containers that share networking and storage.
apiVersion: v1
kind: Pod
metadata:
name: my-app
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 3000
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
You rarely create Pods directly — you use Deployments instead.
Deployments
A Deployment manages a set of identical Pods, handling scaling, updates, and rollbacks.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-app:1.0
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: "production"
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secret
key: url
This creates 3 replicas of your app. If one crashes, Kubernetes automatically creates a replacement.
Services
A Service provides a stable network endpoint for a set of Pods. Pods are ephemeral — they get new IP addresses when recreated. Services give you a consistent way to reach them.
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 3000
type: ClusterIP
Service types:
- ClusterIP (default) — Internal only, accessible within the cluster
- NodePort — Exposes on each node's IP at a static port
- LoadBalancer — Creates an external load balancer (cloud providers)
Ingress
An Ingress manages external HTTP/HTTPS access to services, providing routing rules, SSL termination, and virtual hosting.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt
spec:
tls:
- hosts:
- myapp.com
secretName: myapp-tls
rules:
- host: myapp.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service
port:
number: 80
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
Essential kubectl Commands
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
kubectl get ingress
# Describe (detailed info)
kubectl describe pod my-app-xyz
# Logs
kubectl logs my-app-xyz
kubectl logs -f my-app-xyz # follow
# Apply configuration
kubectl apply -f deployment.yaml
# Scale
kubectl scale deployment my-app --replicas=5
# Delete
kubectl delete -f deployment.yaml
# Port forward (local development)
kubectl port-forward pod/my-app-xyz 3000:3000
# Execute command in pod
kubectl exec -it my-app-xyz -- /bin/sh
ConfigMaps and Secrets
# ConfigMap for non-sensitive config
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_NAME: "My App"
LOG_LEVEL: "info"
---
# Secret for sensitive data
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
stringData:
url: "postgres://user:pass@db:5432/mydb"
api-key: "sk_live_abc123"
Getting Started
- Install kubectl and a local cluster (minikube, kind, or Docker Desktop)
- Write your Deployment YAML
- Apply it:
kubectl apply -f deployment.yaml - Expose it:
kubectl apply -f service.yaml - Check status:
kubectl get pods
Generate Kubernetes YAML with our Kubernetes YAML Generator.
Related Tools & Tutorials
- Kubernetes YAML Generator — Generate K8s manifests
- Dockerfile Generator — Create Dockerfiles
- Docker Compose Generator — Docker Compose files
- YAML Formatter — Format YAML files
- Docker Commands Cheat Sheet — Docker reference
- .env Validator — Validate environment files