CKAD-journey

๐Ÿ“œ Canary Deployment Examples

Ready-to-use examples for different scenarios and use cases

๐Ÿ“‹ Available Examples

Basic Examples

Advanced Examples

Service Mesh Examples

CI/CD Examples

๐Ÿš€ Quick Start Examples

5-Minute Demo

# Clone examples
git clone https://github.com/Salwan-Mohamed/CKAD-journey.git
cd CKAD-journey/Master-Canary-Deployments/examples

# Run simple webapp example
kubectl apply -f simple-webapp/

# Watch deployment
kubectl get pods -w -n canary-demo

# Test traffic distribution
kubectl run client --image=curlimages/curl --rm -it -- sh
# Inside pod:
for i in {1..20}; do curl -s http://webapp-service.canary-demo.svc.cluster.local | grep Version; done

Production Example

# Deploy production-ready setup
kubectl apply -f microservice/namespace.yaml
kubectl apply -f microservice/secrets/
kubectl apply -f microservice/configmaps/
kubectl apply -f microservice/deployments/
kubectl apply -f microservice/services/
kubectl apply -f microservice/monitoring/

# Monitor with Grafana
kubectl port-forward -n monitoring svc/grafana 3000:3000
# Open http://localhost:3000

๐Ÿ“Š Example Structure

Each example follows this structure:

example-name/
โ”œโ”€โ”€ README.md                 # Example-specific documentation
โ”œโ”€โ”€ namespace.yaml            # Kubernetes namespace
โ”œโ”€โ”€ configmaps/
โ”‚   โ”œโ”€โ”€ app-config.yaml
โ”‚   โ””โ”€โ”€ monitoring-config.yaml
โ”œโ”€โ”€ secrets/
โ”‚   โ””โ”€โ”€ app-secrets.yaml
โ”œโ”€โ”€ deployments/
โ”‚   โ”œโ”€โ”€ v1-deployment.yaml
โ”‚   โ””โ”€โ”€ v2-deployment.yaml
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ app-service.yaml
โ”‚   โ””โ”€โ”€ monitoring-service.yaml
โ”œโ”€โ”€ monitoring/
โ”‚   โ”œโ”€โ”€ servicemonitor.yaml
โ”‚   โ”œโ”€โ”€ alerts.yaml
โ”‚   โ””โ”€โ”€ dashboard.json
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ deploy.sh
โ”‚   โ”œโ”€โ”€ test.sh
โ”‚   โ””โ”€โ”€ cleanup.sh
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ integration-test.yaml
    โ””โ”€โ”€ load-test.yaml

๐ŸŽฏ Use Case Matrix

Example Complexity Service Mesh Monitoring CI/CD Best For
Simple Web App โญ โŒ Basic Manual Learning
Microservice โญโญ Optional Full Manual Development
Multi-Region โญโญโญ Required Advanced GitOps Enterprise
Feature Flags โญโญ Optional Full Automated Product
A/B Testing โญโญโญ Required Advanced Automated Product
Database Migration โญโญโญ Optional Full Manual Data Heavy

๐Ÿ‹  Customization Guide

Adapting Examples

  1. Change Application
    # Update image references
    sed -i 's/nginx:1.20/your-app:v1.0/g' deployments/*.yaml
       
    # Update service ports
    sed -i 's/port: 80/port: 8080/g' services/*.yaml
    
  2. Modify Traffic Split
    # Change initial canary percentage
    # Edit service selector or VirtualService weights
    
  3. Add Monitoring
    # Copy monitoring configs
    cp ../microservice/monitoring/* ./monitoring/
       
    # Update labels and selectors
    

Environment Variables

Most examples support these environment variables:

export NAMESPACE="my-canary"
export APP_NAME="my-app"
export STABLE_VERSION="v1.0"
export CANARY_VERSION="v2.0"
export REGISTRY="my-registry.com"
export CANARY_PERCENTAGE="10"

# Deploy with custom values
envsubst < deployment-template.yaml | kubectl apply -f -

๐Ÿงช Testing Examples

Validation Script

#!/bin/bash
# validate-example.sh

EXAMPLE_DIR=$1
NAMESPACE=${2:-canary-demo}

if [ -z "$EXAMPLE_DIR" ]; then
    echo "Usage: $0 <example-directory> [namespace]"
    exit 1
fi

echo "๐Ÿงช Testing example: $EXAMPLE_DIR"

# Deploy example
echo "Deploying example..."
kubectl apply -f "$EXAMPLE_DIR/"

# Wait for pods
echo "Waiting for pods to be ready..."
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=webapp -n "$NAMESPACE" --timeout=300s

# Test connectivity
echo "Testing connectivity..."
kubectl run test-client --image=curlimages/curl --rm -it --restart=Never --namespace="$NAMESPACE" -- sh -c '
for i in $(seq 1 10); do
  curl -s http://webapp-service/health || echo "Failed request $i"
done'

# Check metrics (if monitoring enabled)
if kubectl get servicemonitor -n monitoring webapp-monitor &>/dev/null; then
    echo "Checking metrics availability..."
    kubectl port-forward -n monitoring svc/prometheus 9090:9090 &
    sleep 5
    curl -s "http://localhost:9090/api/v1/query?query=up{job='webapp'}" | jq '.data.result'
    pkill -f "kubectl port-forward"
fi

echo "โœ… Example validation completed!"

Load Testing

# load-test-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: canary-load-test
  namespace: canary-demo
spec:
  template:
    spec:
      containers:
      - name: load-test
        image: loadimpact/k6:latest
        command:
        - k6
        - run
        - -
        stdin: true
        stdinOnce: true
        env:
        - name: TARGET_URL
          value: "http://webapp-service.canary-demo.svc.cluster.local"
      restartPolicy: Never
      stdin: true
  backoffLimit: 1
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: load-test-script
  namespace: canary-demo
data:
  test.js: |
    import http from 'k6/http';
    import { check, sleep } from 'k6';
    
    export let options = {
      stages: [
        { duration: '2m', target: 10 },  // Ramp up
        { duration: '5m', target: 10 },  // Stay at 10 users
        { duration: '2m', target: 0 },   // Ramp down
      ],
      thresholds: {
        http_req_duration: ['p(95)<500'],  // 95% of requests under 500ms
        http_req_failed: ['rate<0.1'],     // Error rate under 10%
      },
    };
    
    export default function() {
      let response = http.get(`${__ENV.TARGET_URL}/api/health`);
      
      check(response, {
        'status is 200': (r) => r.status === 200,
        'response time < 500ms': (r) => r.timings.duration < 500,
      });
      
      // Test different endpoints
      http.get(`${__ENV.TARGET_URL}/api/users`);
      http.post(`${__ENV.TARGET_URL}/api/events`, JSON.stringify({
        event: 'page_view',
        user_id: Math.floor(Math.random() * 1000)
      }), {
        headers: { 'Content-Type': 'application/json' },
      });
      
      sleep(1);
    }

๐Ÿ“‹ Example Catalog

By Technology Stack

Frontend Applications

Backend Services

Databases

Message Queues

By Deployment Pattern

Traffic-Based

Feature-Based

Infrastructure-Based

๐Ÿ”— Integration Examples

Observability Stack

# Deploy complete observability
kubectl apply -f examples/observability-stack/

# Includes:
# - Prometheus + Grafana
# - Jaeger tracing
# - FluentD logging
# - AlertManager
# - Custom dashboards

Security Scanning

# Deploy with security scanning
kubectl apply -f examples/security-scan/

# Includes:
# - Falco runtime security
# - OPA Gatekeeper policies
# - Network policies
# - Pod security standards

Chaos Engineering

# Deploy with chaos testing
kubectl apply -f examples/chaos-engineering/

# Includes:
# - Chaos Monkey
# - Network partitions
# - Resource exhaustion
# - Pod failures

๐Ÿ“ฆ Choose your example and start experimenting with canary deployments!

Each example includes detailed README with specific instructions and customization options.