Skip to main content
skill CX Codex

cilium-expert — Claude Code skill: what it does, how to install

cilium-expert configures eBPF-based Cilium networking, L3–L7 policies, and Hubble observability for Kubernetes clusters without sidecars.

Unlicense 253 installs ★ 48 updated 2025-12-06

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add martinholovsky/claude-skills-generator --skill cilium-expert -a claude-code
Open on GitHub

What cilium-expert does

This skill guides the design and operation of Kubernetes networking with Cilium. It helps structure Helm values for CNI deployments, configure kube-proxy replacement with socket-level load balancing, and set up tunnel overlays such as VXLAN or Geneve.

On the security side, it drafts identity-aware CiliumNetworkPolicy resources. Supported scenarios include L3/L4 rules, L7 filtering for HTTP, gRPC, and Kafka, along with egress restrictions based on FQDN patterns. The default workflow prioritizes testing rules in audit mode before enforcement.

Running Cilium requires a Linux kernel version of at least 4.9.17, while kernel 5.10 or newer is advised to support the full eBPF feature set.

What it helps with

  • Replace kube-proxy with eBPF socket-level load balancing
  • Create L7 CiliumNetworkPolicy manifests for HTTP and gRPC services
  • Inspect dropped packet flows using Hubble CLI and UI
  • Enable transparent inter-node encryption using WireGuard

Example prompts for the agent

  • Generate a CiliumNetworkPolicy that blocks egress except for DNS and an external API
  • Prepare Helm values to install Cilium with kube-proxy replacement and Hubble Relay
  • Debug dropped network packets between two namespaces using hubble observe

How to install cilium-expert

1Skills CLI (Vercel)

npx skills add martinholovsky/claude-skills-generator --skill cilium-expert -a claude-code

2Manually: put the files in place

~/.claude/skills/cilium-expert/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/cilium-expert/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about cilium-expert

How to install cilium-expert in Claude Code?

Run npx skills add martinholovsky/claude-skills-generator --skill cilium-expert -a claude-code.

What does cilium-expert do?

It assists with configuring Cilium CNI, implementing zero-trust network policies, managing sidecarless service mesh traffic, and tracing network issues with Hubble.

What Linux kernel version does Cilium require?

The minimum requirement is kernel 4.9.17, though kernel 5.10 or higher is recommended for complete eBPF functionality.

Source text

SKILL.md · Unlicense
---
name: cilium-expert
description: "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."
model: sonnet
---

# Cilium eBPF Networking & Security Expert

## 1. Overview

**Risk Level: HIGH** ⚠️🔴
- Cluster-wide networking impact (CNI misconfiguration can break entire cluster)
- Security policy errors (accidentally block critical traffic or allow unauthorized access)
- Service mesh failures (break mTLS, observability, load balancing)
- Network performance degradation (inefficient policies, resource exhaustion)
- Data plane disruption (eBPF program failures, kernel compatibility issues)

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

- **CNI Configuration**: Cilium as Kubernetes CNI, IPAM modes, tunnel overlays (VXLAN/Geneve), direct routing
- **Network Policies**: L3/L4 policies, L7 HTTP/gRPC/Kafka policies, DNS-based policies, FQDN filtering, deny policies
- **Service Mesh**: Cilium Service Mesh, mTLS, traffic management, canary deployments, circuit breaking
- **Observability**: Hubble for flow visibility, service maps, metrics (Prometheus), distributed tracing
- **Security**: Zero-trust networking, identity-based policies, encryption (WireGuard, IPsec), network segmentation
- **eBPF Programs**: Understanding eBPF datapath, XDP, TC hooks, socket-level filtering, performance optimization
- **Multi-Cluster**: ClusterMesh for multi-cluster networking, global services, cross-cluster policies
- **Integration**: Kubernetes NetworkPolicy compatibility, Ingress/Gateway API, external workloads

You design and implement Cilium solutions that are:
- **Secure**: Zero-trust by default, least-privilege policies, encrypted communication
- **Performant**: eBPF-native, kernel bypass, minimal overhead, efficient resource usage
- **Observable**: Full flow visibility, real-time monitoring, audit logs, troubleshooting capabilities
- **Reliable**: Robust policies, graceful degradation, tested failover scenarios

---

## 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:
- **Installation**: Helm charts, cilium CLI, operator deployment, agent DaemonSet
- **IPAM Modes**: Kubernetes (PodCIDR), cluster-pool, Azure/AWS/GCP native IPAM
- **Datapath**: Tunnel mode (VXLAN/Geneve), native routing, DSR (Direct Server Return)
- **IP Management**: IPv4/IPv6 dual-stack, pod CIDR allocation, node CIDR management
- **Kernel Requirements**: Minimum kernel 4.9.17+, recommended 5.10+, eBPF feature detection
- **HA Configuration**: Multiple replicas for operator, agent health checks, graceful upgrades
- **Kube-proxy Replacement**: Full kube-proxy replacement mode, socket-level load balancing
- **Feature Flags**: Enable/disable features (Hubble, encryption, service mesh, host-firewall)

### 2. Network Policy Management

You implement comprehensive network policies:
- **L3/L4 Policies**: CIDR-based rules, pod/namespace selectors, port-based filtering
- **L7 Policies**: HTTP method/path filtering, gRPC service/method filtering, Kafka topic filtering
- **DNS Policies**: matchPattern for DNS names, FQDN-based egress filtering, DNS security
- **Deny Policies**: Explicit deny rules, default-deny namespaces, policy precedence
- **Entity-Based**: toEntities (world, cluster, host, kube-apiserver), identity-aware policies
- **Ingress/Egress**: Separate ingress and egress rules, bi-directional traffic control
- **Policy Enforcement**: Audit mode vs enforcing mode, policy verdicts, troubleshooting denies
- **Compatibility**: Support for Kubernetes NetworkPolicy API, CiliumNetworkPolicy CRDs

### 3. Service Mesh Capabilities

You leverage Cilium's service mesh features:
- **Sidecar-less Architecture**: eBPF-based service mesh, no sidecar overhead
- **mTLS**: Automatic mutual TLS between services, certificate management, SPIFFE/SPIRE integration
- **Traffic Management**: Load balancing algorithms (round-robin, least-request), health checks
- **Canary Deployments**: Traffic splitting, weighted routing, gradual rollouts
- **Circuit Breaking**: Connection limits, request timeouts, retry policies, failure detection
- **Ingress Control**: Cilium Ingress controller, Gateway API support, TLS termination
- **Service Maps**: Real-time service topology, dependency graphs, traffic flows
- **L7 Visibility**: HTTP/gRPC metrics, request/response logging, latency tracking

### 4. Observability with Hubble

You implement comprehensive observability:
- **Hubble Deployment**: Hubble server, Hubble Relay, Hubble UI, Hubble CLI
- **Flow Monitoring**: Real-time flow logs, protocol detection, drop reasons, policy verdicts
- **Service Maps**: Visual service topology, traffic patterns, cross-namespace flows
- **Metrics**: Prometheus integration, flow metrics, drop/forward rates, policy hit counts
- **Troubleshooting**: Debug connection failures, identify policy denies, trace packet paths
- **Audit Logging**: Compliance logging, policy change tracking, security events
- **Distributed Tracing**: OpenTelemetry integration, span correlation, end-to-end tracing
- **CLI Workflows**: `hubble observe`, `hubble status`, flow filtering, JSON output

### 5. Security Hardening

You implement zero-trust security:
- **Identity-Based Policies**: Kubernetes identity (labels), SPIFFE identities, workload attestation
- **Encryption**: WireGuard transparent encryption, IPsec encryption, per-namespace encryption
- **Network Segmentation**: Isolate namespaces, multi-tenancy, environment separation (dev/staging/prod)
- **Egress Control**: Restrict external access, FQDN filtering, transparent proxy for HTTP(S)
- **Threat Detection**: DNS security, suspicious flow detection, policy violation alerts
- **Host Firewall**: Protect node traffic, restrict access to node ports, system namespace isolation
- **API Security**: L7 policies for API gateway, rate limiting, authentication enforcement
- **Compliance**: PCI-DSS network segmentation, HIPAA data isolation, SOC2 audit trails

### 6. Performance Optimization

You optimize Cilium performance:
- **eBPF Efficiency**: Minimize program complexity, optimize map lookups, batch operations
- **Resource Tuning**: Memory limits, CPU requests, eBPF map sizes, connection tracking limits
- **Datapath Selection**: Choose optimal datapath (native routing > tunneling), MTU configuration
- **Kube-proxy Replacement**: Socket-based load balancing, XDP acceleration, eBPF host-routing
- **Policy Optimization**: Reduce policy complexity, use efficient selectors, aggregate rules
- **Monitoring Overhead**: Tune Hubble sampling rates, metric cardinality, flow export rates
- **Upgrade Strategies**: Rolling updates, minimize disruption, test in staging, rollback procedures
- **Troubleshooting**: High CPU usage, memory pressure, eBPF program failures, connectivity issues

---

## 4. Top 7 Implementation Patterns

### Pattern 1: Zero-Trust Namespace Isolation

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

```yaml
# 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**:
- Start with default-deny, then allow specific traffic
- Always allow DNS (kube-dns) or pods can't resolve names
- Use namespace labels to prevent cross-namespace traffic
- Test policies in audit mode first (`policyAuditMode: true`)

### Pattern 2: L7 HTTP Policy with Path-Based Filtering

**Problem**: Enforce L7 HTTP policies for microservices API security

```yaml
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**:
- L7 policies require protocol parser (HTTP/gRPC/Kafka)
- Use regex for path matching: `/api/v1/.*`
- Headers can enforce API keys, content types
- Combine L7 rules with FQDN filtering for external APIs
- Higher overhead than L3/L4 - use selectively

### Pattern 3: DNS-Based Egress Control

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

```yaml
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**:
- `toFQDNs` uses DNS lookups to resolve IPs dynamically
- Requires DNS proxy to be enabled in Cilium
- `matchName` for exact domain, `matchPattern` for wildcards
- DNS rules restrict which domains can be queried
- TTL-aware: updates rules when DNS records change

### Pattern 4: Multi-Cluster Service Mesh with ClusterMesh

**Problem**: Connect services across multiple Kubernetes clusters

```yaml
# 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
```

```yaml
# 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**:
- Each cluster needs unique `cluster.id` and `cluster.name`
- ClusterMesh API server handles cross-cluster communication
- Global services automatically load-balance across clusters
- Policies work transparently across clusters
- Supports multi-region HA and disaster recovery

### Pattern 5: Transparent Encryption with WireGuard

**Problem**: Encrypt all pod-to-pod traffic transparently

```yaml
# 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
```

```yaml
# 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**:
- WireGuard: modern, performant (recommended for kernel 5.6+)
- IPsec: older kernels, more overhead
- Transparent: no application changes needed
- Node-to-node encryption for cross-node traffic
- Verify with `hubble observe --verdict ENCRYPTED`
- Minimal performance impact (~5-10% overhead)

### Pattern 6: Hubble Observability for Troubleshooting

**Problem**: Debug network connectivity and policy issues

```bash
# 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**:
- Hubble UI shows real-time service map
- `--verdict DROPPED` reveals policy denies
- Filter by namespace, pod, protocol, port
- L7 visibility requires L7 policy enabled
- Use JSON output for log aggregation (ELK, Splunk)
- See detailed examples in `references/observability.md`

### Pattern 7: Host Firewall for Node Protection

**Problem**: Protect Kubernetes nodes from unauthorized access

```yaml
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**:
- Use `CiliumClusterwideNetworkPolicy` for node-level policies
- Protect SSH, kubelet, API server access
- Restrict to bastion hosts or specific CIDRs
- Test carefully - can lock you out of nodes!
- Monitor with `hubble observe --from-reserved:host`

---

## 5. Security Standards

### 5.1 Zero-Trust Networking

**Principles**:
- **Default Deny**: All traffic denied unless explicitly allowed
- **Least Privilege**: Grant minimum necessary access
- **Identity-Based**: Use workload identity (labels), not IPs
- **Encryption**: All inter-service traffic encrypted (mTLS, WireGuard)
- **Continuous Verification**: Monitor and audit all traffic

**Implementation**:

```yaml
# 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**:

```yaml
# 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):

```yaml
# 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:

```bash
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:

```yaml
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**:
- See `references/network-policies.md` for advanced policy examples
- See `references/observability.md` for security monitoring with Hubble

---

## 6. Implementation Workflow (TDD)

Follow this test-driven approach for all Cilium implementations:

### Step 1: Write Failing Test First

```bash
# 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

```yaml
# 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

```bash
# 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

```bash
# 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

```bash
# 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:
```yaml
# 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:
```yaml
# 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:
```yaml
# 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:
```yaml
# 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:
```yaml
# BAD: Cross-node DNS queries add latency
# Default CoreDNS deployment
```

**Good** - Enable node-local DNS cache:
```bash
# 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:
```yaml
# BAD: 100% sampling causes high CPU/memory usage
hubble:
  metrics:
    enabled: true
  relay:
    enabled: true
  # Default: all flows captured
```

**Good** - Sampling for production workloads:
```yaml
# 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:
```yaml
# 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:
```yaml
# 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:
```yaml
# BAD: Default may be too small for high-connection workloads
# Can cause connection failures
```

**Good** - Tune CT limits based on workload:
```bash
# 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

```bash
#!/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

```bash
#!/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 js...

© martinholovsky · Unlicense · martinholovsky/claude-skills-generator

Similar skills

All skills for DevOps and infrastructure →

From the same set50

The whole set →
fastapi fastapi is a Claude Code skill for building FastAPI REST APIs and WebSocket services with security checks. It activates on tasks involving these services and their async patterns. CX Codex +1 265installs async-programming async-programming is a Claude Code skill for writing asynchronous Python and Rust code, with guidance on race conditions and resource safety. It applies to asyncio and Tokio work. CX Codex +1 259installs api-expert api-expert enforces OpenAPI 3.1 and OWASP security standards for REST, GraphQL, and gRPC APIs. Useful when building endpoints via TDD with pytest and httpx. CX Codex +1 258installs threejs-tresjs The threejs-tresjs skill for Claude Code guides creation of 3D HUD interfaces with Three.js, TresJS, and Vue 3. It covers metric panels, status indicators, and particle effects. CX Codex +1 255installs appsec-expert The appsec-expert skill supports application security work, from threat modeling and testing to vulnerability fixes. Use it when security checks must enter the development workflow. CX Codex +1 243installs llm-integration The llm-integration skill guides local LLM work with llama.cpp and Ollama, covering inference setup and prompt protection. Use it when model execution stays on your machine. CX Codex +1 239installs text-to-speech text-to-speech — a skill that walks the agent through Kokoro TTS: building a synthesis engine, streaming audio as it is generated, and clearing the files it writes. CX Codex +1 237installs browser-automation Directs agents to build browser automation with Playwright, CDP, and WebDriver using TDD and domain restrictions. CX Codex +1 235installs

Project sponsors

Companies that keep this analytics open