Skip to content

๐ŸŽญ 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:

  1. ๐Ÿ—ณ๏ธ Cast Your Vote:
  2. Select your favorite programming language
  3. Click "Vote" button
  4. See your vote recorded instantly

  5. ๐Ÿ“Š Watch Real-time Results:

  6. View the live chart updating
  7. See vote percentages change
  8. Notice the interactive features

  9. ๐Ÿ”„ Test Multiple Votes:

  10. Try different browsers
  11. Vote multiple times (each counts!)
  12. Refresh page and see persistence

  13. ๐ŸŽฎ Challenge Others:

  14. Share your URL with neighbors
  15. See collaborative voting
  16. 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:

  1. Scenario 02: Enterprise Security with Secret Management
  2. Scenario 03: Auto-scaling with HPA
  3. Scenario 04: Blue-Green Deployment Strategies
  4. 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! ๐Ÿš€