๐ญ Scenario 01: Chaos Strikes Manual Deployments
"Python K8s Automation Saves the Day!"
๐ SCENARIO OVERVIEW
The Challenge
Chaos Agent has infiltrated your Kubernetes deployments! Manual kubectl commands are failing left and right due to missing namespaces, broken ConfigMaps, and service misconfigurations. Your team is frustrated, deployments are unreliable, and production is at risk.
The Hero Solution
Deploy a bulletproof Python automation system that handles Kubernetes deployments with enterprise-grade reliability. No more manual errors, no more missing dependencies, no more chaos!
What You'll Build
- ๐ Python Kubernetes Client automation
- ๐ณ๏ธ Interactive Vote Application for real-world testing
- ๐ Real-time Monitoring System for deployment health
- ๐ก๏ธ Chaos-proof Deployment Process with error handling
โฑ๏ธ TIME ALLOCATION
| Activity | Duration | Type |
|---|---|---|
| Live Demo (Instructor) | 10 minutes | ๐ Watch |
| Your Deployment | 5 minutes | ๐ ๏ธ Hands-on |
| App Interaction | 5 minutes | ๐ฎ Interactive |
| Total | 20 minutes |
๐ฏ LEARNING OBJECTIVES
By completing this scenario, you will:
โ
Understand why manual Kubernetes deployments fail
โ
Master Python Kubernetes client library basics
โ
Implement automated resource creation and management
โ
Experience enterprise-grade error handling
โ
Build monitoring and observability systems
โ
Defeat Chaos Agent's manual deployment attacks! ๐ฆธโโ๏ธ
๐งจ THE CHAOS AGENT'S ATTACK
"Your manual kubectl commands are unreliable! Watch me break your deployments with 'simple' configuration errors! Good luck debugging YAML hell in production!" ๐
What Chaos Agent Breaks:
- โ Missing namespaces cause deployment failures
- โ Wrong ConfigMap names break application startup
- โ Service misconfigurations prevent access
- โ Missing resource limits cause production chaos
- โ No health checks = unknown application state
๐ฆธโโ๏ธ THE PYTHON HERO'S RESPONSE
"Not so fast, Chaos Agent! Python automation makes deployments bulletproof. Watch this!"
How Python Hero Wins:
- โ
Automatic namespace management - creates if missing
- โ
Dependency handling - ConfigMaps before deployments
- โ
Configuration validation - catches errors before applying
- โ
Best practices enforcement - resource limits, health checks
- โ
Graceful error handling - conflicts and failures managed
- โ
Real-time monitoring - know exactly what's happening
๐ FILE STRUCTURE
scenarios/01-python-deploy/
โโโ README.md # This comprehensive guide
โโโ demo-script.sh # Instructor live demo script
โโโ chaos/
โ โโโ broken-vote-app.yaml # Intentionally broken for demo
โ โโโ chaos-explanation.md # What's wrong with manual approach
โโโ hero-solution/
โ โโโ deploy-vote-app.py # ๐ Main Python deployment automation
โ โโโ monitor-deployment.py # ๐ Real-time monitoring system
โ โโโ requirements.txt # Python dependencies
โ โโโ k8s-manifests/ # Generated Kubernetes resources
โ โโโ namespace.yaml
โ โโโ configmap.yaml
โ โโโ deployment.yaml
โ โโโ service.yaml
โโโ participant-guide.md # Step-by-step participant instructions
โโโ troubleshooting.md # Complete troubleshooting guide
๐ QUICK START (For Participants)
Prerequisites
- โ Kubernetes cluster running (Docker Desktop, Minikube, or EKS)
- โ Python 3.8+ installed
- โ kubectl configured and working
Step 1: Environment Setup (2 minutes)
# Navigate to this scenario
cd scenarios/01-python-deploy
# Install Python dependencies
pip3 install -r hero-solution/requirements.txt
# Verify your cluster connection
kubectl cluster-info
Step 2: Deploy with Python Automation (3 minutes)
# Run the Python hero solution
python3 hero-solution/deploy-vote-app.py
Expected Output:
๐ Initializing Python K8s Hero System...
โ
Hero system ready to defeat Chaos Agent!
๐ Creating namespace: vote-app
โ
Namespace created successfully
โ๏ธ Creating ConfigMap with poll configuration
โ
ConfigMap created with poll settings
๐ Creating bulletproof deployment
โ
Deployment created with health checks and resource limits
๐ Creating service for external access
โ
Service created - accessible at port 30001
โณ Waiting for deployment to be ready...
๐ Deployment ready! 2/2 pods running
๐ฏ ACCESS YOUR VOTE APP:
๐ป Local: http://localhost:30001
๐ Minikube: http://$(minikube ip):30001
โ๏ธ EKS: http://<any-node-ip>:30001
๐ CHAOS AGENT DEFEATED!
Step 3: Access Your Vote Application (5 minutes)
The script will provide environment-specific access instructions based on auto-detection:
๐ณ Docker Desktop Environment:
๐ป Primary: http://localhost:31000
๐ If blocked: Use port forwarding below
๐ฏ Minikube Environment:
๐ Minikube: http://<minikube-ip>:31000 (auto-detected)
๐ Auto-open: minikube service vote-app-service -n vote-app
๐ก Manual IP: minikube ip
โ๏ธ Cloud Environment (EKS/GKE/AKS):
๐ Get node IP: kubectl get nodes -o wide
๐ Access: http://<any-external-ip>:31000
๐ Universal Access (Always Works):
# This works on ANY Kubernetes environment - no conflicts!
kubectl port-forward svc/vote-app-service -n vote-app 31500:80
# Then access: http://localhost:31500
# Note: Uses port 31500 to avoid Jenkins (8080) and MkDocs (8000) conflicts
Step 4: Interact with Your Vote App (5 minutes)
Once you access the vote app through any of the above methods:
- ๐ณ๏ธ Cast Your Vote:
- Select your favorite programming language
- Click "Vote" button
-
See your vote recorded instantly
-
๐ Watch Real-time Results:
- View the live chart updating
- See vote percentages change
-
Notice the interactive features
-
๐ Test Multiple Votes:
- Try different browsers
- Vote multiple times (each counts!)
-
Refresh page and see persistence
-
๐ฎ Challenge Others:
- Share your URL with neighbors
- See collaborative voting
- Watch real-time updates from multiple users
Step 5: Monitor Your Deployment (5 minutes)
# Run the monitoring system
python3 hero-solution/monitor-deployment.py
# Choose option:
# 1 = One-time status check
# 2 = Continuous monitoring (Press Ctrl+C to stop)
๐ฌ LIVE DEMO WALKTHROUGH (For Instructors)
Demo Script Overview
Part 1: Chaos Agent Strikes (3 minutes)
# Show the chaos - run this live
./demo-script.sh
What Students See:
1. Manual deployment fails - missing namespace
2. Fix namespace, still fails - missing ConfigMap
3. Create ConfigMap manually, still fails - service misconfiguration
4. Frustration mounts - "This is production reality!"
Part 2: Python Hero Saves the Day (4 minutes)
# Run the hero solution
python3 hero-solution/deploy-vote-app.py
Key Teaching Points: - โจ Automation handles all dependencies - โจ Error handling prevents failures - โจ Best practices applied automatically - โจ Monitoring built-in from the start
Part 3: Victory Celebration (3 minutes)
- Show the working vote app
- Demonstrate real-time voting
- Highlight the automation benefits
- Celebrate defeating Chaos Agent!
๐งช CHAOS TESTING
Test 1: Kill Pods and Watch Recovery
# Kill a random pod
kubectl get pods -n vote-app -o name | xargs -I {} kubectl delete {} --grace-period=0
# Watch Kubernetes recreate it automatically
kubectl get pods -n vote-app -w
Test 2: Scale Up/Down
# Scale up to 5 replicas
kubectl scale deployment vote-app -n vote-app --replicas=5
# Scale down to 1 replica
kubectl scale deployment vote-app -n vote-app --replicas=1
Test 3: Resource Pressure
# Create resource pressure
kubectl run stress-test --image=busybox --requests=cpu=1000m,memory=1Gi --limits=cpu=2000m,memory=2Gi --command -- stress --cpu 4 --vm 2 --vm-bytes 1G
๐ MONITORING & OBSERVABILITY
Real-time Monitoring
# Watch pod status
kubectl get pods -n vote-app -w
# Monitor service endpoints
kubectl get endpoints -n vote-app
# Check resource usage
kubectl top pods -n vote-app
Logs and Debugging
# View application logs
kubectl logs -f deployment/vote-app -n vote-app
# Check events
kubectl get events -n vote-app --sort-by='.lastTimestamp'
๐ฏ SUCCESS CRITERIA
โ Scenario 01 Complete Checklist:
- โ Python automation deployed successfully
- โ Vote application accessible and functional
- โ Real-time voting working
- โ Monitoring system operational
- โ Chaos Agent defeated! ๐ฆธโโ๏ธ
Key Learning Outcomes:
- โ Python Kubernetes Client - Mastered automation
- โ Error Handling - Graceful failure management
- โ Best Practices - Resource limits and health checks
- โ Monitoring - Real-time observability
- โ Chaos Resilience - Survived pod failures
๐ NEXT STEPS
What's Next:
- Scenario 02: Enterprise Security with Secret Management
- Scenario 03: Auto-scaling with HPA
- Scenario 04: Blue-Green Deployment Strategies
- Scenario 05: GitOps with ArgoCD and Argo Rollouts
Production Readiness:
- Apply these Python automation patterns to your real applications
- Implement comprehensive error handling
- Add monitoring and alerting
- Test chaos scenarios regularly
๐ TROUBLESHOOTING
Common Issues:
Issue: Python dependencies not found
# Solution: Install requirements
pip3 install -r hero-solution/requirements.txt
Issue: Kubernetes connection failed
# Solution: Check cluster status
kubectl cluster-info
kubectl get nodes
Issue: Port already in use
# Solution: Use different port
kubectl port-forward svc/vote-app-service -n vote-app 31501:80
Issue: Pods not starting
# Solution: Check events and logs
kubectl get events -n vote-app
kubectl describe pod -n vote-app
๐ CONCLUSION
Congratulations! You've successfully defeated Chaos Agent's manual deployment attacks! ๐ฆธโโ๏ธ
What You've Accomplished:
- โ Automated Kubernetes deployments with Python
- โ Built a real interactive application (vote app)
- โ Implemented enterprise-grade error handling
- โ Created comprehensive monitoring systems
- โ Proven chaos resilience through testing
Key Takeaways:
- Automation is essential for reliable deployments
- Error handling prevents production failures
- Monitoring provides real-time visibility
- Testing chaos scenarios builds confidence
You're now ready for the next challenge: Enterprise Security! ๐
Remember: In the world of Kubernetes, automation is your superpower against chaos! ๐