以下是在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
等命令测试网络连通性。