Deploying to Kubernetes
Deployment Workflow
graph TD
A[Manifest File] --> B[Kubectl Command]
B --> C[API Server Validation]
C --> D[Resource Creation]
D --> E[Cluster Scheduling]
E --> F[Pod Deployment]
Deployment Methods
1. Direct Kubectl Deployment
## Deploy a single manifest
kubectl apply -f deployment.yaml
## Deploy multiple manifests
kubectl apply -f ./manifests/
## Deploy from directory
kubectl apply -R -f ./kubernetes/
2. Deployment Strategies
Strategy |
Description |
Use Case |
Rolling Update |
Gradual replacement |
Minimal downtime |
Recreate |
Terminate and restart |
Complete replacement |
Blue-Green |
Parallel environments |
Zero-downtime deployments |
Advanced Deployment Techniques
Resource Management
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
Health Checks and Probes
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
periodSeconds: 5
Deployment Verification
Checking Deployment Status
## List deployments
kubectl get deployments
## Describe specific deployment
kubectl describe deployment web-app
## View deployment rollout status
kubectl rollout status deployment/web-app
Scaling Applications
## Manual scaling
kubectl scale deployment web-app --replicas=5
## Autoscaling
kubectl autoscale deployment web-app \
--min=2 --max=10 --cpu-percent=70
Rollback and Version Management
## View deployment history
kubectl rollout history deployment/web-app
## Rollback to previous version
kubectl rollout undo deployment/web-app
## Rollback to specific revision
kubectl rollout undo deployment/web-app --to-revision=2
Deployment Best Practices
- Use declarative configurations
- Implement resource limits
- Configure proper health checks
- Use namespaces for organization
- Implement monitoring and logging
LabEx Deployment Recommendations
- Leverage LabEx's cloud-native infrastructure
- Use consistent naming conventions
- Implement comprehensive monitoring
- Regularly validate and update manifests
Common Deployment Challenges
graph LR
A[Deployment Challenges] --> B[Network Configuration]
A --> C[Resource Allocation]
A --> D[Security Constraints]
A --> E[Performance Optimization]
Troubleshooting Deployment Issues
## View pod logs
kubectl logs pod-name
## Describe pod details
kubectl describe pod pod-name
## Check cluster events
kubectl get events