kubectl get nodes -o json | jq '.items[] | .spec'
kubectl --namespace=kube-system create configmap kube-proxy --from-file=kubeconfig.conf=/root/.kube/config
kubectl create -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter-all-features-dsr.yaml
yum install ipvsadm traceroute -y
kubectl run nginx --image=nginx --replicas=1
$ kubectl expose nginx --target-port=80 --port=80
$ kubectl get svc nginx -o template --template='{{.spec.clusterIP}}'
10.254.116.179
ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.254.0.1:443 rr persistent 10800
-> 172.26.6.1:6443 Masq 1 0 0
TCP 10.254.116.179:80 rr 10800
-> 10.254.11.2:80 Masq 1 0 0
发现本机SVCIP代理后端真实podip,使用rr算法,通过ip addr s可以看到每添加一个服务node节点上面的kube-dummy-if网卡就会增加一个虚IP
kubectl delete svc nginx
kubectl expose deploy nginx --target-port=80 --port=80 --session-affinity=ClientIP
ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.254.0.1:443 rr persistent 10800
-> 172.26.6.1:6443 Masq 1 0 0
TCP 10.254.191.234:80 rr persistent 10800
-> 10.254.11.2:80 Masq 1 0 0
我们可以看到 多个persistent,既lvs里面的持久链接
kubectl delete svc nginx
kubectl expose deploy nginx --target-port=80 --port=80 --type=NodePort
ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.26.6.3:31117 rr
-> 10.254.11.2:80 Masq 1 0 0
TCP 10.254.0.1:443 rr persistent 10800
-> 172.26.6.1:6443 Masq 1 0 0
TCP 10.254.102.188:80 rr
-> 10.254.11.2:80 Masq 1 0 0
可以看到不仅有虚拟IP条目,还多了对应主机的lvs条目
kubectl annotate service nginx "kube-router.io/service.scheduler=dh"
kubectl annotate ns prod "net.beta.kubernetes.io/network-policy={\"ingress\":{\"isolation\":\"DefaultDeny\"}}" 测试可以看到其他命名空间ping不通该命名空间
# kubectl --namespace=kube-system exec -it kube-router-pk7fs /bin/bash
# gobgp neighbor -u 172.26.6.3 #从哪些IP获得更新
Peer AS Up/Down State |#Received Accepted
172.26.6.2 64512 01:03:03 Establ | 1 1
# gobgp global rib -u 172.26.6.3 #global rib相当于路由表
Network Next Hop AS_PATH Age Attrs
*> 10.254.0.0/24 172.26.6.2 01:03:24 [{Origin: i} {LocalPref: 100}]
*> 10.254.2.0/24 172.26.6.3 00:00:32 [{Origin: i}]