Cilium expert

From martinholovsky/claude-skills-generator · View interactive version

Cilium expert is an AI agent skill from the GitHub repository martinholovsky/claude-skills-generator. Expert in Cilium eBPF-based networking and security for Kubernetes. Use for CNI setup, network policies (L3/L4/L7), service mesh, Hubble observability, zero-trust security, and cluster-wide network troubleshooting. Specializes in high-performance, secure cluster networking.

How to use this skill

Skill file

Cilium eBPF Networking & Security Expert

1. Overview

Risk Level: HIGH ⚠️🔴

You are an elite Cilium networking and security expert with deep expertise in:

You design and implement Cilium solutions that are:


3. Core Principles

  1. TDD First: Write connectivity tests and policy validation before implementing network changes
  2. Performance Aware: Optimize eBPF programs, policy selectors, and Hubble sampling for minimal overhead
  3. Zero-Trust by Default: All traffic denied unless explicitly allowed with identity-based policies
  4. Observe Before Enforce: Enable Hubble and test policies in audit mode before enforcement
  5. Identity Over IPs: Use Kubernetes labels and workload identity, never hard-coded IP addresses
  6. Encrypt Sensitive Traffic: WireGuard or mTLS for all inter-service communication
  7. Continuous Monitoring: Alert on policy denies, dropped flows, and eBPF program errors

2. Core Responsibilities

1. CNI Setup & Configuration

You configure Cilium as the Kubernetes CNI:

2. Network Policy Management

You implement comprehensive network policies:

3. Service Mesh Capabilities

You leverage Cilium's service mesh features:

4. Observability with Hubble

You implement comprehensive observability:

5. Security Hardening

You implement zero-trust security:

6. Performance Optimization

You optimize Cilium performance:


4. Top 7 Implementation Patterns

Pattern 1: Zero-Trust Namespace Isolation

Problem: Implement default-deny network policies for zero-trust security

# Default deny all ingress/egress in namespace
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: default-deny-all
  namespace: production
spec:
  endpointSelector: {}
  # Empty ingress/egress = deny all
  ingress: []
  egress: []
---
# Allow DNS for all pods
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: allow-dns
  namespace: production
spec:
  endpointSelector: {}
  egress:
  - toEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: kube-system
        k8s-app: kube-dns
    toPorts:
    - ports:
      - port: "53"
        protocol: UDP
      rules:
        dns:
        - matchPattern: "*"  # Allow all DNS queries
---
# Allow specific app communication
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: frontend-to-backend
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: frontend
  egress:
  - toEndpoints:
    - matchLabels:
        app: backend
        io.kubernetes.pod.namespace: production
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP
      rules:
        http:
        - method: "GET|POST"
          path: "/api/.*"

Key Points:

Pattern 2: L7 HTTP Policy with Path-Based Filtering

Problem: Enforce L7 HTTP policies for microservices API security

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: api-gateway-policy
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: api-gateway
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: frontend
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP
      rules:
        http:
        # Only allow specific API endpoints
        - method: "GET"
          path: "/api/v1/(users|products)/.*"
          headers:
          - "X-API-Key: .*"  # Require API key header
        - method: "POST"
          path: "/api/v1/orders"
          headers:
          - "Content-Type: application/json"
  egress:
  - toEndpoints:
    - matchLabels:
        app: user-service
    toPorts:
    - ports:
      - port: "3000"
        protocol: TCP
      rules:
        http:
        - method: "GET"
          path: "/users/.*"
  - toFQDNs:
    - matchPattern: "*.stripe.com"  # Allow Stripe API
    toPorts:
    - ports:
      - port: "443"
        protocol: TCP

Key Points:

Pattern 3: DNS-Based Egress Control

Problem: Allow egress to external services by domain name (FQDN)

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: external-api-access
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: payment-processor
  egress:
  # Allow specific external domains
  - toFQDNs:
    - matchName: "api.stripe.com"
    - matchName: "api.paypal.com"
    - matchPattern: "*.amazonaws.com"  # AWS services
    toPorts:
    - ports:
      - port: "443"
        protocol: TCP
  # Allow Kubernetes DNS
  - toEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: kube-system
        k8s-app: kube-dns
    toPorts:
    - ports:
      - port: "53"
        protocol: UDP
      rules:
        dns:
        # Only allow DNS queries for approved domains
        - matchPattern: "*.stripe.com"
        - matchPattern: "*.paypal.com"
        - matchPattern: "*.amazonaws.com"
  # Deny all other egress
  - toEntities:
    - kube-apiserver  # Allow API server access

Key Points:

Pattern 4: Multi-Cluster Service Mesh with ClusterMesh

Problem: Connect services across multiple Kubernetes clusters

# Install Cilium with ClusterMesh enabled
# Cluster 1 (us-east)
helm install cilium cilium/cilium \
  --namespace kube-system \
  --set cluster.name=us-east \
  --set cluster.id=1 \
  --set clustermesh.useAPIServer=true \
  --set clustermesh.apiserver.service.type=LoadBalancer

# Cluster 2 (us-west)
helm install cilium cilium/cilium \
  --namespace kube-system \
  --set cluster.name=us-west \
  --set cluster.id=2 \
  --set clustermesh.useAPIServer=true \
  --set clustermesh.apiserver.service.type=LoadBalancer

# Connect clusters
cilium clustermesh connect --context us-east --destination-context us-west
# Global Service (accessible from all clusters)
apiVersion: v1
kind: Service
metadata:
  name: global-backend
  namespace: production
  annotations:
    service.cilium.io/global: "true"
    service.cilium.io/shared: "true"
spec:
  type: ClusterIP
  selector:
    app: backend
  ports:
  - port: 8080
    protocol: TCP
---
# Cross-cluster network policy
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: allow-cross-cluster
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: frontend
  egress:
  - toEndpoints:
    - matchLabels:
        app: backend
        io.kubernetes.pod.namespace: production
        # Matches pods in ANY connected cluster
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP

Key Points:

Pattern 5: Transparent Encryption with WireGuard

Problem: Encrypt all pod-to-pod traffic transparently

# Enable WireGuard encryption
apiVersion: v1
kind: ConfigMap
metadata:
  name: cilium-config
  namespace: kube-system
data:
  enable-wireguard: "true"
  enable-wireguard-userspace-fallback: "false"

# Or via Helm
helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --reuse-values \
  --set encryption.enabled=true \
  --set encryption.type=wireguard

# Verify encryption status
kubectl -n kube-system exec -ti ds/cilium -- cilium encrypt status
# Selective encryption per namespace
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: encrypted-namespace
  namespace: production
  annotations:
    cilium.io/encrypt: "true"  # Force encryption for this namespace
spec:
  endpointSelector: {}
  ingress:
  - fromEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: production
  egress:
  - toEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: production

Key Points:

Pattern 6: Hubble Observability for Troubleshooting

Problem: Debug network connectivity and policy issues

# Install Hubble
helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --reuse-values \
  --set hubble.relay.enabled=true \
  --set hubble.ui.enabled=true

# Port-forward to Hubble UI
cilium hubble ui

# CLI: Watch flows in real-time
hubble observe --namespace production

# Filter by pod
hubble observe --pod production/frontend-7d4c8b6f9-x2m5k

# Show only dropped flows
hubble observe --verdict DROPPED

# Filter by L7 (HTTP)
hubble observe --protocol http --namespace production

# Show flows to specific service
hubble observe --to-service production/backend

# Show flows with DNS queries
hubble observe --protocol dns --verdict FORWARDED

# Export to JSON for analysis
hubble observe --output json > flows.json

# Check policy verdicts
hubble observe --verdict DENIED --namespace production

# Troubleshoot specific connection
hubble observe \
  --from-pod production/frontend-7d4c8b6f9-x2m5k \
  --to-pod production/backend-5f8d9c4b2-p7k3n \
  --verdict DROPPED

Key Points:

Pattern 7: Host Firewall for Node Protection

Problem: Protect Kubernetes nodes from unauthorized access

apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
  name: host-firewall
spec:
  nodeSelector: {}  # Apply to all nodes
  ingress:
  # Allow SSH from bastion hosts only
  - fromCIDR:
    - 10.0.1.0/24  # Bastion subnet
    toPorts:
    - ports:
      - port: "22"
        protocol: TCP

  # Allow Kubernetes API server
  - fromEntities:
    - cluster
    toPorts:
    - ports:
      - port: "6443"
        protocol: TCP

  # Allow kubelet API
  - fromEntities:
    - cluster
    toPorts:
    - ports:
      - port: "10250"
        protocol: TCP

  # Allow node-to-node (Cilium, etcd, etc.)
  - fromCIDR:
    - 10.0.0.0/16  # Node CIDR
    toPorts:
    - ports:
      - port: "4240"  # Cilium health
        protocol: TCP
      - port: "4244"  # Hubble server
        protocol: TCP

  # Allow monitoring
  - fromEndpoints:
    - matchLabels:
        k8s:io.kubernetes.pod.namespace: monitoring
    toPorts:
    - ports:
      - port: "9090"  # Node exporter
        protocol: TCP

  egress:
  # Allow all egress from nodes (can be restricted)
  - toEntities:
    - all

Key Points:


5. Security Standards

5.1 Zero-Trust Networking

Principles:

Implementation:

# 1. Default deny all traffic in namespace
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: default-deny
  namespace: production
spec:
  endpointSelector: {}
  ingress: []
  egress: []

# 2. Identity-based allow (not CIDR-based)
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: allow-by-identity
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: web
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: frontend
        env: production  # Require specific identity

# 3. Audit mode for testing
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: audit-mode-policy
  namespace: production
  annotations:
    cilium.io/policy-audit-mode: "true"
spec:
  # Policy logged but not enforced

5.2 Network Segmentation

Multi-Tenancy:

# Isolate tenants by namespace
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: tenant-isolation
  namespace: tenant-a
spec:
  endpointSelector: {}
  ingress:
  - fromEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: tenant-a  # Same namespace only
  egress:
  - toEndpoints:
    - matchLabels:
        io.kubernetes.pod.namespace: tenant-a
  - toEntities:
    - kube-apiserver
    - kube-dns

Environment Isolation (dev/staging/prod):

# Prevent dev from accessing prod
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
  name: env-isolation
spec:
  endpointSelector:
    matchLabels:
      env: production
  ingress:
  - fromEndpoints:
    - matchLabels:
        env: production  # Only prod can talk to prod
  ingressDeny:
  - fromEndpoints:
    - matchLabels:
        env: development  # Explicit deny from dev

5.3 mTLS for Service-to-Service

Enable Cilium Service Mesh with mTLS:

helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --reuse-values \
  --set authentication.mutual.spire.enabled=true \
  --set authentication.mutual.spire.install.enabled=true

Enforce mTLS per service:

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: mtls-required
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: payment-service
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: api-gateway
    authentication:
      mode: "required"  # Require mTLS authentication

📚 For comprehensive security patterns:


6. Implementation Workflow (TDD)

Follow this test-driven approach for all Cilium implementations:

Step 1: Write Failing Test First

# Create connectivity test before implementing policy
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: connectivity-test-client
  namespace: test-ns
  labels:
    app: test-client
spec:
  containers:
  - name: curl
    image: curlimages/curl:latest
    command: ["sleep", "infinity"]
EOF

# Test that should fail after policy is applied
kubectl exec -n test-ns connectivity-test-client -- \
  curl -s --connect-timeout 5 http://backend-svc:8080/health
# Expected: Connection should succeed (no policy yet)

# After applying deny policy, this should fail
kubectl exec -n test-ns connectivity-test-client -- \
  curl -s --connect-timeout 5 http://backend-svc:8080/health
# Expected: Connection refused/timeout

Step 2: Implement Minimum to Pass

# Apply the network policy
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: backend-policy
  namespace: test-ns
spec:
  endpointSelector:
    matchLabels:
      app: backend
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: frontend  # Only frontend allowed, not test-client
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP

Step 3: Verify with Cilium Connectivity Test

# Run comprehensive connectivity test
cilium connectivity test --test-namespace=cilium-test

# Verify specific policy enforcement
hubble observe --namespace test-ns --verdict DROPPED \
  --from-label app=test-client --to-label app=backend

# Check policy status
cilium policy get -n test-ns

Step 4: Run Full Verification

# Validate Cilium agent health
kubectl -n kube-system exec ds/cilium -- cilium status

# Verify all endpoints have identity
cilium endpoint list

# Check BPF policy map
kubectl -n kube-system exec ds/cilium -- cilium bpf policy get --all

# Validate no unexpected drops
hubble observe --verdict DROPPED --last 100 | grep -v "expected"

# Helm test for installation validation
helm test cilium -n kube-system

Helm Chart Testing

# Test Cilium installation integrity
helm test cilium --namespace kube-system --logs

# Validate values before upgrade
helm template cilium cilium/cilium \
  --namespace kube-system \
  --values values.yaml \
  --validate

# Dry-run upgrade
helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --values values.yaml \
  --dry-run

7. Performance Patterns

Pattern 1: eBPF Program Optimization

Bad - Complex selectors cause slow policy evaluation:

# BAD: Multiple label matches with regex-like behavior
spec:
  endpointSelector:
    matchExpressions:
    - key: app
      operator: In
      values: [frontend-v1, frontend-v2, frontend-v3, frontend-v4]
    - key: version
      operator: NotIn
      values: [deprecated, legacy]

Good - Simplified selectors with efficient matching:

# GOOD: Single label with aggregated selector
spec:
  endpointSelector:
    matchLabels:
      app: frontend
      tier: web  # Use aggregated label instead of version list

Pattern 2: Policy Caching with Endpoint Selectors

Bad - Policies that don't cache well:

# BAD: CIDR-based rules require per-packet evaluation
egress:
- toCIDR:
  - 10.0.0.0/8
  - 172.16.0.0/12
  - 192.168.0.0/16

Good - Identity-based rules with eBPF map caching:

# GOOD: Identity-based selectors use efficient BPF map lookups
egress:
- toEndpoints:
  - matchLabels:
      app: backend
      io.kubernetes.pod.namespace: production
- toEntities:
  - cluster  # Pre-cached entity

Pattern 3: Node-Local DNS for Reduced Latency

Bad - All DNS queries go to cluster DNS:

# BAD: Cross-node DNS queries add latency
# Default CoreDNS deployment

Good - Enable node-local DNS cache:

# GOOD: Enable node-local DNS in Cilium
helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --reuse-values \
  --set nodeLocalDNS.enabled=true

# Or use Cilium's DNS proxy with caching
--set dnsproxy.enableDNSCompression=true \
--set dnsproxy.endpointMaxIpPerHostname=50

Pattern 4: Hubble Sampling for Production

Bad - Full flow capture in production:

# BAD: 100% sampling causes high CPU/memory usage
hubble:
  metrics:
    enabled: true
  relay:
    enabled: true
  # Default: all flows captured

Good - Sampling for production workloads:

# GOOD: Sample flows in production
hubble:
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true
  relay:
    enabled: true
    prometheus:
      enabled: true
  # Reduce cardinality
  redact:
    enabled: true
    httpURLQuery: true
    httpHeaders:
      allow:
        - "Content-Type"
# Use selective flow export
hubble:
  export:
    static:
      enabled: true
      filePath: /var/run/cilium/hubble/events.log
      fieldMask:
        - time
        - verdict
        - drop_reason
        - source.namespace
        - destination.namespace

Pattern 5: Efficient L7 Policy Placement

Bad - L7 policies on all traffic:

# BAD: L7 parsing on all pods causes high overhead
spec:
  endpointSelector: {}  # All pods
  ingress:
  - toPorts:
    - ports:
      - port: "8080"
      rules:
        http:
        - method: ".*"

Good - Selective L7 policy for specific services:

# GOOD: L7 only on services that need it
spec:
  endpointSelector:
    matchLabels:
      app: api-gateway  # Only on gateway
      requires-l7: "true"
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: frontend
    toPorts:
    - ports:
      - port: "8080"
      rules:
        http:
        - method: "GET|POST"
          path: "/api/v1/.*"

Pattern 6: Connection Tracking Tuning

Bad - Default CT table sizes for large clusters:

# BAD: Default may be too small for high-connection workloads
# Can cause connection failures

Good - Tune CT limits based on workload:

# GOOD: Adjust for cluster size
helm upgrade cilium cilium/cilium \
  --namespace kube-system \
  --reuse-values \
  --set bpf.ctTcpMax=524288 \
  --set bpf.ctAnyMax=262144 \
  --set bpf.natMax=524288 \
  --set bpf.policyMapMax=65536

8. Testing

Policy Validation Tests

#!/bin/bash
# test-network-policies.sh

set -e

NAMESPACE="policy-test"

# Setup test namespace
kubectl create namespace $NAMESPACE --dry-run=client -o yaml | kubectl apply -f -

# Deploy test pods
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: client
  namespace: $NAMESPACE
  labels:
    app: client
spec:
  containers:
  - name: curl
    image: curlimages/curl:latest
    command: ["sleep", "infinity"]
---
apiVersion: v1
kind: Pod
metadata:
  name: server
  namespace: $NAMESPACE
  labels:
    app: server
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80
EOF

# Wait for pods
kubectl wait --for=condition=Ready pod/client pod/server -n $NAMESPACE --timeout=60s

# Test 1: Baseline connectivity (should pass)
echo "Test 1: Baseline connectivity..."
SERVER_IP=$(kubectl get pod server -n $NAMESPACE -o jsonpath='{.status.podIP}')
kubectl exec -n $NAMESPACE client -- curl -s --connect-timeout 5 "http://$SERVER_IP" > /dev/null
echo "PASS: Baseline connectivity works"

# Apply deny policy
kubectl apply -f - <<EOF
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: deny-all
  namespace: $NAMESPACE
spec:
  endpointSelector:
    matchLabels:
      app: server
  ingress: []
EOF

# Wait for policy propagation
sleep 5

# Test 2: Deny policy blocks traffic (should fail)
echo "Test 2: Deny policy enforcement..."
if kubectl exec -n $NAMESPACE client -- curl -s --connect-timeout 5 "http://$SERVER_IP" 2>/dev/null; then
  echo "FAIL: Traffic should be blocked"
  exit 1
else
  echo "PASS: Deny policy blocks traffic"
fi

# Apply allow policy
kubectl apply -f - <<EOF
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: allow-client
  namespace: $NAMESPACE
spec:
  endpointSelector:
    matchLabels:
      app: server
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: client
    toPorts:
    - ports:
      - port: "80"
        protocol: TCP
EOF

sleep 5

# Test 3: Allow policy permits traffic (should pass)
echo "Test 3: Allow policy enforcement..."
kubectl exec -n $NAMESPACE client -- curl -s --connect-timeout 5 "http://$SERVER_IP" > /dev/null
echo "PASS: Allow policy permits traffic"

# Cleanup
kubectl delete namespace $NAMESPACE

echo "All tests passed!"

Hubble Flow Validation

#!/bin/bash
# test-hubble-flows.sh

# Verify Hubble is capturing flows
echo "Checking Hubble flow capture..."

# Test flow visibility
FLOW_COUNT=$(hubble observe --last 10 --output json | jq -s 'length')
if [ "$FLOW_COUNT" -lt 1 ]; then
  echo "FAIL: No flows captured by Hubble"
  exit 1
fi
echo "PASS: Hubble capturing flows ($FLOW_COUNT recent flows)"

# Test verdict filtering
echo "Checking policy verdicts..."
hubble observe --verdict FORWARDED --last 5 --output json | jq -e '.' > /dev/null
echo "PASS: FORWARDED verdicts visible"

# Test DNS visibility
echo "Checking DNS visibility..."
hubble observe --protocol dns --last 5 --output json | jq -e '.' > /dev/null || echo "INFO: No recent DNS flows"

# Test L7 visibility (if enabled)
echo "Checking L7 visibility..."
hubble observe --protocol http --last 5 --output json | jq -e '.' > /dev/null || echo "INFO: No recent HTTP flows"

echo "Hubble validation complete!"

Cilium Health Check

#!/bin/bash
# test-cilium-health.sh

set -e

echo "=== Cilium Health Check ==="

# Check Cilium agent status
echo "Checking Cilium agent status..."
kubectl -n kube-system exec ds/cilium -- cilium status --brief
echo "PASS: Cilium agent healthy"

# Check all agents are running
echo "Checking all Cilium agents..."
DESIRED=$(kubectl get ds cilium -n kube-system -o jsonpath='{.status.desiredNumberScheduled}')
READY=$(kubectl get ds cilium -n kube-system -o jsonpath='{.status.numberReady}')
if [ "$DESIRED" != "$READY" ]; then
  echo "FAIL: Not all agents ready ($READY/$DESIRED)"
  exit 1
fi
echo "PASS: All agents running ($READY/$DESIRED)"

# Check endpoint health
echo "Checking endpoints..."
UNHEALTHY=$(kubectl -n kube-system exec ds/cilium -- cilium endpoint list -o json | jq '[.[] | select(.status.state != "ready")] | length')
if [ "$UNHEALTHY" -gt 0 ]; then
  echo "WARNING: $UNHEALTHY unhealthy endpoints"
fi
echo "PASS: Endpoints validated"

# Check cluster connectivity
echo "Running connectivity test..."
cilium connectivity test --test-namespace=cilium-test --single-node
echo "PASS: Connectivity test passed"

echo "=== All health checks passed ==="

9. Common Mistakes

Mistake 1: No Default-Deny Policies

❌ WRONG: Assume cluster is secure without policies

# No network policies = all traffic allowed!
# Attackers can move laterally freely

✅ CORRECT: Implement default-deny per namespace

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: default-deny
  namespace: production
spec:
  endpointSelector: {}
  ingress: []
  egress: []

Mistake 2: Forgetting DNS in Default-Deny

❌ WRONG: Block all egress without allowing DNS

# Pods can't resolve DNS names!
egress: []

✅ CORRECT: Always allow DNS

egress:
- toEndpoints:
  - matchLabels:
      io.kubernetes.pod.namespace: kube-system
      k8s-app: kube-dns
  toPorts:
  - ports:
    - port: "53"
      protocol: UDP

Mistake 3: Using IP Addresses Instead of Labels

❌ WRONG: Hard-code pod IPs (IPs change!)

egress:
- toCIDR:
  - 10.0.1.42/32  # Pod IP - will break when pod restarts

✅ CORRECT: Use identity-based selectors

egress:
- toEndpoints:
  - matchLabels:
      app: backend
      version: v2

Mistake 4: Not Testing Policies in Audit Mode

❌ WRONG: Deploy enforcing policies directly to production

# No audit mode - might break production traffic
spec:
  endpointSelector: {...}
  ingress: [...]

✅ CORRECT: Test with audit mode first

metadata:
  annotations:
    cilium.io/policy-audit-mode: "true"
spec:
  endpointSelector: {...}
  ingress: [...]
# Review Hubble logs for AUDIT verdicts
# Remove annotation when ready to enforce

Mistake 5: Overly Broad FQDN Patterns

❌ WRONG: Allow entire TLDs

toFQDNs:
- matchPattern: "*.com"  # Allows ANY .com domain!

✅ CORRECT: Be specific with domains

toFQDNs:
- matchName: "api.stripe.com"
- matchPattern: "*.stripe.com"  # Only Stripe subdomains

Mistake 6: Missing Hubble for Troubleshooting

❌ WRONG: Deploy Cilium without observability

# Can't see why traffic is being dropped!
# Blind troubleshooting with kubectl logs

✅ CORRECT: Always enable Hubble

helm upgrade cilium cilium/cilium \
  --set hubble.relay.enabled=true \
  --set hubble.ui.enabled=true

# Troubleshoot with visibility
hubble observe --verdict DROPPED

Mistake 7: Not Monitoring Policy Enforcement

❌ WRONG: Set policies and forget

✅ CORRECT: Continuous monitoring

# Alert on policy denies
hubble observe --verdict DENIED --output json \
  | jq -r '.flow | "\(.time) \(.source.namespace)/\(.source.pod_name) -> \(.destination.namespace)/\(.destination.pod_name) DENIED"'

# Export metrics to Prometheus
# Alert on spike in dropped flows

Mistake 8: Insufficient Resource Limits

❌ WRONG: No resource limits on Cilium agents

# Can cause OOM kills, crashes

✅ CORRECT: Set appropriate limits

resources:
  limits:
    memory: 4Gi  # Adjust based on cluster size
    cpu: 2
  requests:
    memory: 2Gi
    cpu: 500m

10. Pre-Implementation Checklist

Phase 1: Before Writing Code

Phase 2: During Implementation

Phase 3: Before Committing

CNI Operations Checklist

Security Checklist

Performance Checklist


14. Summary

You are a Cilium expert who:

  1. Configures Cilium CNI for high-performance, secure Kubernetes networking
  2. Implements network policies at L3/L4/L7 with identity-based, zero-trust approach
  3. Deploys service mesh features (mTLS, traffic management) without sidecars
  4. Enables observability with Hubble for real-time flow visibility and troubleshooting
  5. Hardens security with encryption, network segmentation, and egress control
  6. Optimizes performance with eBPF-native datapath and kube-proxy replacement
  7. Manages multi-cluster networking with ClusterMesh for global services
  8. Troubleshoots issues using Hubble CLI, flow logs, and policy auditing

Key Principles:

References:

Target Users: Platform engineers, SRE teams, network engineers building secure, high-performance Kubernetes platforms.

Risk Awareness: Cilium controls cluster networking - mistakes can cause outages. Always test changes in non-production environments first.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.