Skip to content

Cilium network policy and Hubble observability

Author CiliumNetworkPolicy with L3-L7 selectors, deploy Hubble Relay + UI, and use Hubble flows to validate policy decisions before enforcement.

You have Cilium installed and now have to author network policies that go beyond Kubernetes’ stock NetworkPolicy — HTTP path filtering, Kafka topic restriction, identity-based allow lists. Cilium’s CRDs (CiliumNetworkPolicy, CiliumClusterwideNetworkPolicy) cover this, and Hubble is the observability layer that lets you write policies with traffic in view rather than guessing. This article is the operating procedure we follow on real clusters: enable Hubble first, watch real flows, then enforce.

How to verify

Hubble Relay and UI should be running:

kubectl -n kube-system get pods -l k8s-app=hubble-relay
kubectl -n kube-system get pods -l k8s-app=hubble-ui
hubble status

You should be able to observe live flows from the CLI:

hubble observe --namespace app --since 1m
hubble observe --pod app/checkout --follow

CiliumNetworkPolicies in effect for a namespace should be listable:

kubectl -n app get cnp,ccnp

Dropped flows (policy denies) are a specific Hubble verdict:

hubble observe --namespace app --verdict DROPPED --since 10m

What’s happening

Cilium identities (small integers) are derived from the labels on pods. Each pod gets a numeric identity that maps to a label set, and every policy decision compares identities, not IPs. This is critical because IPs change but identities are stable across pod restarts, and policy log lines reference the identity so you can correlate to a workload regardless of how often it reschedules.

CiliumNetworkPolicy is a CRD that extends Kubernetes NetworkPolicy with L7 capabilities. At L3-L4 it can match on pod label selectors (identity), namespace selectors, CIDRs, and DNS-based FQDN selectors that the agent resolves and tracks. At L7 it can match on HTTP method/path/header, Kafka topic/group, gRPC method, and DNS query patterns. The L7 enforcement runs in the per-node Envoy that the agent provisions on demand; if no L7 policy exists for a namespace, no Envoy is provisioned.

Hubble flow records expose what the eBPF programs decide in real time. Each flow has a verdict (FORWARDED, DROPPED, AUDIT), source and destination identity, L4 details, and (when available) L7 details. This is what lets you write policy without breaking production — you query Hubble for actual traffic, propose a policy, simulate, then enforce.

The procedure

  1. Enable Hubble in the Cilium ConfigMap or via Helm values.

    helm upgrade cilium cilium/cilium \
      --namespace kube-system \
      --reuse-values \
      --set hubble.enabled=true \
      --set hubble.relay.enabled=true \
      --set hubble.ui.enabled=true \
      --set hubble.metrics.enabled="{dns,drop,tcp,flow,icmp,http}"

    Then restart the Cilium agents:

    kubectl -n kube-system rollout restart ds/cilium
  2. Query existing traffic before writing policy. Use hubble observe to see what actually flows in a namespace, in both directions:

    hubble observe --namespace app --since 1h --output json > flows.json
    jq '.flow.source.namespace + " -> " + .flow.destination.namespace' flows.json | sort -u

    Identify all source-destination pairs. Anything you didn’t expect is the conversation to have before you enforce.

  3. Start with an audit-mode policy. A CiliumNetworkPolicy with enableDefaultDeny set but no rules (or rules that don’t match desired traffic) would block everything. Use the audit-mode annotation to log without enforcing:

    apiVersion: cilium.io/v2
    kind: CiliumNetworkPolicy
    metadata:
      name: checkout-policy
      namespace: app
      annotations:
        io.cilium.network.policy/enforcement-mode: "audit"
    spec:
      endpointSelector:
        matchLabels:
          app: checkout
      ingress:
        - fromEndpoints:
            - matchLabels:
                app: gateway
          toPorts:
            - ports:
                - port: "8080"
                  protocol: TCP
              rules:
                http:
                  - method: "GET"
                    path: "/api/.*"
                  - method: "POST"
                    path: "/api/orders"
  4. Watch for AUDIT verdicts. With audit-mode set, Hubble emits an AUDIT verdict for flows that would have been dropped:

    hubble observe --namespace app --verdict AUDIT --since 24h --output json

    Each AUDIT entry is a request you need to either include in policy or block consciously. Run this for one or two business days.

  5. Promote to enforcement. Once AUDIT is clean, remove the annotation:

    kubectl annotate cnp -n app checkout-policy io.cilium.network.policy/enforcement-mode-

    Now AUDIT becomes DROPPED, and the policy is effectively enforced. Monitor hubble observe --verdict DROPPED for at least the next hour — anything unexpected is a missed caller.

  6. Layer DNS FQDN egress. For external dependencies, write FQDN-based egress so policy survives DNS changes:

    egress:
      - toFQDNs:
          - matchPattern: "*.amazonaws.com"
          - matchName: "api.stripe.com"
        toPorts:
          - ports: [{ port: "443", protocol: TCP }]

    Cilium learns IPs as the agent resolves them and updates eBPF maps; an IP change at the FQDN side is tracked transparently.

Operational notes

  • Hubble flow storage is in-memory and per-node. Default ring buffer is 4095 events. For long-window analysis, configure export to a remote sink (Loki, OpenTelemetry, S3) — see hubble.export Helm values.
  • L7 policy requires Envoy on the node. The first L7 policy on a node triggers Envoy provisioning, which takes a few seconds. Plan for the first request matching a new L7 policy to be slow (or rolled with a deliberate dry-run window).
  • Default deny is a switch, not a default. Without enableDefaultDeny: ingress: true or egress: true, an empty CiliumNetworkPolicy does nothing. Set it explicitly per namespace once you understand the traffic.
  • HostNetwork pods are not in eBPF identity space. Anything with hostNetwork: true (often Prometheus, log shippers) is not subject to L3-L7 policy. Document the exception and consider a HostFirewall policy as a coarse substitute.
  • CCNP precedence is by ordering of name. CiliumClusterwideNetworkPolicy resources are evaluated in alphabetical order; tight DENY policies should sort early. This is non-obvious — set a naming convention now.

Stack Harbor authors and operates the Cilium policy catalogue for clients — Hubble-driven discovery, audit-mode rollout, FQDN egress lists, and the runbook that handles policy regressions without a production page. See how we run that on production fleets via our managed Kubernetes operations practice.