{"id":1179,"date":"2022-04-07T15:07:40","date_gmt":"2022-04-07T07:07:40","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1179"},"modified":"2022-04-07T20:28:51","modified_gmt":"2022-04-07T12:28:51","slug":"1-k8s%e5%9f%ba%e6%9c%ac%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1179","title":{"rendered":"1.k8s\u57fa\u672c\u4ecb\u7ecd\u53cak8s\u96c6\u7fa4\u5b89\u88c5\u90e8\u7f72"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.k8s\u96c6\u7fa4\u57fa\u672c\u4ecb\u7ecd<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fk8<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k8s\u662f\u4e00\u4e2adocker\u96c6\u7fa4\u7684\u7ba1\u7406\u5de5\u5177\nk8s\u662f\u5bb9\u5668\u7684\u7f16\u6392\u5de5\u5177\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.k8s\u7684\u6838\u5fc3\u529f\u80fd<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u81ea\u6108: \u91cd\u65b0\u542f\u52a8\u5931\u8d25\u7684\u5bb9\u5668\uff0c\u5728\u8282\u70b9\u4e0d\u53ef\u7528\u65f6\uff0c\u66ff\u6362\u548c\u91cd\u65b0\u8c03\u5ea6\u8282\u70b9\u4e0a\u7684\u5bb9\u5668\uff0c\u5bf9\u7528\u6237\u5b9a\u4e49\u7684\u5065\u5eb7\u68c0\u67e5\u4e0d\u54cd\u5e94\u7684\u5bb9\u5668\u4f1a\u88ab\u4e2d\u6b62\uff0c\u5e76\u4e14\u5728\u5bb9\u5668\u51c6\u5907\u597d\u670d\u52a1\u4e4b\u524d\u4e0d\u4f1a\u628a\u5176\u5411\u5ba2\u6237\u7aef\u5e7f\u64ad\u3002\n\u5f39\u6027\u4f38\u7f29: \u901a\u8fc7\u76d1\u63a7\u5bb9\u5668\u7684cpu\u7684\u8d1f\u8f7d\u503c,\u5982\u679c\u8fd9\u4e2a\u5e73\u5747\u9ad8\u4e8e80%,\u589e\u52a0\u5bb9\u5668\u7684\u6570\u91cf,\u5982\u679c\u8fd9\u4e2a\u5e73\u5747\u4f4e\u4e8e10%,\u51cf\u5c11\u5bb9\u5668\u7684\u6570\u91cf\n\u670d\u52a1\u7684\u81ea\u52a8\u53d1\u73b0\u548c\u8d1f\u8f7d\u5747\u8861: \u4e0d\u9700\u8981\u4fee\u6539\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u6765\u4f7f\u7528\u4e0d\u719f\u6089\u7684\u670d\u52a1\u53d1\u73b0\u673a\u5236\uff0cKubernetes \u4e3a\u5bb9\u5668\u63d0\u4f9b\u4e86\u81ea\u5df1\u7684 IP \u5730\u5740\u548c\u4e00\u7ec4\u5bb9\u5668\u7684\u5355\u4e2a DNS \u540d\u79f0\uff0c\u5e76\u53ef\u4ee5\u5728\u5b83\u4eec\u4e4b\u95f4\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002\n\u6eda\u52a8\u5347\u7ea7\u548c\u4e00\u952e\u56de\u6eda: Kubernetes \u9010\u6e10\u90e8\u7f72\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6216\u5176\u914d\u7f6e\u7684\u66f4\u6539\uff0c\u540c\u65f6\u76d1\u89c6\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u72b6\u51b5\uff0c\u4ee5\u786e\u4fdd\u5b83\u4e0d\u4f1a\u540c\u65f6\u7ec8\u6b62\u6240\u6709\u5b9e\u4f8b\u3002 \u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0cKubernetes\u4f1a\u4e3a\u60a8\u6062\u590d\u66f4\u6539\uff0c\u5229\u7528\u65e5\u76ca\u589e\u957f\u7684\u90e8\u7f72\u89e3\u51b3\u65b9\u6848\u7684\u751f\u6001\u7cfb\u7edf\u3002\n\u79c1\u5bc6\u914d\u7f6e\u6587\u4ef6\u7ba1\u7406. web\u5bb9\u5668\u91cc\u9762,\u6570\u636e\u5e93\u7684\u8d26\u6237\u5bc6\u7801(\u6d4b\u8bd5\u5e93\u5bc6\u7801)\n<\/code><\/pre>\n\n\n\n<p><strong><em>3.k8s\u7684\u5386\u53f2<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2014\u5e74 docker\u5bb9\u5668\u7f16\u6392\u5de5\u5177\uff0c\u7acb\u9879\n2015\u5e747\u6708 \u53d1\u5e03kubernetes 1.0, \u52a0\u5165cncf\u57fa\u91d1\u4f1a \u5b75\u5316\n2016\u5e74\uff0ckubernetes\u5e72\u6389\u4e24\u4e2a\u5bf9\u624b\uff0cdocker swarm\uff0cmesos marathon 1.2\u7248\n2017\u5e74 1.5 -1.9\n2018\u5e74 k8s \u4ececncf\u57fa\u91d1\u4f1a \u6bd5\u4e1a\u9879\u76ee1.10 1.11 1.12\n2019\u5e74\uff1a 1.13, 1.14 \uff0c1.15,1.16 1.17\ncncf :cloud native compute foundation \u5b75\u5316\u5668\nkubernetes \uff08k8s\uff09: \u5e0c\u814a\u8bed \u8235\u624b\uff0c\u9886\u822a\u8005 \u5bb9\u5668\u7f16\u6392\u9886\u57df\uff0c\n\u8c37\u6b4c15\u5e74\u5bb9\u5668\u4f7f\u7528\u7ecf\u9a8c\uff0cborg\u5bb9\u5668\u7ba1\u7406\u5e73\u53f0\uff0c\u4f7f\u7528golang\u91cd\u6784borg\uff0ckubernetes\n<\/code><\/pre>\n\n\n\n<p><strong><em>4.k8s\u7684\u5b89\u88c5\u65b9\u5f0f<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum\u5b89\u88c5 1.5 \u6700\u5bb9\u6613\u5b89\u88c5\u6210\u529f\uff0c\u6700\u9002\u5408\u5b66\u4e60\u7684\n\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5---\u96be\u5ea6\u6700\u5927 \u53ef\u4ee5\u5b89\u88c5\u6700\u65b0\u7248\n\u4e8c\u8fdb\u5236\u5b89\u88c5---\u6b65\u9aa4\u7e41\u7410 \u53ef\u4ee5\u5b89\u88c5\u6700\u65b0\u7248 shell,ansible,saltstack\nkubeadm \u5b89\u88c5\u6700\u5bb9\u6613, \u7f51\u7edc \u53ef\u4ee5\u5b89\u88c5\u6700\u65b0\u7248\nminikube \u9002\u5408\u5f00\u53d1\u4eba\u5458\u4f53\u9a8ck8s, \u7f51\u7edc\n<\/code><\/pre>\n\n\n\n<p><strong><em>5.k8s\u7684\u5e94\u7528\u573a\u666f<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>k8s\u6700\u9002\u5408\u8dd1\u5fae\u670d\u52a1\u9879\u76ee<\/code><\/pre>\n\n\n\n<p><strong><em>6.k8s\u96c6\u7fa4\u7684\u67b6\u6784<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"598\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-13.png\" alt=\"\" class=\"wp-image-1182\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-13.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-13-300x207.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-13-768x531.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p>\u9664\u4e86\u6838\u5fc3\u7ec4\u4ef6\uff0c\u8fd8\u6709\u4e00\u4e9b\u63a8\u8350\u7684Add-ons<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u7ec4\u4ef6\u540d\u79f0<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td>kube-dns<\/td><td>\u8d1f\u8d23\u4e3a\u6574\u4e2a\u96c6\u7fa4\u63d0\u4f9bDNS\u670d\u52a1<\/td><\/tr><tr><td>Ingress Controller<\/td><td>\u4e3a\u670d\u52a1\u63d0\u4f9b\u5916\u7f51\u5165\u53e3<\/td><\/tr><tr><td>Heapster<\/td><td>\u63d0\u4f9b\u8d44\u6e90\u76d1\u63a7<\/td><\/tr><tr><td>Dashboard<\/td><td>\u63d0\u4f9bGUI<\/td><\/tr><tr><td>Federation<\/td><td>\u63d0\u4f9b\u8de8\u53ef\u7528\u533a\u7684\u96c6\u7fa4<\/td><\/tr><tr><td>Fluentd-elasticsearch<\/td><td>\u63d0\u4f9b\u96c6\u7fa4\u65e5\u5fd7\u91c7\u96c6\u3001\u5b58\u50a8\u4e0e\u67e5\u8be2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.k8s\u96c6\u7fa4\u7684\u5b89\u88c5<\/h2>\n\n\n\n<p><strong><em>1.\u4fee\u6539IP\u5730\u5740\u3001\u4e3b\u673a\u540d\u548chost\u89e3\u6790<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10.0.0.11  k8s-master\r\n10.0.0.12  k8s-node-1\r\n10.0.0.13  k8s-node-2\r\n\u6240\u6709\u8282\u70b9\u9700\u8981\u505ahosts\u89e3\u6790\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.master\u8282\u70b9\u5b89\u88c5etcd<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master ~]# yum install etcd -y\r\n<strong>###\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/strong>\r\n&#91;root@k8s-master ~]# egrep \"^&#91;a-Z]\" \/etc\/etcd\/etcd.conf\r\nETCD_DATA_DIR=\"\/var\/lib\/etcd\/default.etcd\"###etcd\u6570\u636e\u76ee\u5f55\r\nETCD_LISTEN_CLIENT_URLS=\"http:\/\/0.0.0.0:2379\"##etcd\u76d1\u542c\u7684\u5730\u5740\r\nETCD_NAME=\"default\"###etcd\u540d\u5b57\r\nETCD_ADVERTISE_CLIENT_URLS=\"http:\/\/10.0.0.11:2379\"#etcd\u96c6\u7fa4\u901a\u4fe1\u5730\u5740\r\n&#91;root@k8s-master ~]# systemctl start etcd\r\n&#91;root@k8s-master ~]# systemctl enable etcd\r\n<strong>###\u68c0\u67e5etcd\u914d\u7f6e\u662f\u5426\u6210\u529f<\/strong>\r\n\u6ce8\u610f8e9e05c52164694d\u662f\u968f\u673a\u751f\u6210\u7684memid\r\n&#91;root@k8s-master ~]# etcdctl -C http:\/\/10.0.0.11:2379 cluster-health\r\nmember 8e9e05c52164694d is healthy: got healthy result from http:\/\/10.0.0.11:2379\r\ncluster is healthy\r\netcd\u539f\u751f\u652f\u6301\u505a\u96c6\u7fa4\r<\/code><\/pre>\n\n\n\n<p><strong>3.master\u8282\u70b9\u5b89\u88c5kubernetes<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master ~]# yum install kubernetes-master.x86_64 -y\n<strong>####\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/strong>\r\n&#91;root@k8s-master ~]# egrep \"^&#91;a-Z]\" \/etc\/kubernetes\/apiserver\r\nKUBE_API_ADDRESS=\"--insecure-bind-address=0.0.0.0\"#apiserver\u76d1\u542c\u5730\u5740\r\nKUBE_API_PORT=\"--port=8080\"###apiserver\u76d1\u542c\u7aef\u53e3\r\nKUBE_ETCD_SERVERS=\"--etcd-servers=http:\/\/10.0.0.11:2379\"#etcd\u670d\u52a1\u7aef\u5730\u5740\r\nKUBE_SERVICE_ADDRESSES=\"--service-cluster-ip-range=10.254.0.0\/16\"#\u96c6\u7fa4ip\u6bb5\uff0c\u6682\u65f6\u4e0d\u914d\u7f6e\r\nKUBE_ADMISSION_CONTROL=\"--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota\"##\u51c6\u5165\u63a7\u5236\u7b56\u7565\uff0c\u4e3a\u65b9\u4fbf\u5b66\u4e60\uff0c\u5c06\u5012\u6570\u7b2c\u4e8c\u4e2a\u7b56\u7565\u5220\u9664\r\nKUBE_API_ARGS=\"\"###\u81ea\u5b9a\u4e49\u53c2\u6570\uff0c\u6682\u65f6\u4e0d\u8bbe\u7f6e\r\n\r\n&#91;root@k8s-master ~]# egrep \"^&#91;a-Z]\" \/etc\/kubernetes\/config \r\nKUBE_LOGTOSTDERR=\"--logtostderr=true\"#\u65e5\u5fd7\u662f\u5426\u5199\u5165\u7cfb\u7edf\u65e5\u5fd7\r\nKUBE_LOG_LEVEL=\"--v=0\"#\u65e5\u5fd7\u7ea7\u522b\r\nKUBE_ALLOW_PRIV=\"--allow-privileged=false\"#\u662f\u5426\u5f00\u542f\u5bb9\u5668\u7684\u7279\u6743\u6a21\u5f0f\r\nKUBE_MASTER=\"--master=http:\/\/10.0.0.11:8080\"#k8smaster\u5730\u5740\r\n<strong>##\u542f\u52a8\u670d\u52a1<\/strong>\r\n&#91;root@k8s-master ~]# systemctl enable kube-apiserver.service\r\n&#91;root@k8s-master ~]# systemctl restart kube-apiserver.service\r\n&#91;root@k8s-master ~]# systemctl restart kube-controller-manager.service\r\n&#91;root@k8s-master ~]# systemctl restart kube-scheduler.service\r\n<strong>##\u68c0\u67e5\u662f\u5426\u5b89\u88c5\u6b63\u5e38<\/strong>\r\n&#91;root@k8s-master ~]# kubectl get cs\r\nNAME                 STATUS    MESSAGE             ERROR\r\netcd-0               Healthy   {\"health\":\"true\"}   \r\nscheduler            Healthy   ok                  \r\ncontroller-manager   Healthy   ok                  \r\n###########cs=componentstatus\r<\/code><\/pre>\n\n\n\n<p><strong><em>4.node\u8282\u70b9\u5b89\u88c5kubernetes<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-node01 ~]# yum install kubernetes-node.x86_64 -y\r\n<strong>####\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/strong>\r\n&#91;root@k8s-node01 ~]# egrep \"^&#91;a-Z]\" \/etc\/kubernetes\/config\r\nKUBE_LOGTOSTDERR=\"--logtostderr=true\"##\u662f\u5426\u5199\u5165\u7cfb\u7edf\u65e5\u5fd7\r\nKUBE_LOG_LEVEL=\"--v=0\"##\u65e5\u5fd7\u7ea7\u522b\r\nKUBE_ALLOW_PRIV=\"--allow-privileged=false\"##\u662f\u5426\u5f00\u542f\u5bb9\u5668\u7279\u6743\u6a21\u5f0f\r\nKUBE_MASTER=\"--master=http:\/\/10.0.0.11:8080\"##k8s master\u5730\u5740\r\n\r\n&#91;root@k8s-node01 ~]# egrep \"^&#91;a-Z]\" \/etc\/kubernetes\/kubelet\r\nKUBELET_ADDRESS=\"--address=0.0.0.0\"##\u76d1\u542c\u5730\u5740\r\nKUBELET_HOSTNAME=\"--hostname-override=10.0.0.12\"##\u8282\u70b9\u540d\u5b57\uff0c\u4e0d\u914d\u7f6e\u4f7f\u7528\u4e3b\u673a\u540d\u4f5c\u4e3a\u8282\u70b9\u540d\u5b57\uff0c\u6ce8\u610f\u8282\u70b9\u540d\u5b57\u4e0d\u80fd\u51b2\u7a81\r\nKUBELET_API_SERVER=\"--api-servers=http:\/\/10.0.0.11:8080\"#apiserver\u5730\u5740\r\nKUBELET_POD_INFRA_CONTAINER=\"--pod-infra-container-image=registry.access.redhat.com\/rhel7\/pod-infrastructure:latest\"##pod\u57fa\u7840\u5bb9\u5668pull\u5730\u5740\uff0c\u6682\u4e0d\u8bbe\u7f6e\uff0c\u540e\u9762\u4f1a\u8bbe\u7f6e\u4e3a\u79c1\u6709\u4ed3\u5e93\u5730\u5740\r\nKUBELET_ARGS=\"\"##\u81ea\u5b9a\u4e49\u53c2\u6570\uff0c\u6682\u4e0d\u8bbe\u7f6e\r\n<strong>####node\u8282\u70b9\u542f\u52a8\u670d\u52a1<\/strong>\r\n&#91;root@k8s-node01 ~]# systemctl enable kubelet.service\r\n&#91;root@k8s-node01 ~]# systemctl restart kubelet.service\r\n&#91;root@k8s-node01 ~]# systemctl restart kube-proxy.service\r\n&#91;root@k8s-node01 ~]# systemctl enable kube-proxy.service\r\n<strong>##\u6ce8\u610f\u9700\u8981\u5c06docker\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u52a8<\/strong>\r\n\u5982\u679cnode\u8282\u70b9\u5b89\u88c5k8s\u4f1a\u5b89\u88c5\u81ea\u52a8docker\uff0c\u5982\u679cdocker\u670d\u52a1\u6ca1\u8d77\u6765\uff0c\u90a3\u4e48kubelet\u670d\u52a1\u4e5f\u65e0\u6cd5\u542f\u52a8\uff0ckubelet\u4f1a\u81ea\u52a8\u62c9\u8d77docker\u670d\u52a1\u3002\u5177\u4f53\u539f\u56e0\u4e3aKubelet\u670d\u52a1\u542f\u52a8\u6587\u4ef6\u6709\u5982\u4e0b\u5185\u5bb9\uff1a\r\n&#91;root@k8s-node01 ~]# systemctl cat kubelet.service|grep -E \u201cAfter|Requires\u201d\r\nAfter=docker.service##docker\u542f\u52a8\u4e4b\u540e\u518d\u542f\u52a8kubelet\r\nRequires=docker.service###\u9700\u6c42\u662fdocker\r\n<strong>####\u5728master\u8282\u70b9\u68c0\u67e5<\/strong>\r\n&#91;root@k8s-master ~]# kubectl get nodes\r\nNAME        STATUS    AGE\r\n10.0.0.12   Ready     57m\r\n10.0.0.13   Ready     57m\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.k8s\u96c6\u7fa4\u7f51\u7edc\u63d2\u4ef6flannel\u90e8\u7f72<\/h2>\n\n\n\n<p><strong><em>1.flannel\u7f51\u7edc\u7684\u4e09\u79cd\u6a21\u5f0f<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>udp\u6a21\u5f0f\r\nhostgw\u7f51\u7edc\r\nvxlan\u7f51\u7edc\r\nudp\u6a21\u5f0f\uff1a\u4f7f\u7528\u8bbe\u5907flannel.0\u8fdb\u884c\u5c01\u5305\u89e3\u5305\uff0c\u4e0d\u662f\u5185\u6838\u539f\u751f\u652f\u6301\uff0c\u4e0a\u4e0b\u6587\u5207\u6362\u8f83\u5927\uff0c\u6027\u80fd\u975e\u5e38\u5dee\r\nvxlan\u6a21\u5f0f\uff1a\u4f7f\u7528flannel.1\u8fdb\u884c\u5c01\u5305\u89e3\u5305\uff0c\u5185\u6838\u539f\u751f\u652f\u6301\uff0c\u6027\u80fd\u8f83\u5f3a\r\nhost-gw\u6a21\u5f0f\uff1a\u65e0\u9700flannel.1\u8fd9\u6837\u7684\u4e2d\u95f4\u8bbe\u5907\uff0c\u76f4\u63a5\u5bbf\u4e3b\u673a\u5f53\u4f5c\u5b50\u7f51\u7684\u4e0b\u4e00\u8df3\u5730\u5740\uff0c\u6027\u80fd\u6700\u5f3a\r\nhost-gw\u7684\u6027\u80fd\u635f\u5931\u5927\u7ea6\u572810%\u5de6\u53f3\uff0c\u800c\u5176\u4ed6\u6240\u6709\u57fa\u4e8eVXLAN\u201c\u96a7\u9053\u201d\u673a\u5236 \u7684\u7f51\u7edc\u65b9\u6848\uff0c\u6027\u80fd\u635f\u5931\u572820%~30%\u5de6\u53f3\r\n\u8be6\u7ec6\u8bf7\u53c2\u9605\u4ee5\u4e0b\u94fe\u63a5https:\/\/bbs.huaweicloud.com\/blogs\/126511\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u6240\u6709\u8282\u70b9\u914d\u7f6eflannel\u7f51\u7edc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install flannel -y\r\n&#91;root@k8s-master ~]# cat \/etc\/sysconfig\/flanneld \r\n# Flanneld configuration options  \r\n\r\n# etcd url location.  Point this to the server where etcd runs\r\nFLANNEL_ETCD_ENDPOINTS=\"http:\/\/10.0.0.11:2379\"##etcd\u94fe\u63a5\u5730\u5740\r\n\r\n# etcd config key.  This is the configuration key that flannel queries\r\n# For address range assignment\r\nFLANNEL_ETCD_PREFIX=\"\/atomic.io\/network\"#\u94fe\u63a5etcd\u7684\u524d\u7f00\uff0c\u8bbe\u7f6e\u7f51\u7edc\u5730\u5740\u6bb5\r\n\r\n# Any additional options that you want to pass\r\n#FLANNEL_OPTIONS=\"\"\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u914d\u7f6eudp\u6a21\u5f0f\u7f51\u7edc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>###master\u8282\u70b9<\/strong>\r\n&#91;root@k8s-master ~]# etcdctl mk \/atomic.io\/network\/config '{\"Network\":\"172.18.0.0\/16\"}'\r\n&#91;root@k8s-master ~]#  systemctl restart flanneld.service \r\n&#91;root@k8s-master ~]#  systemctl enable flanneld.service\r\n<strong>###\u5168\u90e8node\u8282\u70b9<\/strong>\r\n&#91;root@k8s-node01 ~]#  systemctl restart flanneld.service \r\n&#91;root@k8s-node01 ~]#  systemctl enable flanneld.service\r\n<strong>######\u5404\u8282\u70b9\u67e5\u770b\u7f51\u5361\uff0c\u53d1\u73b0\u591a\u4e86\u4e00\u4e2aflannel0\u7f51\u5361\uff0c\u5e76\u968f\u673a\u5206\u914d\u4e86\u4e00\u4e2a\u7f51\u6bb5\u4f46\u662fdocker\u7684\u7f51\u6bb5\u548cflannel\u7684\u7f51\u6bb5\u4e0d\u4e00\u81f4<\/strong>\r\n\u9700\u8981\u91cd\u542fdocker\u624d\u4f1a\u4e00\u81f4\r\n&#91;root@k8s-node02 ~]# systemctl restart docker\r\n<strong>###\u4e24\u4e2a\u8282\u70b9\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668<\/strong>\r\n&#91;root@k8s-node02 ~]# docker run  -it docker.io\/alpine:latest\r\n&#91;root@k8s-node01 ~]# docker run  -it docker.io\/alpine:latest\r\n<strong>###\u6d4b\u8bd5\u4e24\u4e2a\u8282\u70b9\u5bb9\u5668\u7684\u8054\u901a\u6027<\/strong>\r\n\u5728node01\u8282\u70b9\u7684\u5bb9\u5668\u4e2dping node02\u8282\u70b9\u5bb9\u5668\u7684\u7f51\u5173\uff0c\u53d1\u73b0\u53ef\u4ee5ping\u901a\r\n\/ # ping -c1 -W1 172.18.17.1\r\nPING 172.18.17.1 (172.18.17.1): 56 data bytes\r\n64 bytes from 172.18.17.1: seq=0 ttl=61 time=2.920 ms\r\n\r\n--- 172.18.17.1 ping statistics ---\r\n1 packets transmitted, 1 packets received, 0% packet loss\r\nround-trip min\/avg\/max = 2.920\/2.920\/2.920 ms\r\n<strong>###\u4f46\u662fping\u5bb9\u5668\u7684ip\u5730\u5740\uff0c\u53d1\u73b0\u65e0\u6cd5ping\u901a<\/strong>\r\n\/ # ping -c1 -W1 172.18.17.2\r\nPING 172.18.17.2 (172.18.17.2): 56 data bytes\r\n\r\n--- 172.18.17.2 ping statistics ---\r\n1 packets transmitted, 0 packets received, 100% packet loss\r\n<strong>###\u5bb9\u5668ping\u4e0d\u901a\u9700\u8981\u8c03\u4e00\u4e0biptables\u9632\u706b\u5899\u7684\u89c4\u5219<\/strong>\r\n&#91;root@k8s-node01 ~]# iptables -P FORWARD ACCEPT\r\n\u7136\u540e\u518dping\u4ee5\u4e0bnode01\u7684\u5bb9\u5668\uff0c\u53d1\u73b0\u7f51\u7edc\u5df2\u7ecf\u901a\u4e86\r\n\/ # ping -c1 -W1 172.18.17.2\r\nPING 172.18.17.2 (172.18.17.2): 56 data bytes\r\n64 bytes from 172.18.17.2: seq=0 ttl=60 time=2.199 ms\r\n\r\n--- 172.18.17.2 ping statistics ---\r\n1 packets transmitted, 1 packets received, 0% packet loss\r\nround-trip min\/avg\/max = 2.199\/2.199\/2.199 ms\r\n<strong>\u4f46\u662f\u7f51\u7edc\u5ef6\u8fdf\u6bd4\u8f83\u9ad8<\/strong>\r<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u914d\u7f6evxlan\u6a21\u5f0f\u7f51\u7edc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>###\u6240\u6709\u4e3b\u673a\u5148\u5173\u95edflannel\u670d\u52a1<\/strong>\r\n&#91;root@k8s-master ~]# systemctl stop flanneld\r\n&#91;root@k8s-node01 ~]# systemctl stop flanneld\r\n&#91;root@k8s-node02 ~]# systemctl stop flanneld\r\n<strong>###\u5220\u9664\u4e4b\u524detcd\u521b\u5efa\u7684key\u5e76\u91cd\u65b0\u521b\u5efa<\/strong>\r\n&#91;root@k8s-master ~]# etcdctl rm \/atomic.io\/network\/config\r\n&#91;root@k8s-master ~]# etcdctl mk \/atomic.io\/network\/config '{\"Network\":\"172.18.0.0\/16\",\"Backend\": {\"Type\": \"vxlan\"}}'\r\n<strong>###\u5404\u8282\u70b9\u91cd\u65b0\u542f\u52a8flannel\u7f51\u7edc\u548cdocker\u5e76\u542f\u52a8\u4e00\u7ec4\u5bb9\u5668<\/strong>\r\n&#91;root@k8s-node02 ~]# systemctl restart flanneld.service\r\n&#91;root@k8s-node01 ~]# systemctl restart flanneld.service\r\n&#91;root@k8s-master ~]# systemctl restart flanneld.service\r\n&#91;root@k8s-node02 ~]# docker run  -it docker.io\/alpine:latest\r\n&#91;root@k8s-node01 ~]# docker run  -it docker.io\/alpine:latest\r\n<strong>####\u67e5\u770b\u7f51\u5361\u4fe1\u606f\u6211\u4eec\u53ef\u4ee5\u770b\u5230flannel.0\u53d8\u6210\u4e86flannel.1\r\n###\u6d4b\u8bd5\u4e24\u4e2a\u8282\u70b9\u5bb9\u5668\u7684\u8054\u901a\u6027<\/strong>\r\n\u5728node01\u8282\u70b9\u7684\u5bb9\u5668\u4e2dping node02\u8282\u70b9\u5bb9\u5668\u7684\u7f51\u5173\uff0c\u53d1\u73b0\u53ef\u4ee5ping\u901a\r\n\/ # ping -c1 -W1 172.18.17.1\r\nPING 172.18.17.1 (172.18.17.1): 56 data bytes\r\n64 bytes from 172.18.17.1: seq=0 ttl=61 time=2.920 ms\r\n\r\n--- 172.18.17.1 ping statistics ---\r\n1 packets transmitted, 1 packets received, 0% packet loss\r\nround-trip min\/avg\/max = 2.920\/2.920\/2.920 ms\r\n###\u4f46\u662fping\u5bb9\u5668\u7684ip\u5730\u5740\uff0c\u53d1\u73b0\u65e0\u6cd5ping\u901a\r\n\/ # ping -c1 -W1 172.18.17.2\r\nPING 172.18.17.2 (172.18.17.2): 56 data bytes\r\n\r\n--- 172.18.17.2 ping statistics ---\r\n1 packets transmitted, 0 packets received, 100% packet loss\r\n<strong>###\u5bb9\u5668ping\u4e0d\u901a\u9700\u8981\u8c03\u4e00\u4e0biptables\u9632\u706b\u5899\u7684\u89c4\u5219<\/strong>\r\n&#91;root@k8s-node01 ~]# iptables -P FORWARD ACCEPT\r\n\u7136\u540e\u518dping\u4ee5\u4e0bnode01\u7684\u5bb9\u5668\uff0c\u53d1\u73b0\u7f51\u7edc\u5df2\u7ecf\u901a\u4e86\r\n\/ # ping -c1 -W1 172.18.17.2\r\nPING 172.18.17.2 (172.18.17.2): 56 data bytes\r\n64 bytes from 172.18.17.2: seq=0 ttl=60 time=2.199 ms\r\n\r\n--- 172.18.17.2 ping statistics ---\r\n1 packets transmitted, 1 packets received, 0% packet loss\r\nround-trip min\/avg\/max = 2.199\/2.199\/2.199 ms\r\n<strong>\u4f46\u662f\u7f51\u7edc\u5ef6\u8fdf\u6bd4udp\u6a21\u5f0f\u7684\u5ef6\u8fdf\u8981\u4f4e\u5f88\u591a<\/strong>\r<\/code><\/pre>\n\n\n\n<p><strong><em>5.\u5982\u4f55\u4e00\u773c\u5206\u8fa8\u662fvxlan\u6a21\u5f0f\u7f51\u7edc\uff0c\u8fd8\u662fudp\u6a21\u5f0f\u7f51\u7edc<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Vxlan\u6a21\u5f0f\u7684\u7f51\u7edc\u7f51\u5361\u540d\u4e3aflannel.1\u800cudp\u6a21\u5f0f\u7684\u540d\u5b57\u4e3aflannel.0<\/code><\/pre>\n\n\n\n<p><strong><em>6.\u4e3a\u4ec0\u4e48\u4fee\u6539flannel\u7f51\u7edc\u540e\u91cd\u542fdocker\u624d\u751f\u6548<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u56e0\u4e3aflannel\u4f1a\u751f\u6210\/var\/run\/flannel\/docker\u7684\u914d\u7f6e\u6587\u4ef6\r\n&#91;root@k8s-node02 ~]# cat \/var\/run\/flannel\/docker \r\nDOCKER_OPT_BIP=\"--bip=172.18.28.1\/24\"###docker\u7f51\u6bb5\u4fe1\u606f\r\nDOCKER_OPT_IPMASQ=\"--ip-masq=true\"\r\nDOCKER_OPT_MTU=\"--mtu=1450\"\r\nDOCKER_NETWORK_OPTIONS=\" --bip=172.18.28.1\/24 --ip-masq=true --mtu=1450\"\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"129\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-14.png\" alt=\"\" class=\"wp-image-1199\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-14.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-14-300x45.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-14-768x115.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53ef\u4ee5\u770b\u5230docker\u7684\u542f\u52a8\u53c2\u6570\u591a\u4e86\u70b9\u4e1c\u897f\r\n####\u90a3\u4e3a\u4ec0\u4e48\u91cd\u542f\u5c31\u591a\u4e86\u8fd9\u51e0\u884c\u53c2\u6570\u5462\uff1f\r\n&#91;root@k8s-node01 ~]# cat \/usr\/lib\/systemd\/system\/docker.service.d\/flannel.conf \r\n&#91;Service]\r\nEnvironmentFile=-\/run\/flannel\/docker###\u52a0\u8f7d\u8fd9\u4e2a\u6587\u4ef6\r\n##\u53ef\u4ee5\u770b\u5230\u8fd9\u4e2a\u6587\u4ef6\u662fflannel\u751f\u6210\u7684\r\n&#91;root@k8s-node01 ~]# rpm -qf \/usr\/lib\/systemd\/system\/docker.service.d\/flannel.conf\r\nflannel-0.7.1-4.el7.x86_64\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"95\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-15.png\" alt=\"\" class=\"wp-image-1200\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-15.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-15-300x33.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-15-768x84.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>Docker\u7684\u542f\u52a8\u6587\u4ef6\u4e2d\u4f1a\u52a0\u8f7dflannel\u751f\u6210\u7684run\u6587\u4ef6\u4e2d\u7684\u73af\u5883\u53d8\u91cf<\/code><\/pre>\n\n\n\n<p><strong><em>7.\u4e3a\u4ec0\u4e48\u4e0d\u4fee\u6539iptables\u89c4\u5219\u4f1aping\u4e0d\u901a\u5176\u4ed6\u4e3b\u673a\u7684\u5bb9\u5668<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b89\u88c5docker\u4e4b\u524d\uff0ciptables\u7684\u89c4\u5219\u662f\u5341\u5206\u5e72\u51c0\u7684\uff0c\u4f46\u662f\u5b89\u88c5\u4e4b\u540e\uff0cdocker\u4f1a\u4fee\u6539iptables\u7684\u89c4\u5219\uff0c\u62d2\u7edd\u4e86\u6570\u636e\u5305\u7684\u8f6c\u53d1\uff0c\u9700\u8981\u5c06\u89c4\u5219\u6539\u4e3a\u5141\u8bb8<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"319\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-16.png\" alt=\"\" class=\"wp-image-1201\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-16.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-16-300x111.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/04\/image-16-768x283.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f46\u662f\u8fd9\u4e2a\u662f\u4e34\u65f6\u751f\u6548\u7684\uff0c\u5982\u679c\u91cd\u542fdocker\uff0c\u89c4\u5219\u53c8\u4f1a\u88ab\u4fee\u6539\u4e3a\u62d2\u7edd\uff0c\u90a3\u6709\u6ca1\u6709\u4e00\u52b3\u6c38\u9038\u7684\u914d\u7f6e\u5462\uff1f\r\n\u5728docker\u7684\u542f\u52a8\u6587\u4ef6\u7684service\u91cc\u6dfb\u52a0\u5982\u4e0b\u4e00\u884c\uff0c\u610f\u601d\u662f\u5728\u542f\u52a8\u540e\u505a\u7684\u52a8\u4f5c\u662f\u4fee\u6539iptables\u7684\u914d\u7f6e\u6587\u4ef6\r\nExecStartPost=\/usr\/sbin\/iptables -P FORWARD ACCEPT\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.\u914d\u7f6emaster\u4e3a\u955c\u50cf\u4ed3\u5e93<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4e3a\u4e86\u8282\u7701\u8d44\u6e90\uff0c\u8fd9\u91cc\u7528master\u8282\u70b9\u517c\u804c\u79c1\u6709\u4ed3\u5e93\uff0c\u56e0\u4e3ahaber\u5360\u7528\u8d44\u6e90\u591a\uff0c\u6240\u4ee5\u79c1\u6709\u4ed3\u5e93\u9009\u62e9register\u642d\u5efa<\/code><\/pre>\n\n\n\n<p><strong><em>1.Master\u8282\u70b9\u914d\u7f6e<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master ~]# yum -y install docker\r\n&#91;root@k8s-master ~]# cat \/etc\/docker\/daemon.json \r\n{\r\n  \"registry-mirrors\": &#91;\"https:\/\/registry.docker-cn.com\"],###\u52a0\u901f\u5730\u5740\r\n  \"insecure-registries\": &#91;\"10.0.0.11:5000\"]####\u4fe1\u4efb\u8fd9\u4e2a\u79c1\u6709\u4ed3\u5e93\uff0c\u4e0d\u7136\u8d70https\u534f\u8bae\r\n}\r\n&#91;root@k8s-master ~]# systemctl restart docker\r\n&#91;root@k8s-master ~]# systemctl enable docker\r\n&#91;root@k8s-master ~]# docker pull registry###\u62c9\u53d6\u79c1\u6709\u4ed3\u5e93\u955c\u50cf\r\n&#91;root@k8s-master ~]#docker run -d -p 5000:5000 --restart=always --name registry -v \/opt\/myregistry:\/var\/lib\/registry registry##\u542f\u52a8\u79c1\u6709\u4ed3\u5e93\u5bb9\u5668\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.node\u8282\u70b9\u914d\u7f6e\u4fe1\u4efb\u79c1\u6709\u4ed3\u5e93\u5730\u5740\u53ca\u6d4b\u8bd5<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-node02 ~]# cat \/etc\/docker\/daemon.json \r\n{\r\n  \"registry-mirrors\": &#91;\"https:\/\/registry.docker-cn.com\"],\r\n  \"insecure-registries\": &#91;\"10.0.0.11:5000\"]\r\n}\r\n&#91;root@k8s-node02 ~]# systemctl restart docker\r\n&#91;root@k8s-node02 ~]# docker tag docker.io\/alpine:latest 10.0.0.11:5000\/sunfuyang\/alpine:latest\r\n&#91;root@k8s-node02 ~]# docker push 10.0.0.11:5000\/sunfuyang\/alpine:latest\r<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1179"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1179"}],"version-history":[{"count":11,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions"}],"predecessor-version":[{"id":1204,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1179\/revisions\/1204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/media\/246"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}