Deployment Fundamentals
What is a Kubernetes Deployment?
A Kubernetes Deployment is a crucial resource that provides declarative updates for Pods and ReplicaSets. It allows you to describe the desired state of your application, and the Deployment controller works to maintain that state by creating or deleting pods as needed.
Key Characteristics
Characteristic |
Description |
Scalability |
Easily scale applications up or down |
Rolling Updates |
Update applications with zero downtime |
Self-healing |
Automatically replaces failed pods |
Declarative Management |
Define desired state in configuration |
Basic Deployment Architecture
graph TD
A[Deployment Configuration] --> B[ReplicaSet]
B --> C[Pod 1]
B --> D[Pod 2]
B --> E[Pod 3]
Creating a Simple Deployment
Here's an example of a basic Deployment configuration in Ubuntu:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
Deployment Strategies
1. Recreate Strategy
Terminates all existing pods before creating new ones.
2. Rolling Update Strategy
Gradually replaces pods, ensuring zero downtime during updates.
Practical Deployment Commands
## Create a deployment
kubectl apply -f nginx-deployment.yaml
## Check deployment status
kubectl get deployments
## Scale deployment
kubectl scale deployment nginx-deployment --replicas=5
## Update deployment image
kubectl set image deployment/nginx-deployment nginx=nginx:new-version
Best Practices
- Use labels and selectors effectively
- Define resource limits
- Implement health checks
- Use version control for deployment configurations
Common Use Cases
- Web application hosting
- Microservices deployment
- Stateless application management
By understanding these fundamentals, you'll be well-prepared to manage deployments in Kubernetes. LabEx provides hands-on environments to practice these concepts and improve your skills.