Ready-to-use examples for different scenarios and use cases
# 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
# 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
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
| 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 |
# 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
# Change initial canary percentage
# Edit service selector or VirtualService weights
# Copy monitoring configs
cp ../microservice/monitoring/* ./monitoring/
# Update labels and selectors
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 -
#!/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-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);
}
Frontend Applications
Backend Services
Databases
Message Queues
Traffic-Based
Feature-Based
Infrastructure-Based
# Deploy complete observability
kubectl apply -f examples/observability-stack/
# Includes:
# - Prometheus + Grafana
# - Jaeger tracing
# - FluentD logging
# - AlertManager
# - Custom dashboards
# Deploy with security scanning
kubectl apply -f examples/security-scan/
# Includes:
# - Falco runtime security
# - OPA Gatekeeper policies
# - Network policies
# - Pod security standards
# 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.