Skip to content

Instantly share code, notes, and snippets.

@astoycos
Last active July 10, 2023 12:20
Show Gist options
  • Save astoycos/c4019178c7cd69b0b5a8d069a26281ee to your computer and use it in GitHub Desktop.
Save astoycos/c4019178c7cd69b0b5a8d069a26281ee to your computer and use it in GitHub Desktop.
Bpfd-Heart-K8s-Demo
  1. Create Kind Cluster
kind create cluster --name=test-bpfd
  1. Deploy Cert manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
  1. Deploy bpfd Crds
kubectl apply -f  https://github.com/bpfd-dev/bpfd/releases/download/v0.2.1/bpfd-crds-install-v0.2.1.yaml
  1. Deploy bpfd-operator
kubectl apply -f https://github.com/bpfd-dev/bpfd/releases/download/v0.2.1/bpfd-operator-install-v0.2.1.yaml
  1. Configure Xdp Pass program to drop on proceed-on, Specifically add the following to the xdpProgram's Spec
 proceedon:
 - drop
  1. Deploy Xdp Pass program
kubectl apply -f - <<EOF
apiVersion: bpfd.io/v1alpha1
kind: XdpProgram
metadata:
  labels:
    app.kubernetes.io/name: xdpprogram
  name: xdp-pass-all-nodes
spec:
  sectionname: pass
  # Select all nodes
  nodeselector: {}
  interfaceselector:
    primarynodeinterface: true
  priority: 0
  proceedon:
    - drop
  bytecode:
    image:
      url: quay.io/bpfd-bytecode/xdp_pass:latest
EOF
  1. Deploy the xdp counter program and userspace application
kubectl apply -f https://github.com/bpfd-dev/bpfd/releases/download/v0.2.1/go-xdp-counter-install-v0.2.1.yaml
  1. Ensure Programs are deployed
kubectl get xdpprogram -o wide
NAME                     SECTIONNAME   NODESELECTOR   PRIORITY   INTERFACESELECTOR               PROCEEDON
go-xdp-counter-example   stats         {}             55         {"primarynodeinterface":true}   ["pass","dispatcher_return"]
xdp-pass-all-nodes       pass          {}             0          {"primarynodeinterface":true}   ["drop"]
  1. Verify no packets are being counted by the counter program
kubectl logs go-xdp-counter-ds-czlvx -n go-xdp-counter
2023/05/10 03:41:50 0 packets received
2023/05/10 03:41:50 0 bytes received

2023/05/10 03:41:53 0 packets received
2023/05/10 03:41:53 0 bytes received
...
  1. Edit the Xdp Pass program to have a higher priority then the counter program, Specifically edit the priority field of the Spec to 60
priority: 60
  1. Verify that packets are now being counted by the counter program
kubectl logs go-xdp-counter-ds-czlvx -n go-xdp-counter
2023/05/10 03:42:23 0 packets received
2023/05/10 03:42:23 0 bytes received

2023/05/10 03:42:26 6 packets received
2023/05/10 03:42:26 1386 bytes received

2023/05/10 03:42:29 70 packets received
2023/05/10 03:42:29 30654 bytes received

2023/05/10 03:42:32 203 packets received
2023/05/10 03:42:32 40111 bytes received
...
  1. Clean everything up
kubectl delete xdpprogram xdp-pass-all-nodes
kubectl delete -f https://github.com/bpfd-dev/bpfd/releases/download/v0.2.0/go-xdp-counter-install-v0.2.0.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment