- Core Operations
- Deployment Management
- HPA Operations
- Monitoring and Debugging
- Advanced Configuration
# Verify cluster access and configuration
kubectl cluster-info
kubectl get nodes
# Verify metrics-server installation
kubectl get deployment metrics-server -n kube-system
# Create the NGINX deployment
kubectl apply -f nginx-deployment.yaml
# Verify deployment status
kubectl get deployment nginx
kubectl describe deployment nginx
# Check pod status
kubectl get pods -l app=nginx
# Create HPA using command line
kubectl autoscale deployment nginx \
--cpu-percent=80 \
--min=3 \
--max=10
# Create HPA using configuration file
kubectl apply -f nginx-hpa.yaml
# View HPA status
kubectl get hpa nginx
kubectl describe hpa nginx
# Monitor HPA metrics
kubectl get hpa nginx --watch
# Update existing HPA
kubectl patch hpa nginx --patch \
'{"spec":{"metrics":[{"resource":{"name":"cpu","target":{"averageUtilization":70,"type":"Utilization"}},"type":"Resource"}]}}'
# Delete and recreate HPA
kubectl delete hpa nginx
kubectl apply -f nginx-hpa.yaml
# Monitor pod resource usage
kubectl top pods
kubectl top pods -l app=nginx
# Monitor node resource usage
kubectl top nodes
# Get detailed pod metrics
kubectl describe pod <pod-name>
# View HPA events
kubectl describe hpa nginx | grep -A 10 Events:
# View deployment events
kubectl describe deployment nginx | grep -A 10 Events:
# View pod logs
kubectl logs -l app=nginx --tail=100
# Update deployment resources
kubectl set resources deployment nginx \
--requests=cpu=50m,memory=64Mi \
--limits=cpu=100m,memory=128Mi
# View current resource settings
kubectl get deployment nginx -o jsonpath='{.spec.template.spec.containers[0].resources}'
# Manual scaling (if needed)
kubectl scale deployment nginx --replicas=5
# Check scaling status
kubectl rollout status deployment/nginx
# View replica set status
kubectl get rs -l app=nginx
# Remove HPA
kubectl delete hpa nginx
# Remove deployment
kubectl delete deployment nginx
# Verify cleanup
kubectl get all | grep nginx
- Always verify metrics-server is running before configuring HPA
- Monitor both CPU and memory metrics for optimal scaling
- Use declarative YAML files for better version control
- Implement gradual scaling to prevent resource spikes
- Regular monitoring of HPA events helps in troubleshooting
💡 Best Practice: Always set appropriate resource requests and limits to ensure effective autoscaling.
⚠️ Warning: Removing HPA will not automatically scale down the deployment to its original replica count.
📝 Note: The metrics-server requires a few minutes to collect accurate resource utilization data.