Skip to content

☸️ Scenario 05: Deploy to AWS EKS

Overview

This scenario teaches you how to deploy applications to AWS EKS using Jenkins, including both successful and intentionally failing deployments. You'll learn to validate manifests, monitor rollouts, and troubleshoot Kubernetes chaos.


πŸ“ Directory Structure

Jenkins/jenkins_scenarios/scenario_05_deploy_eks/
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Jenkinsfile
β”œβ”€β”€ JenkinsfileAuth
β”œβ”€β”€ Jenkins-Setup.md
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── tests/
    └── deploy/
        β”œβ”€β”€ deployment-pass.yaml
        β”œβ”€β”€ deployment-fail.yaml
        β”œβ”€β”€ service.yaml
        └── configmap.yaml

βœ… How to Set Up the Pipeline in Jenkins UI

  1. Open Jenkins in your browser.
  2. Click "New Item".
  3. Enter a name (e.g., scenario_05_deploy_eks), select Pipeline, and click OK.
  4. In the pipeline config:
  5. Under Pipeline script, select Pipeline script from SCM.
  6. Set SCM to Git and enter your repository URL.
  7. Set Script Path to Jenkins/jenkins_scenarios/scenario_05_deploy_eks/Jenkinsfile.
  8. Click Save.

βœ… How to Run the Pipeline

  1. Click "Build with Parameters".
  2. Set the following parameters as needed:
  3. RUN_SCENARIO_5: Enable/disable scenario
  4. SCENARIO_5_PASS: Run successful deployment test
  5. SCENARIO_5_FAIL: Run failure simulation test
  6. CLUSTER_NAME: EKS cluster name
  7. AWS_REGION: AWS region
  8. CLEANUP_AFTER_TESTS: Clean up resources after tests
  9. Click Build.
  10. Watch the console output for deployment, monitoring, and results.
  11. Download/view reports from Jenkins artifacts after the build completes.

βœ… What the Pipeline Does

  • Builds a Docker image with all dependencies
  • Sets up AWS and Kubernetes access
  • Validates Kubernetes manifests
  • Deploys to EKS (both PASS and FAIL scenarios)
  • Monitors rollout and pod status
  • Optionally cleans up resources after tests
  • Archives reports as Jenkins build artifacts

πŸ§ͺ Chaos Testing Scenarios

βœ… Scenario 1: Deployment Failures

# deployment-fail.yaml - Intentionally broken deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: chaos-app-fail
spec:
  replicas: 3
  selector:
    matchLabels:
      app: chaos-app
  template:
    metadata:
      labels:
        app: chaos-app
    spec:
      containers:
      - name: chaos-app
        image: chaos-app:latest
        resources:
          requests:
            memory: "1Gi"  # Too much memory request
            cpu: "1000m"   # Too much CPU request
        ports:
        - containerPort: 3000

βœ… Scenario 2: Pod Eviction Simulation

def test_pod_eviction():
    """Simulate pod eviction in EKS"""
    # Deploy application
    kubectl_apply("deployment-pass.yaml")

    # Simulate node pressure
    kubectl_drain_node("node-1", "--force", "--ignore-daemonsets")

    # Verify pods reschedule
    pods = kubectl_get_pods("--field-selector=spec.nodeName=node-1")
    assert len(pods) == 0

βœ… Scenario 3: Service Discovery Failures

def test_service_discovery_failure():
    """Test service discovery under chaos"""
    # Deploy service
    kubectl_apply("service.yaml")

    # Simulate DNS failure
    kubectl_patch_service("chaos-app-service", 
                         '{"spec":{"clusterIP":"10.0.0.999"}}')

    # Verify service is unreachable
    with pytest.raises(Exception):
        kubectl_exec("chaos-app-pod", "curl", "chaos-app-service:3000")

βœ… Troubleshooting

  • Cannot connect to EKS:
  • Check kubeconfig and AWS credentials.
  • Ensure your cluster is running and accessible.
  • YAML validation fails:
  • Check for syntax errors in your manifest files in tests/deploy/.
  • Pods stuck or failing:
  • Use Jenkins logs to inspect rollout status and pod events.
  • Build fails:
  • Check for missing dependencies in requirements.txt.
  • Review the Docker build logs for errors.
  • No reports generated:
  • Check the Jenkins workspace and ensure reports are written to the correct directory.

βœ… Useful Commands

  • See running pods and services: bash kubectl get pods kubectl get services
  • Check rollout status: bash kubectl rollout status deployment/<deployment-name>
  • View events for troubleshooting: bash kubectl get events --sort-by=.metadata.creationTimestamp

πŸ“Š Monitoring & Reporting

βœ… Deployment Metrics

  • Deployment success rate
  • Rollout time
  • Pod startup time
  • Resource utilization

βœ… Chaos Metrics

  • Number of deployment failures
  • Recovery time from failures
  • Service discovery reliability
  • Node failure resilience

Next: Scenario 01: Docker Build | Scenario 02: Testcontainers | Scenario 03: HTML Reports | Scenario 04: Manage Secrets


This scenario helps you master Kubernetes deployments in Jenkins, preparing you for real-world cloud CI/CD challenges! πŸ”₯