First Cluster Deployment
Deployment Fundamentals
Kubernetes Deployment Workflow
graph TD
A[Define Deployment] --> B[Create YAML Configuration]
B --> C[Apply Configuration]
C --> D[Kubernetes Scheduler]
D --> E[Create Pods]
E --> F[Monitor Deployment]
Basic Deployment Concepts
Deployment Types
Type |
Purpose |
Complexity |
Simple Web App |
Stateless Applications |
Low |
Stateful App |
Databases, Persistent Storage |
Medium |
Microservices |
Distributed Systems |
High |
Preparing Deployment Configuration
Sample Nginx Deployment
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 Steps
1. Create Deployment File
mkdir -p ~/kubernetes-demo
cd ~/kubernetes-demo
nano nginx-deployment.yaml
2. Apply Deployment
kubectl apply -f nginx-deployment.yaml
3. Verify Deployment
kubectl get deployments
kubectl get pods
Service Exposure
Create NodePort Service
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30080
Scaling Deployments
Manual Scaling
## Scale to 5 replicas
kubectl scale deployment nginx-deployment --replicas=5
## Scale back to 3 replicas
kubectl scale deployment nginx-deployment --replicas=3
Deployment Strategies
graph LR
A[Deployment Strategies] --> B[Rolling Update]
A --> C[Recreate]
A --> D[Blue-Green]
A --> E[Canary]
Rollback Mechanism
Rollback to Previous Version
## View Deployment History
kubectl rollout history deployment/nginx-deployment
## Rollback to Previous Revision
kubectl rollout undo deployment/nginx-deployment
Monitoring Deployment
Useful Commands
## Detailed Pod Information
kubectl describe pods
## View Logs
kubectl logs deployment/nginx-deployment
LabEx Learning Insights
LabEx provides interactive scenarios that guide you through complex Kubernetes deployment techniques, helping you understand real-world application scenarios.
Best Practices
- Use declarative YAML configurations
- Implement health checks
- Use resource limits
- Practice proper image versioning
- Implement logging and monitoring
Common Deployment Challenges
Potential Issues
- Image pull errors
- Insufficient resources
- Configuration mismatches
- Network connectivity problems
Advanced Deployment Techniques
ConfigMaps and Secrets
- Separate configuration from containers
- Manage sensitive information securely
Persistent Storage
- Use PersistentVolumeClaims
- Handle stateful applications
Conclusion
This guide provides a comprehensive introduction to Kubernetes deployments, covering fundamental concepts, practical examples, and best practices for successful container orchestration.