以下是在Ubuntu上配置Kubernetes网络的指南:
/etc/hosts文件中添加节点间的IP和主机名映射。systemctl stop ufw和systemctl disable ufw关闭防火墙,在/etc/fstab中注释掉Swap相关行以关闭Swap分区。/etc/sysctl.d/k8s.conf文件,添加net.bridge.bridge-nf-call-ip6tables = 1、net.bridge.bridge-nf-call-iptables = 1和net.ipv4.ip_forward = 1,然后执行sudo modprobe br_netfilter和sudo sysctl --system使其生效。kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml进行安装。network-policy.yaml,定义podSelector、policyTypes、ingress和egress等规则。kubectl apply -f network-policy.yaml将策略应用到集群。使用kubectl get nodes查看节点状态,使用kubectl run -it --rm test-pod --image=busybox创建测试Pod,并通过ping等命令测试网络连通性。