Kubernetes for Developers: Getting Started Guide
Kubernetes felt like magic until it didn't work. Then it felt like torture. Let me simplify the core concepts you actually need to know as a developer.
Why Kubernetes?
- Self-healing: Crashed container? Auto-restarted
- Scaling: More traffic? More containers
- Rolling updates: Deploy without downtime
- Service discovery: Containers find each other
Core Concepts
Pod
Smallest deployable unit. Usually one container per pod.
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: app
image: myapp:1.0
ports:
- containerPort: 3000
Deployment
Manages pod replicas. This is what you'll use most.
# deployment.yaml
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: myapp:1.0
ports:
- containerPort: 3000
resources:
limits:
memory: "256Mi"
cpu: "500m"
Service
Exposes pods to network traffic.
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 3000
type: LoadBalancer
Essential Commands
# Apply configuration
kubectl apply -f deployment.yaml
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
# Describe (for debugging)
kubectl describe pod my-app-xyz123
# View logs
kubectl logs my-app-xyz123
kubectl logs -f my-app-xyz123 # Follow
# Execute command in container
kubectl exec -it my-app-xyz123 -- sh
# Delete resources
kubectl delete -f deployment.yaml
ConfigMaps and Secrets
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
NODE_ENV: production
API_URL: https://api.example.com
---
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: app-secrets
type: Opaque
stringData:
DATABASE_URL: postgres://...
JWT_SECRET: mysupersecret
Using in deployment:
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secrets
Local Development
Use Minikube or Docker Desktop Kubernetes:
# Start minikube
minikube start
# Enable dashboard
minikube dashboard
# Build image in minikube's Docker
eval $(minikube docker-env)
docker build -t myapp:1.0 .
Debugging Tips
Pod stuck in Pending:
kubectl describe pod <pod-name>
# Usually: insufficient resources or no matching nodes
Pod in CrashLoopBackOff:
kubectl logs <pod-name> --previous
# Check why the container crashed
Can't connect to service:
kubectl get endpoints <service-name>
# Empty? Your pod labels don't match service selector
What Next?
- Deploy a simple app locally with Minikube
- Learn about Ingress for HTTP routing
- Explore Helm for package management
- Understand namespaces for environment separation
Kubernetes has a steep learning curve, but modern cloud platforms (GKE, EKS) handle most of the complexity. Focus on understanding the abstractions.