注意, 这边的 10.87.2.50 必须换成你自己同网段下无使用的 IP e.g. 10.87.2.X 后面 nginx 为 service 的 name, 这边可以自行更换
接着确认一下
$kubectl get configmapNAMEDATAAGEvip-configmap123h
再来就是设置 keepalived-vip
apiVersion:extensions/v1beta1kind:DaemonSetmetadata:name:kube-keepalived-vipspec:template:metadata:labels:name:kube-keepalived-vipspec:hostNetwork:truecontainers: - image:gcr.io/google_containers/kube-keepalived-vip:0.9name:kube-keepalived-vipimagePullPolicy:AlwayssecurityContext:privileged:truevolumeMounts: - mountPath:/lib/modulesname:modulesreadOnly:true - mountPath:/devname:dev# use downward APIenv: - name:POD_NAMEvalueFrom:fieldRef:fieldPath:metadata.name - name:POD_NAMESPACEvalueFrom:fieldRef:fieldPath:metadata.namespace# to use unicastargs: - --services-configmap=default/vip-configmap# unicast uses the ip of the nodes instead of multicast# this is useful if running in cloud providers (like AWS)#- --use-unicast=truevolumes: - name:moduleshostPath:path:/lib/modules - name:devhostPath:path:/dev
$curl10.87.2.50<!DOCTYPEhtml><html><head><title>Welcome to nginx!</title><style>body{width:35em;margin:0auto;font-family:Tahoma,Verdana,Arial,sans-serif; }</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking.Furtherconfigurationisrequired.</p><p>For online documentation and support please refer to<a href="http://nginx.org/">nginx.org</a>.<br/>Commercialsupportisavailableat<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>
10.87.2.50:80(我们假设的 VIP, 实际上其实没有 node 是用这 IP) 即可帮我们导向这个 service