Skip to content

Cilium ​

What is Cilium? ​

Cilium is an open source, cloud native Kubernetes CNI, providing network connectivity between workloads in a Kubernetes cluster.

Cilium is implements networking, observability, and security solution with an eBPF-based dataplane. It provides a Layer 3 network with the ability to span multiple clusters in either a native routing or overlay mode. It is also L7-protocol aware and can enforce network policies on L3-L7 using an identity based security model that is decoupled from network addressing.

Cilium implements distributed load balancing for traffic between pods and to external services, and is able to fully replace kube-proxy, using efficient hash tables in eBPF allowing for almost unlimited scale. It also supports advanced functionality like integrated ingress and egress gateway, bandwidth management and service mesh, and provides deep network and security visibility, observability and monitoring.

The Linux kernel technology eBPF is at the foundation of Cilium. It supports dynamic insertion of eBPF bytecode into the Linux kernel at various integration points such as: network IO, application sockets, and tracepoints to implement security, networking and visibility logic. eBPF is highly efficient and flexible. To learn more about eBPF, visit eBPF.io.

Egress Gateways ​

A Cilium Egress Gateway provides a feature that can route all traffic originating from pods and destined to specific cluster-external CIDRs through particular Kubernetes worker nodes, called "gateway nodes".

When the egress gateway feature is enabled and egress gateway policies are in place, matching packets that leave the cluster are masqueraded with selected, predictable IPs associated with these gateway nodes. As an example, this feature can be used in combination with legacy firewalls to allow traffic to legacy infrastructure only from specific pods within a given namespace. The pods typically have ever-changing IP addresses, and even if masquerading was to be used as a way to mitigate this, the IP addresses of worker nodes can also change frequently over time.

BPF Masquerade pitfalls ​

To use the Cilium Egress Gateway feature, it requires that both BPF masquerading (bpf.masquerade: true) and the kube-proxy replacement (kubeProxyReplacement: true) are enabled. Enabling of BPF masquerading also requires to enable Host Legacy Routing (bpf.hostLegacyRouting: true), otherwise pods will not be able to reach the control-plane and apiserver of the cluster anymore.

💡 Note

The same is true if you want to install Istio into your cluster, it is also incompatible with native BPF Host-Routing and will require hostLegacyRouting

The replacement of kube-proxy is enabled by default when you create a new Kubernetes cluster and choose Cilium as its CNI, the options for BPF Masquerading, Host Legacy Routing and Egress Gateways however are not. You can set these either during cluster creation, or also afterwards by modifying the Cilium settings of your Kubernetes cluster.

💡 Note

  • Egress gateways are not compatible with the Cluster Mesh feature. The gateway selected by an egress gateway policy must be in the same cluster as the selected pods.
  • Egress gateways are not compatible with the CiliumEndpointSlice feature.

⚠️ Warning

Do not forget to also enable hostLegacyRouting at the same time when enabling BPF masquerading, otherwise the cluster will stop functioning!

How to enable ​

The following values will all need to be set to true to enable the egress gateway feature:

values.yaml settings ​

KS Cilium - enable Egress Gateway settings

This can be done for both, a new cluster during creation or also for an existing cluster afterwards.

How to enable in a new cluster ​

For a new cluster the Cilium configuration screen is hidden behind the "ADVANCED NETWORK CONFIGURATION". After expansion it will show an "Edit CNI Values" button at the bottom which allows editing the Cilium configuration for the new cluster.

KS Cilium - enable Egress Gateway in a new cluster

How to enable in an existing cluster ​

In an already existing Kubernetes cluster the Cilium configuration can be found on the Applications tab at the bottom of the cluster details screen. Make sure to also Show System Applications and then click the edit button on the Cilium system application.

KS Cilium - enable Egress Gateway in an existing cluster

Configuring an egress gateway ​

You can check if the Cilium egress gateway feature has been successfully enabled by running:

bash
$ kubectl api-resources | grep egress
ciliumegressgatewaypolicies  cilium.io/v2  CiliumEgressGatewayPolicy

If the CiliumEgressGatewayPolicy custom resource does not show up after enabling the egress gateway feature in an already existing cluster you might want to restart the cilium-operator.

bash
$ kubectl -n kube-system rollout restart deploy/cilium-operator

If the cluster was newly created this should not be necessary.

CiliumEgressGatewayPolicy ​

The next step is to create and apply a CiliumEgressGatewayPolicy which specifies a source pods (selectors:) and a target gateway node (egressGateway:) from which the traffic should leave the Kubernetes cluster:

yaml
---
apiVersion: cilium.io/v2
kind: CiliumEgressGatewayPolicy
metadata:
  name: egress-example
spec:
  selectors: # can be any combination of podSelector or nodeSelector
  - podSelector:
      matchLabels:
        app: my-db-frontend
  destinationCIDRs:
  - "0.0.0.0/0"
  # - "10.221.10.13/32" # or more specific is also possible
  egressGateway:
    nodeSelector:
      matchLabels:
        # can be any label(s) of a worker node
        my-custom-label: egress-to-db-from-here
        topology.kubernetes.io/zone: zhh

Once this policy has been applied all traffic emitted by any pod with the label app: my-db-frontend will now be routed through and only exit from the node(s) with the matching labels as specified in the nodeSelector.

💡 Info

Please consult the official Cilium Egress Gateway documentation for more details and information on configuration options. There are various more options available to specify sources and target nodes for these egress policies.

It is recommended to create dedicated MachineDeployments to be used as target gateway nodes. This allows selection of specific, potentially much smaller and/or SNATed subnets per MachineDeployment, and it is also possible to add many additional labels which will then be inherited down to each individual node.

Cilium Ingress ​

Cilium provides a built-in Ingress Controller that can handle HTTP/HTTPS traffic routing without requiring an additional ingress controller deployment. It leverages the same eBPF dataplane for efficient L7 traffic processing.

💡 Note

Cilium Ingress requires a working LoadBalancer setup. Make sure KubeLB is enabled on your cluster before using Cilium Ingress.

How to enable ​

Cilium Ingress is enabled by setting the ingressController.enabled value to true in the Cilium configuration.

values.yaml settings ​

yaml
ingressController:
  enabled: true
  default: false
  loadbalancerMode: shared
  service:
    loadBalancerClass: kubelb
SettingDescription
ingressController.enabledEnables the Cilium Ingress Controller
ingressController.defaultIf true, Cilium becomes the default ingress controller for all Ingress resources without an explicit ingressClassName
ingressController.loadbalancerModeshared uses a single LoadBalancer IP for all Ingress resources; dedicated creates one LoadBalancer per Ingress
ingressController.service.loadBalancerClassMust be set to kubelb to use the KS load balancer infrastructure

⚠️ Important

Set ingressController.service.loadBalancerClass to kubelb, otherwise the Ingress LoadBalancer service will remain in Pending state.

How to enable in a new cluster ​

During cluster creation, expand "ADVANCED NETWORK CONFIGURATION" and click "Edit CNI Values" to access the Cilium configuration. Add the ingressController settings shown above.

How to enable in an existing cluster ​

Navigate to the cluster's Applications tab, enable Show System Applications, and click the edit button on the Cilium system application. Add the ingressController settings to the existing values.

After applying the configuration, verify that the Cilium Ingress Controller is running:

bash
kubectl get svc -n kube-system cilium-ingress

You should see a service of type LoadBalancer with an assigned EXTERNAL-IP.

Using Cilium Ingress ​

Create an Ingress resource with ingressClassName: cilium:

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: cilium
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app
            port:
              number: 80

TLS termination ​

To terminate TLS at the ingress, create a Kubernetes Secret containing your certificate and reference it in the Ingress:

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-tls-ingress
spec:
  ingressClassName: cilium
  tls:
  - hosts:
    - app.example.com
    secretName: app-tls-secret
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app
            port:
              number: 80

Limitations ​

  • Cilium Ingress only supports HTTP and HTTPS (L7). For raw TCP/UDP use a LoadBalancer service directly.
  • When using shared mode, all Ingress resources must be distinguishable by host or path.
  • The Cilium Ingress Controller is managed as part of the Cilium CNI system application. Support for issues related to Cilium Ingress follows the same model as the CNI itself.

💡 Upstream documentation

For advanced configuration options such as header manipulation, request timeouts, and traffic splitting, consult the official Cilium Ingress documentation.