Use Cilium for NetworkPolicy

This page shows how to use Cilium for NetworkPolicy.

For background on Cilium, read the Introduction to Cilium.

Before you begin

You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:

To check the version, enter kubectl version.

Deploying Cilium on Minikube for Basic Testing

To get familiar with Cilium easily you can follow the Cilium Kubernetes Getting Started Guide to perform a basic DaemonSet installation of Cilium in minikube.

To start minikube, minimal version required is >= v1.3.1, run the with the following arguments:

  1. minikube version
  1. minikube version: v1.3.1
  1. minikube start --network-plugin=cni --memory=4096

Mount the BPF filesystem:

  1. minikube ssh -- sudo mount bpffs -t bpf /sys/fs/bpf

For minikube you can deploy this simple ‘’all-in-one’’ YAML file that includes DaemonSet configurations for Cilium as well as appropriate RBAC settings:

  1. kubectl create -f https://raw.githubusercontent.com/cilium/cilium/v1.8/install/kubernetes/quick-install.yaml
  1. configmap/cilium-config created
  2. serviceaccount/cilium created
  3. serviceaccount/cilium-operator created
  4. clusterrole.rbac.authorization.k8s.io/cilium created
  5. clusterrole.rbac.authorization.k8s.io/cilium-operator created
  6. clusterrolebinding.rbac.authorization.k8s.io/cilium created
  7. clusterrolebinding.rbac.authorization.k8s.io/cilium-operator created
  8. daemonset.apps/cilium create
  9. deployment.apps/cilium-operator created

The remainder of the Getting Started Guide explains how to enforce both L3/L4 (i.e., IP address + port) security policies, as well as L7 (e.g., HTTP) security policies using an example application.

Deploying Cilium for Production Use

For detailed instructions around deploying Cilium for production, see: Cilium Kubernetes Installation Guide This documentation includes detailed requirements, instructions and example production DaemonSet files.

Understanding Cilium components

Deploying a cluster with Cilium adds Pods to the kube-system namespace. To see this list of Pods run:

  1. kubectl get pods --namespace=kube-system

You’ll see a list of Pods similar to this:

  1. NAME READY STATUS RESTARTS AGE
  2. cilium-6rxbd 1/1 Running 0 1m
  3. ...

A cilium Pod runs on each node in your cluster and enforces network policy on the traffic to/from Pods on that node using Linux BPF.

What’s next

Once your cluster is running, you can follow the Declare Network Policy to try out Kubernetes NetworkPolicy with Cilium. Have fun, and if you have questions, contact us using the Cilium Slack Channel.