Skip to main content
  1. Posts/

Configure Calico with eBPF Mode

·3 mins·
calico kubernetes calico
Table of Contents

eBPF (extended Berkeley Packet Filter) merupakan virtual machine (VM) yang tertanam di dalam kernel Linux sehingga memungkinkan fungsionalitas BPF yang lebih kuat seperti kemampuan untuk mengeksekusi kode dari tingkat kernel yang lebih dalam, melakukan pemantauan, logging, pemrosesan paket, dan banyak hal lainnya tanpa mengganggu kernel itu sendiri.

Pastikan cluster Anda siap atau support untuk mode eBPF.

mount | grep "/sys/fs/bpf"
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)

Create ConfigMap kubernetes-service-endpoint
#

Buat configmap di namespace tigera-operator menggunakan host dan port kubernetes service pada node master atau control-plane.

kubectl apply -f - <<EOF
kind: ConfigMap
apiVersion: v1
metadata:
  name: kubernetes-services-endpoint
  namespace: tigera-operator
data:
  KUBERNETES_SERVICE_HOST: 192.168.100.11
  KUBERNETES_SERVICE_PORT: "6443"
EOF

Install Calico With Operator
#

Install tigera-operator.

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml

Selanjutnya unduh custom-resources.yaml.

wget https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml

Edit custom-resources.yaml dengan menambahkan linuxDataplane dan sesuaikan cidr dengan network pod.

spec:
  calicoNetwork:
    linuxDataplane: BPF
    ipPools:
    - blockSize: 26
      cidr: 10.10.0.0/16
      encapsulation: VXLANCrossSubnet
      natOutgoing: Enabled
      nodeSelector: all()

Deploy custom-resources.yaml.

kubectl create -f custom-resources.yaml

Remove taints pada node control-plane sehingga dapat menjadwalkan atau membuat pod di node tersebut.

kubectl taint nodes -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/control-plane-

Tunggu beberapa saat sampai semua pods running.

Configure calicoctl
#

Unduh calicoctl

wget https://github.com/projectcalico/calico/releases/download/v3.26.1/calicoctl-linux-amd64 \
 -O /usr/local/bin/calicoctl

Tambahkan environment shell berikut.

export CALICO_DATASTORE_TYPE=kubernetes
export CALICO_KUBECONFIG=~/.kube/config

Test calicoctl untuk memastikan sudah terhubung ke cluster.

calicoctl get workloadendpoints
calicoctl get nodes

Change to eBPF mode
#

Dalam mode eBPF, untuk menghindari adanya konflik dengan tigera-operator maka perlu menonaktifkan kube-proxy dengan perintah.

kubectl patch ds -n kube-system kube-proxy \
 -p '{"spec":{"template":{"spec":{"nodeSelector":{"non-calico": "true"}}}}}'

Jika Anda tetap ingin kube-proxy berjalan di cluster maka Anda dapat mengubah parameter konfigurasi Felix BPFKubeProxyIptablesCleanupEnabled menjadi false.

kubectl patch felixconfiguration.p default \
 --patch='{"spec": {"bpfKubeProxyIptablesCleanupEnabled": false}}'

Untuk mengaktifkan mode eBPF

kubectl patch installation.operator.tigera.io default --type merge -p '{"spec":{"calicoNetwork":{"linuxDataplane":"BPF", "hostPorts":null}}}'
calicoctl patch felixconfiguration default --patch='{"spec": {"bpfEnabled": true}}'

Untuk mengaktifkan mode DSR untuk mengurangi latensi dan overhead CPU.

calicoctl patch felixconfiguration default \
 --patch='{"spec": {"bpfExternalServiceMode": "DSR"}}'

Mengaktifkan jaringan overlay dengan VXLAN

calicoctl patch felixconfiguration default \
 --patch='{"spec": {"vxlanEnabled": true, "ipipEnabled": false}}'

Checking eBPF
#

Berikut beberapa cara untuk memeriksa apakah eBPF cluster berfungsi dengan benar.

View eth0 NIC counter

kubectl exec -n calico-system ds/calico-node -- calico-node -bpf counters dump --iface=eth0

View conntrack status

kubectl exec -n calico-system ds/calico-node -- calico-node -bpf conntrack dump

View routing table

kubectl exec -n calico-system ds/calico-node -- calico-node -bpf routes dump

View log

kubectl exec -n calico-system ds/calico-node -- grep -i  felix/int_dataplane.go /var/log/calico/felix/current | grep BPF

Disable eBPF mode
#

Untuk menonaktifkan eBPF dan mengembalikan semua konfigurasi ke default.

calicoctl patch felixconfiguration default --patch='{"spec": {"bpfEnabled": false}}'
calicoctl patch felixconfiguration default --patch='{"spec": {"bpfExternalServiceMode": "Tunnel"}}'
kubectl patch installation.operator.tigera.io default --type merge -p '{"spec":{"calicoNetwork":{"linuxDataplane":"Iptables"}}}'
kubectl patch ds -n kube-system kube-proxy --type merge -p '{"spec":{"template":{"spec":{"nodeSelector":{"non-calico": null}}}}}'
kubectl taint nodes -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/control-plane:NoSchedule

Related

Konfigurasi Mode VXLAN pada Calico Kubernetes
·2 mins
calico kubernetes calico
Convert Docker Compose to Kubernetes Resources
·1 min
kubernetes kubernetes
Backup dan Restore Etcd pada Kubernetes Cluster
·2 mins
kubernetes kubernetes
Deploy Kubernetes Dashboard
·1 min
kubernetes kubernetes
Deploy Pod ke Node Tertentu
·2 mins
kubernetes kubernetes
Kubectl Cheat Sheet
·14 mins
kubernetes kubernetes