#k8s-cni-test
-
It is best to have a clean k8s environment without any network plug-ins installed.
// Create a new file ending with .conf in the /etc/cni/net.d/ directory and enter the following configuration items
{
"cniVersion": "0.3.0",
"name": "testcni",
"type": "testcni",
"mode": "ipip",
"subnet": "10.244.0.0/16"
}
# Execute in the project root directory
make build_main
-
A main will be generated at this time
-
Go to https://github.com/projectcalico/bird clone project
-
Execution
# Compile calico's bird
# After compilation, there will be a bird binary in the dist directory
ARCH=<your computer architecture> ./build.sh
-
Create the /opt/testcni directory and copy the bird binary above to here
-
Copy the main binary generated in the third step to /opt/cni/bin/testcni
mv main /opt/cni/bin/testcni
-
It is best to have a clean k8s environment without any network plug-ins installed.
// Create a new file ending with .conf in the /etc/cni/net.d/ directory and enter the following configuration items
{
"cniVersion": "0.3.0",
"name": "testcni",
"type": "testcni",
"mode": "vxlan",
"subnet": "10.244.0.0"
}
# Execute in the project root directory
make build
-
A binary file named testcni will be generated. Three ebpf files will be generated at the same time. These three ebpf files will be automatically copied to the “/opt/testcni/” directory. If this directory does not exist, you can create it manually.
-
Copy the testcni generated in the previous step to the "/opt/cni/bin" directory
-
It is best to have a clean k8s environment without any network plug-ins installed.
//Create a new file ending with .conf in the /etc/cni/net.d/ directory of each node and enter the following configuration items
// Note that the range in "subnet" and "ipam" needs to be manually changed to your own environment. In addition, each node of the range should be configured to a different range.
{
"cniVersion": "0.3.0",
"name": "testcni",
"type": "testcni",
"mode": "ipvlan",
"subnet": "192.168.64.0/24",
"ipam": {
"rangeStart": "192.168.64.90",
"rangeEnd": "192.168.64.100"
}
}
2.
```bash
# Execute in the project root directory
make build_main
- At this time, a main binary will be generated, and the binary will be copied to /opt/cni/bin/testcni
mv main /opt/cni/bin/testcni
// Create a new file ending with .conf in the /etc/cni/net.d/ directory and enter the following configuration items
{
"cniVersion": "0.3.0",
"name": "testcni",
"type": "testcni",
"bridge": "testcni0",
"subnet": "10.244.0.0/16"
}
- Change the IP address used to initialize the etcd client under /etcd/client.go to the etcd address of your own cluster.
- go build main.go
- mv main /opt/cni/bin/testcni
- Repeat the above three steps on each host.
- kubectl apply -f test-busybox.yaml
- Check cluster pod status
- Testing can be done through main_test.go in the /test directory
- Before testing, create a command space using ip netns add test.net.1
- Then go test ./test/main_test.go -v
- Then perform the same steps on other nodes.
- ip netns exec test.net.1 ping the network card ip under ns on another node
- Switch to the test/cni-test branch
- Enter the ./cnitool directory
- go build cnitool.go
- ip netns add test.net.1 creates a net ns
- Create the same configuration as above in the /etc/cni/net.d/ directory
- ./cnitool add testcni /run/netns/test.net.1
- View kubelet logs through journalctl -xeu kubelet -f command
- Modify the log output address in the ./utils/write_log.go file. Key error messages will be automatically sent to this address.
- If the compiled main.go has been copied to /opt/cni/bin/testcni but kubelet still reports an error like "not found", try adding "export CNI_PATH=/ to the environment variable opt/cni/bin"
- If the kubelet log shows something like "the configuration file contains illegal characters", check whether any logs are output directly to the standard output using fmt in all codes. cni reads the configuration through the standard output, so if there is any illegal Configuration related information is output, it will definitely be gg