Kubernetes: Orchestration Basics
Kubernetes orchestrates containerized applications at scale. This article covers Kubernetes fundamentals.
Introduction
Kubernetes provides:
- Container orchestration
- Auto-scaling
- Self-healing
- Rolling updates
- Service discovery
Kubernetes Manifests
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myapp:1.0.0
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: "production"
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
Service
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
Commands
Kubectl Commands
# โ
Good: Deploy application
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
# โ
Good: Check status
kubectl get deployments
kubectl get pods
kubectl get services
# โ
Good: View logs
kubectl logs deployment/app-deployment
kubectl logs pod-name
# โ
Good: Scale deployment
kubectl scale deployment app-deployment --replicas=5
# โ
Good: Update image
kubectl set image deployment/app-deployment app=myapp:2.0.0
# โ
Good: Rollback
kubectl rollout undo deployment/app-deployment
# โ
Good: Delete resources
kubectl delete deployment app-deployment
kubectl delete service app-service
Best Practices
-
Use resource limits:
# โ Good: Resource limits resources: requests: memory: "256Mi" cpu: "250m" limits: memory: "512Mi" cpu: "500m" # โ Bad: No limits -
Use health checks:
# โ Good: Health checks livenessProbe: httpGet: path: /health port: 3000 initialDelaySeconds: 30 # โ Bad: No health checks -
Use namespaces:
# โ Good: Use namespaces kubectl create namespace production kubectl apply -f deployment.yaml -n production # โ Bad: Use default namespace kubectl apply -f deployment.yaml
Summary
Kubernetes is essential. Key takeaways:
- Create deployments
- Define services
- Set resource limits
- Use health checks
- Scale applications
- Update images
- Rollback deployments
- Use namespaces
Related Resources
Next Steps
- Learn about Infrastructure
- Explore CI/CD
- Study Monitoring
- Practice Kubernetes
- Deploy applications
Comments