Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 1.71 KB

File metadata and controls

82 lines (63 loc) · 1.71 KB

Task 10: Load Balancing Configuration

Step 1: Switch to Correct Context

kubectl config use-context cluster3-admin@cluster3

Step 2: Create DestinationRule with Load Balancing

kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
  name: cyan-ds
  namespace: cyan
spec:
  host: cyan-echo
  trafficPolicy:
    loadBalancer:
      simple: ROUND_ROBIN
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
EOF

Step 3: Verify Configuration

# Check DestinationRule
kubectl get destinationrule -n cyan -o yaml

# View load balancer configuration
kubectl get destinationrule cyan-ds -n cyan -o yaml | grep -A 3 loadBalancer

Testing

Test Load Distribution

# Create test pod
kubectl exec -n red sleep-red -- curl http://cyan-echo.cyan.svc.cluster.local/normandy

# Check logs
kubectl logs -n cyan cyan-echo -c cyan-echo

Verify Round Robin Behavior

# Continuous testing to observe round robin
kubectl exec -n red sleep-red -- sh -c '
  for i in $(seq 1 10); do
    echo " Request $i: $(curl -s http://cyan-echo.cyan.svc.cluster.local/normandy)"
  done
'

# Should cycle through available pods in order

Verification Commands

# Verify load balancer algorithm
kubectl get destinationrule cyan-ds -n cyan -o jsonpath='{.spec.trafficPolicy.loadBalancer.simple}'

# Should output: ROUND_ROBIN

# Check subsets defined
kubectl get destinationrule cyan-ds -n cyan -o jsonpath='{.spec.subsets[*].name}'

# Test distribution
kubectl exec sleep-red -n red -- sh -c \
  'for i in $(seq 1 50); do curl -s http://cyan-echo.cyan.svc.cluster.local/normandy; done | sort | uniq -c'