{"id":144555,"date":"2019-05-17T08:19:33","date_gmt":"2019-05-17T00:19:33","guid":{"rendered":"https:\/\/gulass.cn\/?p=144555"},"modified":"2019-05-13T09:34:19","modified_gmt":"2019-05-13T01:34:19","slug":"kubernetes-ha-sealos","status":"publish","type":"post","link":"https:\/\/gulass.cn\/kubernetes-ha-sealos.html","title":{"rendered":"\u7ec6\u8ff0kubernetes HA\u5b89\u88c5\u65b9\u5f0f- sealos\u8be6\u89e3"},"content":{"rendered":"
\u672c\u6587\u6559\u4f60\u5982\u4f55\u7528\u4e00\u6761\u547d\u4ee4\u6784\u5efak8s\u9ad8\u53ef\u7528\u96c6\u7fa4\u4e14\u4e0d\u4f9d\u8d56haproxy\u548ckeepalived\uff0c\u4e5f\u65e0\u9700ansible\u3002\u901a\u8fc7\u5185\u6838ipvs\u5bf9apiserver\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\uff0c\u5e76\u4e14\u5e26apiserver\u5065\u5eb7\u68c0\u6d4b\u3002<\/p>\n
\u88c5\u597ddocker\u5e76\u542f\u52a8docker,\u628a\u79bb\u7ebf\u5b89\u88c5\u5305 \u4e0b\u8f7d\u597d\u62f7\u8d1d\u5230\u6240\u6709\u8282\u70b9\u7684\/root\u76ee\u5f55\u4e0b, \u4e0d\u9700\u8981\u89e3\u538b\uff0c\u5982\u679c\u6709\u6587\u4ef6\u670d\u52a1\u5668\u66f4\u597d\uff0csealos\u652f\u6301\u4ece\u4e00\u4e2a\u670d\u52a1\u5668\u4e0awget\u5230\u6240\u6709\u8282\u70b9\u4e0a<\/p>\n
sealos\u5df2\u7ecf\u653e\u5728\u79bb\u7ebf\u5305\u4e2d\uff0c\u89e3\u538b\u540e\u5728kube\/bin\u76ee\u5f55\u4e0b(\u53ef\u4ee5\u89e3\u538b\u4e00\u4e2a\uff0c\u83b7\u53d6sealos bin\u6587\u4ef6)<\/p>\n
\r\nsealos init \\\r\n --master 192.168.0.2 \\\r\n --master 192.168.0.3 \\\r\n --master 192.168.0.4 \\ # master\u5730\u5740\u5217\u8868\r\n --node 192.168.0.5 \\ # node\u5730\u5740\u5217\u8868\r\n --user root \\ # \u670d\u52a1\u7528\u6237\u540d\r\n --passwd your-server-password \\ # \u670d\u52a1\u5668\u5bc6\u7801\uff0c\u7528\u4e8e\u8fdc\u7a0b\u6267\u884c\u547d\u4ee4\r\n --pkg kube1.14.1.tar.gz \\ # \u79bb\u7ebf\u5b89\u88c5\u5305\u540d\u79f0\r\n --version v1.14.1 # kubernetes \u79bb\u7ebf\u5b89\u88c5\u5305\u7248\u672c\uff0c\u8fd9\u6e32\u67d3kubeadm\u914d\u7f6e\u65f6\u9700\u8981\u4f7f\u7528\r\n<\/pre>\n\u7136\u540e\uff0c\u5c31\u6ca1\u6709\u7136\u540e\u4e86<\/p>\n
\u5176\u5b83\u53c2\u6570<\/strong><\/span><\/div>\n\r\n --kubeadm-config string kubeadm-config.yaml local # \u81ea\u5b9a\u4e49kubeadm\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u6709\u8fd9\u4e2asealos\u5c31\u4e0d\u53bb\u6e32\u67d3kubeadm\u914d\u7f6e\r\n --pkg-url string http:\/\/store.lameleg.com\/kube1.14.1.tar.gz download offline pakage url # \u652f\u6301\u4ece\u8fdc\u7a0b\u62c9\u53d6\u79bb\u7ebf\u5305\uff0c\u7701\u7684\u6bcf\u4e2a\u673a\u5668\u62f7\u8d1d\uff0c\u524d\u63d0\u4f60\u5f97\u6709\u4e2ahttp\u670d\u52a1\u5668\u653e\u79bb\u7ebf\u5305\r\n --vip string virtual ip (default \"10.103.97.2\") # \u4ee3\u7406master\u7684\u865a\u62dfIP\uff0c\u53ea\u8981\u4e0e\u4f60\u5730\u5740\u4e0d\u51b2\u7a81\u8bf7\u4e0d\u8981\u6539\r\n<\/pre>\n\u6e05\u7406<\/strong><\/span><\/div>\n\r\nsealos clean \\\r\n --master 192.168.0.2 \\\r\n --master 192.168.0.3 \\\r\n --master 192.168.0.4 \\ # master\u5730\u5740\u5217\u8868\r\n --node 192.168.0.5 \\ # node\u5730\u5740\u5217\u8868\r\n --user root \\ # \u670d\u52a1\u7528\u6237\u540d\r\n --passwd your-server-password\r\n<\/pre>\n\u589e\u52a0\u8282\u70b9<\/strong><\/span><\/div>\n\u65b0\u589e\u8282\u70b9\u53ef\u76f4\u63a5\u4f7f\u7528kubeadm\uff0c \u5230\u65b0\u8282\u70b9\u4e0a\u89e3\u538b<\/p>\n
\r\ncd kube\/shell && init.sh\r\necho \"10.103.97.2 apiserver.cluster.local\" >> \/etc\/hosts # using vip\r\nkubeadm join 10.103.97.2:6443 --token 9vr73a.a8uxyaju799qwdjv \\\r\n --master 10.103.97.100:6443 \\\r\n --master 10.103.97.101:6443 \\\r\n --master 10.103.97.102:6443 \\\r\n --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866\r\n<\/pre>\n\u5b89\u88c5dashboard prometheus<\/strong><\/span><\/div>\n\u79bb\u7ebf\u5305\u91cc\u5305\u542b\u4e86yaml\u914d\u7f6e\u548c\u955c\u50cf\uff0c\u7528\u6237\u6309\u9700\u5b89\u88c5\u3002<\/p>\n
\r\ncd \/root\/kube\/conf\r\nkubectl taint nodes --all node-role.kubernetes.io\/master- # \u53bb\u6c61\u70b9\uff0c\u6839\u636e\u9700\u6c42\u770b\u60c5\u51b5\uff0c\u53bb\u4e86\u540emaster\u5141\u8bb8\u8c03\u5ea6\r\nkubectl apply -f heapster\/ # \u5b89\u88c5heapster, \u4e0d\u5b89\u88c5dashboard\u4e0a\u6ca1\u76d1\u63a7\u6570\u636e\r\nkubectl apply -f heapster\/rbac \r\nkubectl apply -f dashboard # \u88c5dashboard\r\nkubectl apply -f prometheus # \u88c5\u76d1\u63a7\r\n<\/pre>\n\u662f\u4e0d\u662f\u5f88\u795e\u5947\uff0c\u5230\u5e95\u662f\u5982\u4f55\u505a\u5230\u8fd9\u70b9\u7684\uff1f\u90a3\u5c31\u9700\u8981\u53bb\u770b\u4e0b\u9762\u4e24\u4e2a\u4e1c\u897f<\/p>\n
\u5173\u4e8e\u8d85\u7ea7kubeadm<\/strong><\/span><\/div>\n\u6211\u4eec\u5b9a\u5236\u4e86kubeadm\uff0c\u505a\u4e86\u4e24\u4e2a\u4e8b\u60c5\uff1a<\/p>\n
\u5728\u6bcf\u4e2anode\u8282\u70b9\u4e0a\u589e\u52a0\u4e86\u4e00\u6761ipvs\u89c4\u5219\uff0c\u5176\u540e\u7aef\u4ee3\u7406\u4e86\u4e09\u4e2amaster<\/p>\n
\u5728node\u4e0a\u8d77\u4e86\u4e00\u4e2alvscare\u7684static pod\u53bb\u5b88\u62a4\u8fd9\u4e2a ipvs, \u4e00\u65e6apiserver\u4e0d\u53ef\u8bbf\u95ee\u4e86\uff0c\u4f1a\u81ea\u52a8\u6e05\u7406\u6389\u6240\u6709node\u4e0a\u5bf9\u5e94\u7684ipvs\u89c4\u5219\uff0c master\u6062\u590d\u6b63\u5e38\u65f6\u6dfb\u52a0\u56de\u6765\u3002<\/p>\n
\u901a\u8fc7\u8fd9\u6837\u7684\u65b9\u5f0f\u5b9e\u73b0\u6bcf\u4e2anode\u4e0a\u901a\u8fc7\u672c\u5730\u5185\u6838\u8d1f\u8f7d\u5747\u8861\u8bbf\u95eemasters\uff1a<\/p>\n
\r\n +----------+ +---------------+ virturl server: 127.0.0.1:6443\r\n | mater0 |< ----------------------| ipvs nodes | real servers:\r\n +----------+ |+---------------+ 10.103.97.200:6443\r\n | 10.103.97.201:6443\r\n +----------+ | 10.103.97.202:6443\r\n | mater1 |<---------------------+\r\n +----------+ |\r\n |\r\n +----------+ |\r\n | mater2 |<---------------------+\r\n +----------+\r\n<\/pre>\n\u5176\u5b9esealos\u5c31\u662f\u5e2e\u4f60\u6267\u884c\u4e86\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n
\r\nsuper-kubeadm\r\n<\/pre>\n\u5728\u4f60\u7684node\u4e0a\u589e\u52a0\u4e86\u4e09\u4e2a\u4e1c\u897f\uff1a<\/p>\n
\r\ncat \/etc\/kubernetes\/manifests # \u8fd9\u4e0b\u9762\u589e\u52a0\u4e86lvscare\u7684static pod\r\nipvsadm -Ln # \u53ef\u4ee5\u770b\u5230\u521b\u5efa\u7684ipvs\u89c4\u5219\r\ncat \/etc\/hosts # \u589e\u52a0\u4e86\u865a\u62dfIP\u7684\u5730\u5740\u89e3\u6790\r\n<\/pre>\n\u5173\u4e8elvscare<\/strong><\/span><\/div>\n\u8fd9\u662f\u4e00\u4e2a\u8d85\u7ea7\u7b80\u5355\u8f7b\u91cf\u7ea7\u7684lvs\u521b\u5efa\u4e0e\u5b88\u62a4\u8fdb\u7a0b\uff0c\u652f\u6301\u5065\u5eb7\u68c0\u67e5\uff0c\u5e95\u5c42\u4e0ekube-proxy\u4f7f\u7528\u7684\u662f\u76f8\u540c\u7684\u5e93\uff0c\u652f\u6301HTTP\u7684\u5065\u5eb7\u68c0\u6d4b\u3002<\/p>\n
\u6e05\u7406\u673a\u5668\u4e0a\u7684IPVS\u89c4\u5219<\/strong><\/span><\/div>\n\r\nipvsadm -C\r\n<\/pre>\n\u542f\u52a8\u51e0\u4e2anginx\u4f5c\u4e3aipvs\u4ee3\u7406\u540e\u7aef\u7684realserver<\/p>\n
\r\ndocker run -p 8081:80 --name nginx1 -d nginx\r\ndocker run -p 8082:80 --name nginx2 -d nginx\r\ndocker run -p 8083:80 --name nginx3 -d nginx\r\n<\/pre>\n\u542f\u52a8lvscare\u5b88\u62a4\u5b83\u4eec<\/strong><\/span><\/div>\n\r\nlvscare care --vs 10.103.97.12:6443 --rs 127.0.0.1:8081 --rs 127.0.0.1:8082 --rs 127.0.0.1:8083 \\\r\n--health-path \/ --health-schem http\r\n<\/pre>\n\u53ef\u4ee5\u770b\u5230\u89c4\u5219\u5df2\u7ecf\u88ab\u521b\u5efa<\/p>\n
\r\nipvsadm -Ln\r\n\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# ipvsadm -Ln\r\nIP Virtual Server version 1.2.1 (size=4096)\r\nProt LocalAddress:Port Scheduler Flags\r\n -> RemoteAddress:Port Forward Weight ActiveConn InActConn\r\nTCP 10.103.97.12:6443 rr\r\n -> 127.0.0.1:8081 Masq 1 0 0 \r\n -> 127.0.0.1:8082 Masq 1 0 0 \r\n -> 127.0.0.1:8083 Masq 1 0 0 \r\ncurl vip:\r\n\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# curl 10.103.97.12:6443 \r\n\r\n<\/pre>\n\u5220\u9664\u4e00\u4e2anginx,\u89c4\u5219\u5c31\u5c11\u4e86\u4e00\u6761<\/p>\n
\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# docker stop nginx1\r\nnginx1\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# ipvsadm -Ln\r\nIP Virtual Server version 1.2.1 (size=4096)\r\nProt LocalAddress:Port Scheduler Flags\r\n -> RemoteAddress:Port Forward Weight ActiveConn InActConn\r\nTCP 10.103.97.12:6443 rr\r\n -> 127.0.0.1:8082 Masq 1 0 0 \r\n -> 127.0.0.1:8083 Masq 1 0 1 \r\n<\/pre>\n\u518d\u5220\u9664\u4e00\u4e2a:<\/p>\n
\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# docker stop nginx2\r\nnginx2\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# ipvsadm -Ln\r\nIP Virtual Server version 1.2.1 (size=4096)\r\nProt LocalAddress:Port Scheduler Flags\r\n -> RemoteAddress:Port Forward Weight ActiveConn InActConn\r\nTCP 10.103.97.12:6443 rr\r\n -> 127.0.0.1:8083 Masq 1 0 0 \r\n<\/pre>\n\u6b64\u65f6VIP\u4efb\u7136\u53ef\u4ee5\u8bbf\u95ee:<\/p>\n
\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# curl 10.103.97.12:6443 \r\n<\/pre>\n\u5168\u90e8\u5220\u9664, \u89c4\u5219\u5c31\u81ea\u52a8\u88ab\u6e05\u9664\u5149\u4e86, curl\u4e5fcurl\u4e0d\u901a\u4e86\uff0c\u56e0\u4e3a\u6ca1realserver\u53ef\u7528\u4e86<\/p>\n
\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# docker stop nginx3\r\nnginx3\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# ipvsadm -Ln\r\nIP Virtual Server version 1.2.1 (size=4096)\r\nProt LocalAddress:Port Scheduler Flags\r\n -> RemoteAddress:Port Forward Weight ActiveConn InActConn\r\nTCP 10.103.97.12:6443 rr\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# curl 10.103.97.12:6443 \r\ncurl: (7) Failed connect to 10.103.97.12:6443; \u62d2\u7edd\u8fde\u63a5\r\n<\/pre>\n\u518d\u628anginx\u90fd\u542f\u52a8\u8d77\u6765,\u89c4\u5219\u5c31\u81ea\u52a8\u88ab\u52a0\u56de\u6765<\/p>\n
\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# docker start nginx1 nginx2 nginx3\r\nnginx1\r\nnginx2\r\nnginx3\r\n[root@iZj6c9fiza9orwscdhate4Z ~]# ipvsadm -Ln\r\nIP Virtual Server version 1.2.1 (size=4096)\r\nProt LocalAddress:Port Scheduler Flags\r\n -> RemoteAddress:Port Forward Weight ActiveConn InActConn\r\nTCP 10.103.97.12:6443 rr\r\n -> 127.0.0.1:8081 Masq 1 0 0 \r\n -> 127.0.0.1:8082 Masq 1 0 0 \r\n -> 127.0.0.1:8083 Masq 1 0 0 \r\n<\/pre>\n\u6240\u4ee5sealos\u4e2d\uff0c\u4e0a\u9762apiserver\u5c31\u662f\u4e0a\u9762\u4e09\u4e2anginx\uff0clvscare\u4f1a\u5bf9\u5176\u8fdb\u884c\u5065\u5eb7\u68c0\u6d4b\u3002\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u628alvscare\u7528\u4e8e\u4e00\u4e9b\u5176\u5b83\u573a\u666f\uff0c\u6bd4\u5982\u4ee3\u7406\u81ea\u5df1\u7684TCP\u670d\u52a1\u7b49<\/p>\n","protected":false},"excerpt":{"rendered":"
\u672c\u6587\u6559\u4f60\u5982\u4f55\u7528\u4e00\u6761\u547d\u4ee4\u6784\u5efak8s\u9ad8\u53ef\u7528\u96c6\u7fa4\u4e14\u4e0d\u4f9d\u8d56haproxy\u548ckeepalived\uff0c\u4e5f\u65e0\u9700ansible\u3002 […]<\/p>\n","protected":false},"author":668,"featured_media":142067,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-144555","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/144555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=144555"}],"version-history":[{"count":28,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/144555\/revisions"}],"predecessor-version":[{"id":144761,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/144555\/revisions\/144761"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/142067"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=144555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=144555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=144555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}