{"id":9517,"date":"2025-11-24T15:01:16","date_gmt":"2025-11-24T07:01:16","guid":{"rendered":"\/?p=9517"},"modified":"2025-11-24T15:01:16","modified_gmt":"2025-11-24T07:01:16","slug":"kubernetes%e5%bf%ab%e9%80%9f%e5%ae%9e%e6%88%98%e4%b8%8e%e6%a0%b8%e5%bf%83%e5%8e%9f%e7%90%86%e5%89%96%e6%9e%90","status":"publish","type":"post","link":"\/?p=9517","title":{"rendered":"Kubernetes\u5feb\u901f\u5b9e\u6218\u4e0e\u6838\u5fc3\u539f\u7406\u5256\u6790"},"content":{"rendered":"<h2><strong>1. K8S \u6982\u89c8<\/strong><\/h2>\n<h3><strong>1.1 K8S \u662f\u4ec0\u4e48<\/strong><\/h3>\n<p>K8S\u5b98\u7f51\u6587\u6863<strong>\uff1a<\/strong><a href=\"https:\/\/kubernetes.io\/zh\/docs\/home\/\"><strong>https:\/\/kubernetes.io\/zh\/docs\/home\/<\/strong><\/a><\/p>\n<p>K8S \u662fKubernetes\u7684\u5168\u79f0\uff0c\u6e90\u4e8e\u5e0c\u814a\u8bed\uff0c\u610f\u4e3a\u201c\u8235\u624b\u201d\u6216\u201c\u98de\u884c\u5458\u201d\u3002Kubernetes \u662f\u7528\u4e8e\u81ea\u52a8\u90e8\u7f72\u3001\u6269\u7f29\u548c\u7ba1\u7406\u5bb9\u5668\u5316\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90\u7cfb\u7edf\u3002 Kubernetes \u6e90\u81ea<a href=\"http:\/\/queue.acm.org\/detail.cfm?id=2898444\">Google 15 \u5e74\u751f\u4ea7\u73af\u5883\u7684\u8fd0\u7ef4\u7ecf\u9a8c<\/a>\uff0c\u540c\u65f6\u51dd\u805a\u4e86\u793e\u533a\u7684\u6700\u4f73\u521b\u610f\u548c\u5b9e\u8df5\u3002<\/p>\n<p><strong>Docker<\/strong>\uff1a\u4f5c\u4e3a\u5f00\u6e90\u7684\u5e94\u7528\u5bb9\u5668\u5f15\u64ce\uff0c\u53ef\u4ee5\u628a\u5e94\u7528\u7a0b\u5e8f\u548c\u5176\u76f8\u5173\u4f9d\u8d56\u6253\u5305\u751f\u6210\u4e00\u4e2a Image \u955c\u50cf\u6587\u4ef6\uff0c\u662f\u4e00\u4e2a\u6807\u51c6\u7684\u8fd0\u884c\u73af\u5883\uff0c\u63d0\u4f9b\u53ef\u6301\u7eed\u4ea4\u4ed8\u7684\u80fd\u529b\uff1b<\/p>\n<p><strong>Kubernetes<\/strong>\uff1a\u4f5c\u4e3a\u5f00\u6e90\u7684\u5bb9\u5668\u7f16\u6392\u5f15\u64ce\uff0c\u7528\u6765\u5bf9\u5bb9\u5668\u5316\u5e94\u7528\u8fdb\u884c\u81ea\u52a8\u5316\u90e8\u7f72\u3001 \u6269\u7f29\u548c\u7ba1\u7406\uff1b<\/p>\n<h3><strong>1.2 K8S\u6838\u5fc3\u7279\u6027<\/strong><\/h3>\n<p>\u670d\u52a1\u53d1\u73b0\u4e0e\u8d1f\u8f7d\u5747\u8861\uff1a\u65e0\u9700\u4fee\u6539\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5373\u53ef\u4f7f\u7528\u964c\u751f\u7684\u670d\u52a1\u53d1\u73b0\u673a\u5236\u3002<\/p>\n<p>\u5b58\u50a8\u7f16\u6392\uff1a\u81ea\u52a8\u6302\u8f7d\u6240\u9009\u5b58\u50a8\u7cfb\u7edf\uff0c\u5305\u62ec\u672c\u5730\u5b58\u50a8\u3002<\/p>\n<p>Secret\u548c\u914d\u7f6e\u7ba1\u7406\uff1a\u90e8\u7f72\u66f4\u65b0Secrets\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u65f6\u4e0d\u5fc5\u91cd\u65b0\u6784\u5efa\u5bb9\u5668\u955c\u50cf\uff0c\u4e14\u4e0d\u5fc5\u5c06\u8f6f\u4ef6\u5806\u6808\u914d\u7f6e\u4e2d\u7684\u79d8\u5bc6\u4fe1\u606f\u66b4\u9732\u51fa\u6765\u3002<\/p>\n<p>\u6279\u91cf\u6267\u884c\uff1a\u9664\u4e86\u670d\u52a1\u4e4b\u5916\uff0cKubernetes\u8fd8\u53ef\u4ee5\u7ba1\u7406\u4f60\u7684\u6279\u5904\u7406\u548cCI\u5de5\u4f5c\u8d1f\u8f7d\uff0c\u5728\u671f\u671b\u65f6\u66ff\u6362\u6389\u5931\u6548\u7684\u5bb9\u5668\u3002<\/p>\n<p>\u6c34\u5e73\u6269\u7f29\uff1a\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u547d\u4ee4\u3001\u4e00\u4e2aUI\u6216\u57fa\u4e8eCPU\u4f7f\u7528\u60c5\u51b5\u81ea\u52a8\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u6269\u7f29\u3002<\/p>\n<p>\u81ea\u52a8\u5316\u4e0a\u7ebf\u548c\u56de\u6eda\uff1aKubernetes\u4f1a\u5206\u6b65\u9aa4\u5730\u5c06\u9488\u5bf9\u5e94\u7528\u6216\u5176\u914d\u7f6e\u7684\u66f4\u6539\u4e0a\u7ebf\uff0c\u540c\u65f6\u76d1\u89c6\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u72b6\u51b5\u4ee5\u786e\u4fdd\u4f60\u4e0d\u4f1a\u540c\u65f6\u7ec8\u6b62\u6240\u6709\u5b9e\u4f8b\u3002<\/p>\n<p>\u81ea\u52a8\u88c5\u7bb1\uff1a\u6839\u636e\u8d44\u6e90\u9700\u6c42\u548c\u5176\u4ed6\u7ea6\u675f\u81ea\u52a8\u653e\u7f6e\u5bb9\u5668\uff0c\u540c\u65f6\u907f\u514d\u5f71\u54cd\u53ef\u7528\u6027\u3002<\/p>\n<p>\u81ea\u6211\u4fee\u590d\uff1a\u91cd\u65b0\u542f\u52a8\u5931\u8d25\u7684\u5bb9\u5668\uff0c\u5728\u8282\u70b9\u6b7b\u4ea1\u65f6\u66ff\u6362\u5e76\u91cd\u65b0\u8c03\u5ea6\u5bb9\u5668\uff0c\u6740\u6b7b\u4e0d\u54cd\u5e94\u7528\u6237\u5b9a\u4e49\u7684\u5065\u5eb7\u68c0\u67e5\u7684\u5bb9\u5668\u3002<\/p>\n<h3><strong>1.3 K8S \u6838\u5fc3\u67b6\u6784<\/strong><\/h3>\n<p>\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e86 K8S \u7684\u6838\u5fc3\u529f\u80fd\uff1a\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u591a\u4e2a\u5bb9\u5668\u5316\u7a0b\u5e8f\u3002\u90a3\u4e48 K8S \u600e\u4e48\u505a\u5230\u7684\u5462\uff1f\u8fd9\u91cc\uff0c\u6211\u4eec\u4ece\u5b8f\u89c2\u67b6\u6784\u4e0a\u6765\u5b66\u4e60 K8S \u7684\u8bbe\u8ba1\u601d\u60f3\u3002\u9996\u5148\u770b\u4e0b\u56fe\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps1.jpg\" alt=\"img\" \/> <\/p>\n<p>K8S \u662f\u5c5e\u4e8e<strong>Master-Worker\u67b6\u6784<\/strong>\uff0c\u5373\u6709 Master \u8282\u70b9\u8d1f\u8d23\u6838\u5fc3\u7684\u8c03\u5ea6\u3001\u7ba1\u7406\u548c\u8fd0\u7ef4\uff0cWorker \u8282\u70b9\u5219\u6267\u884c\u7528\u6237\u7684\u7a0b\u5e8f\u3002\u4f46\u662f\u5728 K8S \u4e2d\uff0c\u4e3b\u8282\u70b9\u4e00\u822c\u88ab\u79f0\u4e3a<strong>Master Node<\/strong> \uff0c\u800c\u4ece\u8282\u70b9\u5219\u88ab\u79f0\u4e3a<strong>Worker Node \u6216\u8005 Node<\/strong>\u3002<\/p>\n<p>\u6ce8\u610f\uff1aMaster Node \u548c Worker Node \u662f\u5206\u522b\u5b89\u88c5\u4e86 K8S \u7684 Master \u548c Woker \u7ec4\u4ef6\u7684\u5b9e\u4f53\u670d\u52a1\u5668\uff0c\u6bcf\u4e2a Node \u90fd\u5bf9\u5e94\u4e86\u4e00\u53f0\u5b9e\u4f53\u670d\u52a1\u5668\uff08\u867d\u7136 Master Node \u53ef\u4ee5\u548c\u5176\u4e2d\u4e00\u4e2a Worker Node \u5b89\u88c5\u5728\u540c\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u4f46\u662f\u5efa\u8bae Master Node \u5355\u72ec\u90e8\u7f72\uff09\uff0c<strong>\u6240\u6709 Master Node \u548c Worker Node \u7ec4\u6210\u4e86 K8S \u96c6\u7fa4<\/strong>\uff0c\u540c\u4e00\u4e2a\u96c6\u7fa4\u53ef\u80fd\u5b58\u5728\u591a\u4e2a Master Node \u548c Worker Node\u3002 <\/p>\n<p>\u9996\u5148\u6765\u770b<strong>Master Node<\/strong>\u90fd\u6709\u54ea\u4e9b\u7ec4\u4ef6\uff1a<\/p>\n<p><strong>kube-apiserver<\/strong>\u3002<strong>K8S \u7684\u8bf7\u6c42\u5165\u53e3\u670d\u52a1<\/strong>\u3002API Server \u8d1f\u8d23\u63a5\u6536 K8S \u6240\u6709\u8bf7\u6c42\uff08\u6765\u81ea UI \u754c\u9762\u6216\u8005 CLI \u547d\u4ee4\u884c\u5de5\u5177\uff09\uff0c\u7136\u540e\uff0cAPI Server \u6839\u636e\u7528\u6237\u7684\u5177\u4f53\u8bf7\u6c42\uff0c\u53bb\u901a\u77e5\u5176\u4ed6\u7ec4\u4ef6\u5e72\u6d3b\u3002<\/p>\n<p><strong>Scheduler<\/strong>\u3002<strong>K8S \u6240\u6709 Worker Node \u7684\u8c03\u5ea6\u5668<\/strong>\u3002\u5f53\u7528\u6237\u8981\u90e8\u7f72\u670d\u52a1\u65f6\uff0cScheduler \u4f1a\u9009\u62e9\u6700\u5408\u9002\u7684 Worker Node\uff08\u670d\u52a1\u5668\uff09\u6765\u90e8\u7f72\u3002<\/p>\n<p><strong>Controller Manager<\/strong>\u3002<strong>K8S \u6240\u6709 Worker Node \u7684\u76d1\u63a7\u5668<\/strong>\u3002Controller Manager \u6709\u5f88\u591a\u5177\u4f53\u7684 Controller\uff0c Node Controller\u3001Service Controller\u3001Volume Controller \u7b49\u3002Controller \u8d1f\u8d23\u76d1\u63a7\u548c\u8c03\u6574\u5728 Worker Node \u4e0a\u90e8\u7f72\u7684\u670d\u52a1\u7684\u72b6\u6001\uff0c\u6bd4\u5982\u7528\u6237\u8981\u6c42 A \u670d\u52a1\u90e8\u7f72 2 \u4e2a\u526f\u672c\uff0c\u90a3\u4e48\u5f53\u5176\u4e2d\u4e00\u4e2a\u670d\u52a1\u6302\u4e86\u7684\u65f6\u5019\uff0cController \u4f1a\u9a6c\u4e0a\u8c03\u6574\uff0c\u8ba9 Scheduler \u518d\u9009\u62e9\u4e00\u4e2a Worker Node \u91cd\u65b0\u90e8\u7f72\u670d\u52a1\u3002<\/p>\n<p><strong>etcd<\/strong>\u3002<strong>K8S \u7684\u5b58\u50a8\u670d\u52a1<\/strong>\u3002etcd \u5b58\u50a8\u4e86 K8S \u7684\u5173\u952e\u914d\u7f6e\u548c\u7528\u6237\u914d\u7f6e\uff0cK8S \u4e2d\u4ec5 API Server \u624d\u5177\u5907\u8bfb\u5199\u6743\u9650\uff0c\u5176\u4ed6\u7ec4\u4ef6\u5fc5\u987b\u901a\u8fc7 API Server \u7684\u63a5\u53e3\u624d\u80fd\u8bfb\u5199\u6570\u636e\u3002<\/p>\n<p>\u63a5\u7740\u6765\u770b<strong>Worker Node<\/strong>\u7684\u7ec4\u4ef6\uff1a<\/p>\n<p><strong>Kubelet<\/strong>\u3002<strong>Worker Node \u7684\u76d1\u89c6\u5668\uff0c\u4ee5\u53ca\u4e0e Master Node \u7684\u901a\u8baf\u5668<\/strong>\u3002Kubelet \u662f Master Node \u5b89\u63d2\u5728 Worker Node \u4e0a\u7684\u201c\u773c\u7ebf\u201d\uff0c\u5b83\u4f1a\u5b9a\u671f\u5411 Master Node \u6c47\u62a5\u81ea\u5df1 Node \u4e0a\u8fd0\u884c\u7684\u670d\u52a1\u7684\u72b6\u6001\uff0c\u5e76\u63a5\u53d7\u6765\u81ea Master Node \u7684\u6307\u793a\u91c7\u53d6\u8c03\u6574\u63aa\u65bd\u3002\u8d1f\u8d23\u63a7\u5236\u6240\u6709\u5bb9\u5668\u7684\u542f\u52a8\u505c\u6b62\uff0c\u4fdd\u8bc1\u8282\u70b9\u5de5\u4f5c\u6b63\u5e38\u3002<\/p>\n<p><strong>Kube-Proxy<\/strong>\u3002<strong>K8S \u7684\u7f51\u7edc\u4ee3\u7406<\/strong>\u3002Kube-Proxy \u8d1f\u8d23 Node \u5728 K8S \u7684\u7f51\u7edc\u901a\u8baf\u3001\u4ee5\u53ca\u5bf9\u5916\u90e8\u7f51\u7edc\u6d41\u91cf\u7684\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<p><strong>Container Runtime<\/strong>\u3002<strong>Worker Node \u7684\u8fd0\u884c\u73af\u5883<\/strong>\u3002\u5373\u5b89\u88c5\u4e86\u5bb9\u5668\u5316\u6240\u9700\u7684\u8f6f\u4ef6\u73af\u5883\u786e\u4fdd\u5bb9\u5668\u5316\u7a0b\u5e8f\u80fd\u591f\u8dd1\u8d77\u6765\uff0c\u6bd4\u5982 Docker Engine\u8fd0\u884c\u73af\u5883\u3002<\/p>\n<h3><strong>1.4 K8S\u96c6\u7fa4\u5b89\u88c5<\/strong><\/h3>\n<p>\u5b98\u65b9\u6587\u6863\uff1a <a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/setup\/production-environment\/tools\/kubeadm\/install-kubeadm\/\">https:\/\/kubernetes.io\/zh-cn\/docs\/setup\/production-environment\/tools\/kubeadm\/install-kubeadm\/<\/a><\/p>\n<p>k8s v1.20.1  <a href=\"https:\/\/note.youdao.com\/s\/MignGqZj\">https:\/\/note.youdao.com\/s\/MignGqZj<\/a><\/p>\n<p>k8s v1.24.3 <a href=\"https:\/\/docs.qq.com\/doc\/DUWRRQmZpeE1Sd1dC\">https:\/\/docs.qq.com\/doc\/DUWRRQmZpeE1Sd1dC<\/a><\/p>\n<p>k8s v1.27.1 <a href=\"https:\/\/note.youdao.com\/s\/Dxh3Qaaa\">https:\/\/note.youdao.com\/s\/Dxh3Qaaa<\/a><\/p>\n<p><strong>\u5229\u7528sealos\u5feb\u901f\u5b89\u88c5kubernetes\u96c6\u7fa4(Fox\u8001\u5e08\u63a8\u8350):<\/strong> <a href=\"https:\/\/note.youdao.com\/s\/M2z4OzsL\">https:\/\/note.youdao.com\/s\/M2z4OzsL<\/a> <\/p>\n<h2><strong>2. K8S \u5feb\u901f\u5b9e\u6218<\/strong><\/h2>\n<h3><strong>2.1 kubectl\u547d\u4ee4\u4f7f\u7528<\/strong><\/h3>\n<p>kubectl\u662fapiserver\u7684\u5ba2\u6237\u7aef\u5de5\u5177\uff0c\u5de5\u4f5c\u5728\u547d\u4ee4\u884c\u4e0b\uff0c\u80fd\u591f\u8fde\u63a5apiserver\u5b9e\u73b0\u5404\u79cd\u589e\u5220\u6539\u67e5\u7b49\u64cd\u4f5c kubectl\u5b98\u65b9\u4f7f\u7528\u6587\u6863\uff1a<a href=\"https:\/\/kubernetes.io\/zh\/docs\/reference\/kubectl\/overview\/\">https:\/\/kubernetes.io\/zh\/docs\/reference\/kubectl\/overview\/<\/a><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps2.jpg\" alt=\"img\" \/> <\/p>\n<p>K8S\u7684\u5404\u79cd\u547d\u4ee4\u5e2e\u52a9\u6587\u6863\u505a\u5f97\u975e\u5e38\u4e0d\u9519\uff0c\u9047\u5230\u95ee\u9898\u53ef\u4ee5\u591a\u67e5help\u5e2e\u52a9<\/p>\n<h3><strong>2.2 Namespace<\/strong><\/h3>\n<p>K8s \u4e2d\uff0c<a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/overview\/working-with-objects\/namespaces\/\"><strong>\u547d\u540d\u7a7a\u95f4<\/strong>\uff08Namespace\uff09<\/a> \u63d0\u4f9b\u4e00\u79cd\u673a\u5236\uff0c\u5c06\u540c\u4e00\u96c6\u7fa4\u4e2d\u7684\u8d44\u6e90\u5212\u5206\u4e3a\u76f8\u4e92\u9694\u79bb\u7684\u7ec4\u3002\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u5185\u7684\u8d44\u6e90\u540d\u79f0\u8981\u552f\u4e00\uff0c\u547d\u540d\u7a7a\u95f4\u662f\u7528\u6765\u9694\u79bb\u8d44\u6e90\u7684\uff0c\u4e0d\u9694\u79bb\u7f51\u7edc\u3002<\/p>\n<p>Kubernetes \u542f\u52a8\u65f6\u4f1a\u521b\u5efa\u56db\u4e2a\u521d\u59cb\u547d\u540d\u7a7a\u95f4\uff1a<\/p>\n<ul>\n<li><strong>default<\/strong><\/li>\n<\/ul>\n<p>Kubernetes \u5305\u542b\u8fd9\u4e2a\u547d\u540d\u7a7a\u95f4\uff0c\u4ee5\u4fbf\u4e8e\u4f60\u65e0\u9700\u521b\u5efa\u65b0\u7684\u547d\u540d\u7a7a\u95f4\u5373\u53ef\u5f00\u59cb\u4f7f\u7528\u65b0\u96c6\u7fa4\u3002<\/p>\n<ul>\n<li><strong>kube-node-lease<\/strong><\/li>\n<\/ul>\n<p>\u8be5\u547d\u540d\u7a7a\u95f4\u5305\u542b\u7528\u4e8e\u4e0e\u5404\u4e2a\u8282\u70b9\u5173\u8054\u7684 <a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/architecture\/leases\/\">Lease\uff08\u79df\u7ea6\uff09<\/a>\u5bf9\u8c61\u3002 \u8282\u70b9\u79df\u7ea6\u5141\u8bb8 kubelet \u53d1\u9001<a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/architecture\/nodes\/#heartbeats\">\u5fc3\u8df3<\/a>\uff0c \u7531\u6b64\u63a7\u5236\u9762\u80fd\u591f\u68c0\u6d4b\u5230\u8282\u70b9\u6545\u969c\u3002<\/p>\n<ul>\n<li><strong>kube-public<\/strong><\/li>\n<\/ul>\n<p>\u6240\u6709\u7684\u5ba2\u6237\u7aef\uff08\u5305\u62ec\u672a\u7ecf\u8eab\u4efd\u9a8c\u8bc1\u7684\u5ba2\u6237\u7aef\uff09\u90fd\u53ef\u4ee5\u8bfb\u53d6\u8be5\u547d\u540d\u7a7a\u95f4\u3002 \u8be5\u547d\u540d\u7a7a\u95f4\u4e3b\u8981\u9884\u7559\u4e3a\u96c6\u7fa4\u4f7f\u7528\uff0c\u4ee5\u4fbf\u67d0\u4e9b\u8d44\u6e90\u9700\u8981\u5728\u6574\u4e2a\u96c6\u7fa4\u4e2d\u53ef\u89c1\u53ef\u8bfb\u3002 \u8be5\u547d\u540d\u7a7a\u95f4\u7684\u516c\u5171\u5c5e\u6027\u53ea\u662f\u4e00\u79cd\u7ea6\u5b9a\u800c\u975e\u8981\u6c42\u3002<\/p>\n<ul>\n<li><strong>kube-system<\/strong><\/li>\n<\/ul>\n<p>\u8be5\u547d\u540d\u7a7a\u95f4\u7528\u4e8e Kubernetes \u7cfb\u7edf\u521b\u5efa\u7684\u5bf9\u8c61\u3002<\/p>\n<pre><code># \u67e5\u770bnamespace\nkubectl get namespace\n#\u67e5\u770bkube-system\u4e0b\u7684pod\nkubectl get pods -n kube-system\n#\u67e5\u770b\u6240\u6709namespace\u4e0b\u7684pod\nkubectl get pods -A<\/code><\/pre>\n<h4><strong>\u521b\u5efaNamesapce\u793a\u4f8b<\/strong><\/h4>\n<ul>\n<li><strong>\u547d\u4ee4\u884c\u65b9\u5f0f<\/strong><\/li>\n<\/ul>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u521b\u5efaNamespace\uff1a<\/p>\n<pre><code>kubectl create namespace tuling<\/code><\/pre>\n<ul>\n<li><strong>yaml\u65b9\u5f0f<\/strong><\/li>\n<\/ul>\n<p>\u65b0\u5efa\u4e00\u4e2a\u540d\u4e3a my-namespace.yaml \u7684 YAML \u6587\u4ef6\uff0c\u5e76\u5199\u5165\u4e0b\u5217\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: Namespace\nmetadata:\n name: tulingmall<\/code><\/pre>\n<p>\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n<pre><code>kubectl apply -f my-namespace.yaml<\/code><\/pre>\n<p><strong>\u5220\u9664namesapce<\/strong><\/p>\n<pre><code>kubectl delete namespace tuling\nkubectl delete -f my-namespace.yaml<\/code><\/pre>\n<h3><strong>2.3 Pod<\/strong><\/h3>\n<p><a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/workloads\/pods\/\"><strong>Pod<\/strong><\/a> <strong>\u662f\u53ef\u4ee5\u5728 Kubernetes \u4e2d\u521b\u5efa\u548c\u7ba1\u7406\u7684\u3001\u6700\u5c0f\u7684\u53ef\u90e8\u7f72\u7684\u8ba1\u7b97\u5355\u5143\u3002<\/strong>Pod<strong>\uff08\u5c31\u50cf\u5728\u9cb8\u9c7c\u835a\u6216\u8005\u8c4c\u8c46\u835a\u4e2d\uff09<\/strong>\u662f\u4e00\u7ec4\uff08\u4e00\u4e2a\u6216\u591a\u4e2a\uff09\u5bb9\u5668\uff1b \u8fd9\u4e9b\u5bb9\u5668\u5171\u4eab\u5b58\u50a8\u3001\u7f51\u7edc\u3001\u4ee5\u53ca\u600e\u6837\u8fd0\u884c\u8fd9\u4e9b\u5bb9\u5668\u7684\u58f0\u660e\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps3.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u521b\u5efaPod\u793a\u4f8b\uff1a\u8fd0\u884c\u4e00\u4e2aNGINX\u5bb9\u5668<\/strong><\/h4>\n<ul>\n<li><strong>\u547d\u4ee4\u884c\u65b9\u5f0f<\/strong><\/li>\n<\/ul>\n<pre><code># \u521b\u5efapod\nkubectl run mynginx --image=nginx:1.14.2\n# \u83b7\u53d6pod\u7684\u4fe1\u606f\uff0c-owide \u8868\u793a\u66f4\u8be6\u7ec6\u7684\u663e\u793a\u4fe1\u606f  -n \u547d\u540d\u7a7a\u95f4 \u67e5\u8be2\u5bf9\u5e94namespace\u4e0b\u7684pod\nkubectl get pod\nkubectl get pod -owide\nkubectl get pod -owide -n &lt;namespace-name&gt;\n#\u67e5\u770bpod\u7684\u8be6\u60c5\nkubectl describe pod &lt;pod-name&gt;\n# \u67e5\u770bPod\u7684\u8fd0\u884c\u65e5\u5fd7\nkubectl logs &lt;pod-name&gt;\n# \u5220\u9664pod\nkubectl delete pod &lt;pod-name&gt;<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps4.jpg\" alt=\"img\" \/> <\/p>\n<ul>\n<li><strong>yaml\u65b9\u5f0f<\/strong><\/li>\n<\/ul>\n<pre><code>#vim nginx-pod.yaml\n\napiVersion: v1\nkind: Pod\nmetadata:\n labels:\n  run: mynginx\n name: mynginx\nspec:\n containers:\n - name: nginx\n  image: nginx:1.14.2\n  ports:\n  - containerPort: 80  <\/code><\/pre>\n<p>\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n<pre><code>kubectl apply -f  nginx-pod.yaml<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps5.jpg\" alt=\"img\" \/> <\/p>\n<p>\u5220\u9664pod<\/p>\n<pre><code>kubectl delete -f  nginx-pod.yaml<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps6.jpg\" alt=\"img\" \/> <\/p>\n<h3><strong>\u601d\u8003\uff1a\u4e00\u4e2apod\u4e2d\u53ef\u4ee5\u8fd0\u884c\u591a\u4e2a\u5bb9\u5668\u5417\uff1f<\/strong><\/h3>\n<pre><code>apiVersion: v1\nkind: Pod\nmetadata:\n labels:\n  run: myapp\n name: myapp\nspec:\n containers:\n - image: nginx:1.14.2\n  name: nginx\n - image: tomcat:9.0.55\n  name: tomcat<\/code><\/pre>\n<h3><strong>2.4 Deployment<\/strong><\/h3>\n<p>Deployment\u8d1f\u8d23\u521b\u5efa\u548c\u66f4\u65b0\u5e94\u7528\u7a0b\u5e8f\u7684\u5b9e\u4f8b\uff0c<strong>\u4f7fPod\u62e5\u6709\u591a\u526f\u672c\uff0c\u81ea\u6108\uff0c\u6269\u7f29\u5bb9\u7b49\u80fd\u529b<\/strong>\u3002\u521b\u5efaDeployment\u540e\uff0cKubernetes Master \u5c06\u5e94\u7528\u7a0b\u5e8f\u5b9e\u4f8b\u8c03\u5ea6\u5230\u96c6\u7fa4\u4e2d\u7684\u5404\u4e2a\u8282\u70b9\u4e0a\u3002\u5982\u679c\u6258\u7ba1\u5b9e\u4f8b\u7684\u8282\u70b9\u5173\u95ed\u6216\u88ab\u5220\u9664\uff0cDeployment\u63a7\u5236\u5668\u4f1a\u5c06\u8be5\u5b9e\u4f8b\u66ff\u6362\u4e3a\u7fa4\u96c6\u4e2d\u53e6\u4e00\u4e2a\u8282\u70b9\u4e0a\u7684\u5b9e\u4f8b\u3002\u8fd9\u63d0\u4f9b\u4e86\u4e00\u79cd\u81ea\u6211\u4fee\u590d\u673a\u5236\u6765\u89e3\u51b3\u673a\u5668\u6545\u969c\u7ef4\u62a4\u95ee\u9898\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps7.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u521b\u5efa\u4e00\u4e2aTomcat\u5e94\u7528\u7a0b\u5e8f<\/strong><\/h4>\n<p>\u4f7f\u7528 kubectl create deployment \u547d\u4ee4\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5e94\u7528\u90e8\u7f72<strong>deployment<\/strong>\u4e0e<strong>pod<\/strong><\/p>\n<pre><code>#my-tomcat\u8868\u793apod\u7684\u540d\u79f0 --image\u8868\u793a\u955c\u50cf\u7684\u5730\u5740 \nkubectl create deployment my-tomcat --image=tomcat:9.0.55\n#\u67e5\u770b\u4e00\u4e0bdeployment\u7684\u4fe1\u606f\nkubectl get deployment\n#\u5220\u9664deployment\nkubectl delete deployment my-tomcat\n#\u67e5\u770bPod\u6253\u5370\u7684\u65e5\u5fd7\nkubectl logs my-tomcat-6d6b57c8c8-n5gm4\n#\u4f7f\u7528 exec \u53ef\u4ee5\u5728Pod\u7684\u5bb9\u5668\u4e2d\u6267\u884c\u547d\u4ee4\nkubectl exec my-tomcat-6d6b57c8c8-n5gm4 -- env  #\u4f7f\u7528 env \u547d\u4ee4\u67e5\u770b\u73af\u5883\u53d8\u91cf\nkubectl exec my-tomcat-6d6b57c8c8-n5gm4 -- ls \/  # \u67e5\u770b\u5bb9\u5668\u7684\u6839\u76ee\u5f55\u4e0b\u9762\u5185\u5bb9\nkubectl exec -it my-tomcat-6d6b57c8c8-n5gm4 -- sh  #\u8fdb\u5165Pod\u5bb9\u5668\u5185\u90e8\u5e76\u6267\u884cbash\u547d\u4ee4\uff0c\u5982\u679c\u60f3\u9000\u51fa\u5bb9\u5668\u53ef\u4ee5\u4f7f\u7528exit\u547d\u4ee4<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps8.jpg\" alt=\"img\" \/> <\/p>\n<p>\u601d\u8003\uff1a\u4e0b\u9762\u4e24\u4e2a\u547d\u4ee4\u6709\u4ec0\u4e48\u533a\u522b?<\/p>\n<pre><code>kubectl create my-tomcat --image=tomcat:9.0.55\nkubectl create deployment my-tomcat --image=tomcat:9.0.55<\/code><\/pre>\n<h4><strong>\u81ea\u6108<\/strong><\/h4>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u5220\u9664\u521a\u521a\u6dfb\u52a0\u7684pod\uff0c\u770b\u770b\u4f1a\u53d1\u751f\u4ec0\u4e48<\/p>\n<pre><code>#\u67e5\u770bpod\u4fe1\u606f\uff0c-w\u610f\u601d\u662f\u4e00\u76f4\u7b49\u5f85\u89c2\u5bdfpod\u4fe1\u606f\u7684\u53d8\u52a8\n\nkubectl get pod -w<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps9.jpg\" alt=\"img\" \/> <\/p>\n<p>\u5f00\u53e6\u5916\u4e00\u4e2a\u547d\u4ee4\u7a97\u53e3\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u540c\u65f6\u89c2\u5bdf\u4e4b\u524d\u547d\u4ee4\u7a97\u53e3\u7684\u53d8\u5316\u60c5\u51b5<\/p>\n<pre><code>kubectl delete pod  my-tomcat-6d6b57c8c8-n5gm4<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps10.jpg\" alt=\"img\" \/> <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e4b\u524d\u90a3\u4e2atomcat\u7684pod\u88ab\u9500\u6bc1\uff0c\u4f46\u662f\u53c8\u91cd\u65b0\u542f\u52a8\u4e86\u4e00\u4e2a\u65b0\u7684tomcat pod\uff0c\u8fd9\u662fk8s\u7684\u670d\u52a1<strong>\u81ea\u6108\u529f\u80fd<\/strong>\uff0c\u4e0d\u9700\u8981\u8fd0\u7ef4\u4eba\u5458\u5e72\u9884<\/p>\n<h4><strong>\u591a\u526f\u672c<\/strong><\/h4>\n<ul>\n<li>\u547d\u4ee4\u884c\u7684\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code># \u521b\u5efa3\u4e2a\u526f\u672c\nkubectl create deployment my-tomcat --image=tomcat:9.0.55 --replicas=3<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps11.jpg\" alt=\"img\" \/> <\/p>\n<ul>\n<li>yaml\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n labels:\n  app: my-tomcat\n name: my-tomcat\nspec:\n replicas: 3\n selector:\n  matchLabels:\n   app: my-tomcat\n template:\n  metadata:\n   labels:\n     app: my-tomcat\n  spec:\n   containers:\n   \\- image: tomcat:9.0.55\n     name: tomcat  <\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps12.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u6269\u7f29\u5bb9<\/strong><\/h4>\n<pre><code># \u6269\u5bb9\u52305\u4e2apod\nkubectl scale --replicas=5 deployment my-tomcat\n# \u7f29\u52303\u4e2apod\nkubectl scale --replicas=3 deployment my-tomcat<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps13.jpg\" alt=\"img\" \/> <\/p>\n<pre><code>#\u4fee\u6539 replicas\nkubectl edit deployment my-tomcat<\/code><\/pre>\n<h4><strong>\u6eda\u52a8\u5347\u7ea7\u4e0e\u56de\u6eda<\/strong><\/h4>\n<p>\u5bf9my-tomcat\u8fd9\u4e2adeployment\u8fdb\u884c\u6eda\u52a8\u5347\u7ea7\u548c\u56de\u6eda\uff0c\u5c06tomcat\u7248\u672c\u7531tomcat:9.0.55\u5347\u7ea7\u5230tomcat:10.1.11\uff0c\u518d\u56de\u6eda\u5230tomcat:9.0.55<\/p>\n<p><strong>\u6eda\u52a8\u5347\u7ea7\uff1a<\/strong><\/p>\n<pre><code>kubectl set image deployment my-tomcat tomcat=tomcat:10.1.11 --record<\/code><\/pre>\n<p>\u53ef\u4ee5\u6267\u884c kubectl get pod -w \u89c2\u5bdfpod\u7684\u53d8\u52a8\u60c5\u51b5\uff0c\u53ef\u4ee5\u770b\u5230\u6709\u7684pod\u5728\u9500\u6bc1\uff0c\u6709\u7684pod\u5728\u521b\u5efa<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps14.jpg\" alt=\"img\" \/> <\/p>\n<p>\u67e5\u770bpod\u4fe1\u606f<\/p>\n<pre><code>kubectl get pod<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps15.jpg\" alt=\"img\" \/> <\/p>\n<p>\u67e5\u770b\u67d0\u4e2apod\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u53d1\u73b0pod\u91cc\u7684\u955c\u50cf\u7248\u672c\u5df2\u7ecf\u5347\u7ea7\u4e86<\/p>\n<pre><code>kubectl describe pod my-tomcat-85c5c8f685-lnkfm<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps16.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u7248\u672c\u56de\u6eda\uff1a<\/strong><\/p>\n<p>\u67e5\u770b\u5386\u53f2\u7248\u672c<\/p>\n<pre><code>kubectl rollout history deploy my-tomcat<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps17.jpg\" alt=\"img\" \/> <\/p>\n<p>\u56de\u6eda\u5230\u4e0a\u4e00\u4e2a\u7248\u672c<\/p>\n<pre><code>kubectl rollout undo deployment my-tomcat   #--to-revision \u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u56de\u9000\u7684\u7248\u672c\n\n#\u56de\u6eda(\u56de\u5230\u6307\u5b9a\u7248\u672c)\nkubectl rollout undo deployment\/my-dep --to-revision=2<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps18.jpg\" alt=\"img\" \/> <\/p>\n<p>\u67e5\u770bpod\u8be6\u60c5\uff0c\u53d1\u73b0\u7248\u672c\u5df2\u7ecf\u56de\u9000\u4e86<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps19.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u8bbf\u95eetomcat pod<\/strong><\/p>\n<p><strong>\u96c6\u7fa4\u5185\u8bbf\u95ee<\/strong>\uff08\u5728\u96c6\u7fa4\u91cc\u4efb\u4e00worker\u8282\u70b9\u90fd\u53ef\u4ee5\u8bbf\u95ee\uff09<\/p>\n<pre><code>curl 10.244.169.164:8080<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps20.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps21.jpg\" alt=\"img\" \/> <\/p>\n<p>\u5f53\u6211\u4eec\u5728\u96c6\u7fa4\u4e4b\u5916\u8bbf\u95ee\u662f\u53d1\u73b0\u65e0\u6cd5\u8bbf\u95ee\uff0c\u90a3\u4e48\u96c6\u7fa4\u4e4b\u5916\u7684\u5ba2\u6237\u7aef\u5982\u4f55\u624d\u80fd\u8bbf\u95ee\u5462\uff1f\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u7684service\u670d\u52a1\u4e86\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u521b\u5efa\u4e00\u4e2aservice\uff0c\u4f7f\u5916\u90e8\u5ba2\u6237\u7aef\u53ef\u4ee5\u8bbf\u95ee\u6211\u4eec\u7684pod<\/p>\n<h3><strong>2.5 Service<\/strong><\/h3>\n<p><a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/services-networking\/service\/\">Service<\/a>\u662f\u4e00\u4e2a\u62bd\u8c61\u5c42\uff0c\u5b83\u5b9a\u4e49\u4e86\u4e00\u7ec4Pod\u7684\u903b\u8f91\u96c6\uff0c\u5e76\u4e3a\u8fd9\u4e9bPod\u652f\u6301\u5916\u90e8\u6d41\u91cf\u66b4\u9732\u3001\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0\u3002<\/p>\n<p>\u5c3d\u7ba1\u6bcf\u4e2aPod \u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684IP\u5730\u5740\uff0c\u4f46\u662f\u5982\u679c\u6ca1\u6709Service\uff0c\u8fd9\u4e9bIP\u4e0d\u4f1a\u66b4\u9732\u5728\u7fa4\u96c6\u5916\u90e8\u3002Service\u5141\u8bb8\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u63a5\u6536\u6d41\u91cf\u3002Service\u4e5f\u53ef\u4ee5\u7528\u5728ServiceSpec\u6807\u8bb0type\u7684\u65b9\u5f0f\u66b4\u9732\uff0ctype\u7c7b\u578b\u5982\u4e0b\uff1a<\/p>\n<p>ClusterIP\uff08\u9ed8\u8ba4\uff09\uff1a\u5728\u96c6\u7fa4\u7684\u5185\u90e8IP\u4e0a\u516c\u5f00Service\u3002\u8fd9\u79cd\u7c7b\u578b\u4f7f\u5f97Service\u53ea\u80fd\u4ece\u96c6\u7fa4\u5185\u8bbf\u95ee\u3002<\/p>\n<p>NodePort\uff1a\u4f7f\u7528NAT\u5728\u96c6\u7fa4\u4e2d\u6bcf\u4e2a\u9009\u5b9aNode\u7684\u76f8\u540c\u7aef\u53e3\u4e0a\u516c\u5f00Service\u3002\u4f7f\u7528 <strong><NodeIP>:<NodePort><\/strong> \u4ece\u96c6\u7fa4\u5916\u90e8\u8bbf\u95eeService\u3002\u662fClusterIP\u7684\u8d85\u96c6\u3002<\/p>\n<p>LoadBalancer\uff1a\u5728\u5f53\u524d\u4e91\u4e2d\u521b\u5efa\u4e00\u4e2a\u5916\u90e8\u8d1f\u8f7d\u5747\u8861\u5668(\u5982\u679c\u652f\u6301\u7684\u8bdd)\uff0c\u5e76\u4e3aService\u5206\u914d\u4e00\u4e2a\u56fa\u5b9a\u7684\u5916\u90e8IP\u3002\u662fNodePort\u7684\u8d85\u96c6\u3002<\/p>\n<p>ExternalName\uff1a\u901a\u8fc7\u8fd4\u56de\u5e26\u6709\u8be5\u540d\u79f0\u7684CNAME\u8bb0\u5f55\uff0c\u4f7f\u7528\u4efb\u610f\u540d\u79f0\uff08\u7531spec\u4e2d\u7684externalName\u6307\u5b9a\uff09\u516c\u5f00Service\u3002\u4e0d\u4f7f\u7528\u4ee3\u7406\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps22.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u521b\u5efaservice\u793a\u4f8b<\/strong><\/h4>\n<ul>\n<li>\u547d\u4ee4\u884c\u7684\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code>kubectl expose deployment my-tomcat --name=tomcat --port=8080 --type=NodePort\n\n#\u67e5\u770bservice\u4fe1\u606f\uff0cport\u4fe1\u606f\u91cc\u5192\u53f7\u540e\u9762\u7684\u7aef\u53e3\u53f7\u5c31\u662f\u5bf9\u96c6\u7fa4\u5916\u66b4\u9732\u7684\u8bbf\u95ee\u63a5\u53e3\n# NodePort\u8303\u56f4\u5728 30000-32767 \u4e4b\u95f4\nkubectl get svc -o wide<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps23.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee<\/strong><\/p>\n<p>\u4f7f\u7528\u96c6\u7fa4\u8282\u70b9\u7684ip\u52a0\u4e0a\u66b4\u9732\u7684\u7aef\u53e3\u5c31\u53ef\u4ee5\u8bbf\u95ee<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps24.jpg\" alt=\"img\" \/> <\/p>\n<p>tomcat\u7248\u672c\u592a\u9ad8\u8fd4\u56de404\u7684\u89e3\u51b3\u529e\u6cd5\uff1a\u8fdb\u5165tomcat\u5bb9\u5668\uff0c\u628a webapps \u76ee\u5f55\u5220\u9664\uff0c\u518d\u628a webapps.dist \u91cd\u547d\u540d\u4e3a webapps \u5373\u53ef\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps25.jpg\" alt=\"img\" \/> <\/p>\n<ul>\n<li>yaml\u7684\u65b9\u5f0f<\/li>\n<\/ul>\n<pre><code class=\"language-yaml\"># vim mytomcat-service.yaml \n\napiVersion: v1\nkind: Service\nmetadata:\n labels:\n  app: my-tomcat\n name: my-tomcat\nspec:\n ports:\n - port: 8080  # service\u7684\u865a\u62dfip\u5bf9\u5e94\u7684\u7aef\u53e3\uff0c\u5728\u96c6\u7fa4\u5185\u7f51\u673a\u5668\u53ef\u4ee5\u8bbf\u95ee\u7528service\u7684\u865a\u62dfip\u52a0\u8be5\u7aef\u53e3\u53f7\u8bbf\u95ee\u670d\u52a1\n  nodePort: 30001  # service\u5728\u5bbf\u4e3b\u673a\u4e0a\u6620\u5c04\u7684\u5916\u7f51\u8bbf\u95ee\u7aef\u53e3\uff0c\u7aef\u53e3\u8303\u56f4\u5fc5\u987b\u572830000-32767\u4e4b\u95f4\n  protocol: TCP\n  targetPort: 8080  # pod\u66b4\u9732\u7684\u7aef\u53e3\uff0c\u4e00\u822c\u4e0epod\u5185\u90e8\u5bb9\u5668\u66b4\u9732\u7684\u7aef\u53e3\u4e00\u81f4\n selector:\n  app: my-tomcat\n type: NodePort<\/code><\/pre>\n<p>\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u521b\u5efaservice\uff1a<\/p>\n<pre><code>kubectl apply -f mytomcat-service.yaml <\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps26.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee<\/strong><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps27.jpg\" alt=\"img\" \/> <\/p>\n<h3><strong>2.6<\/strong> <strong>\u5b58\u50a8<\/strong><\/h3>\n<h4><strong>Volume<\/strong><\/h4>\n<p><a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/storage\/volumes\/\">Volume<\/a>\u6307\u7684\u662f\u5b58\u50a8\u5377\uff0c\u5305\u542b\u53ef\u88abPod\u4e2d\u5bb9\u5668\u8bbf\u95ee\u7684\u6570\u636e\u76ee\u5f55\u3002\u5bb9\u5668\u4e2d\u7684\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u662f\u4e34\u65f6\u5b58\u653e\u7684\uff0c\u5f53\u5bb9\u5668\u5d29\u6e83\u65f6\u6587\u4ef6\u4f1a\u4e22\u5931\uff0c\u540c\u65f6\u65e0\u6cd5\u5728\u591a\u4e2aPod\u4e2d\u5171\u4eab\u6587\u4ef6\uff0c\u901a\u8fc7\u4f7f\u7528\u5b58\u50a8\u5377\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002<\/p>\n<p>Kubernetes \u652f\u6301\u5f88\u591a\u7c7b\u578b\u7684\u5377\u3002 Pod \u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u4efb\u610f\u6570\u76ee\u7684\u5377\u7c7b\u578b\u3002 \u4e34\u65f6\u5377\u7c7b\u578b\u7684\u751f\u547d\u5468\u671f\u4e0e Pod \u76f8\u540c\uff0c\u4f46\u6301\u4e45\u5377\u53ef\u4ee5\u6bd4 Pod \u7684\u5b58\u6d3b\u671f\u957f\u3002 \u5f53 Pod \u4e0d\u518d\u5b58\u5728\u65f6\uff0cKubernetes \u4e5f\u4f1a\u9500\u6bc1\u4e34\u65f6\u5377\uff1b\u4e0d\u8fc7 Kubernetes \u4e0d\u4f1a\u9500\u6bc1\u6301\u4e45\u5377\u3002 \u5bf9\u4e8e\u7ed9\u5b9a Pod \u4e2d\u4efb\u4f55\u7c7b\u578b\u7684\u5377\uff0c\u5728\u5bb9\u5668\u91cd\u542f\u671f\u95f4\u6570\u636e\u90fd\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n<p>\u5377\u7684\u6838\u5fc3\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u5176\u4e2d\u53ef\u80fd\u5b58\u6709\u6570\u636e\uff0cPod \u4e2d\u7684\u5bb9\u5668\u53ef\u4ee5\u8bbf\u95ee\u8be5\u76ee\u5f55\u4e2d\u7684\u6570\u636e\u3002 \u6240\u91c7\u7528\u7684\u4e0d\u540c\u5377\u7684\u7c7b\u578b\u5c06\u51b3\u5b9a\u8be5\u76ee\u5f55\u5982\u4f55\u5f62\u6210\u7684\u3001\u4f7f\u7528\u4f55\u79cd\u4ecb\u8d28\u4fdd\u5b58\u6570\u636e\u4ee5\u53ca\u76ee\u5f55\u4e2d\u5b58\u653e\u7684\u5185\u5bb9\u3002\u5e38\u7528\u7684\u5377\u7c7b\u578b\u6709 <strong>configMap\u3001emptyDir\u3001local\u3001nfs\u3001secret<\/strong> \u7b49\u3002<\/p>\n<p>ConfigMap\uff1a\u53ef\u4ee5\u5c06\u914d\u7f6e\u6587\u4ef6\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u4fdd\u5b58\u5230 ConfigMap \u4e2d\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728 Pod \u4e2d\u4ee5\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf\u7684\u5f62\u5f0f\u4f7f\u7528\u3002ConfigMap \u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u4e0d\u654f\u611f\u7684\u914d\u7f6e\u4fe1\u606f\uff0c\u5982\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>EmptyDir\uff1a\u662f\u4e00\u4e2a\u7a7a\u76ee\u5f55\uff0c\u53ef\u4ee5\u5728 Pod \u4e2d\u7528\u6765\u5b58\u50a8\u4e34\u65f6\u6570\u636e\uff0c\u5f53 Pod \u88ab\u5220\u9664\u65f6\uff0c\u8be5\u76ee\u5f55\u4e5f\u4f1a\u88ab\u5220\u9664\u3002<\/p>\n<p>Local\uff1a\u5c06\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u7684\u76ee\u5f55\u6216\u6587\u4ef6\u6620\u5c04\u5230 Pod \u4e2d\u7684\u4e00\u4e2a Volume \u4e2d\uff0c\u53ef\u4ee5\u7528\u6765\u5728 Pod \u4e2d\u5171\u4eab\u6587\u4ef6\u6216\u6570\u636e\u3002<\/p>\n<p>NFS\uff1a\u5c06\u7f51\u7edc\u4e0a\u7684\u4e00\u4e2a\u6216\u591a\u4e2a NFS \u5171\u4eab\u76ee\u5f55\u6302\u8f7d\u5230 Pod \u4e2d\u7684 Volume \u4e2d\uff0c\u53ef\u4ee5\u7528\u6765\u5728\u591a\u4e2a Pod \u4e4b\u95f4\u5171\u4eab\u6570\u636e\u3002<\/p>\n<p>Secret\uff1a\u5c06\u654f\u611f\u4fe1\u606f\u4ee5\u5bc6\u6587\u7684\u5f62\u5f0f\u4fdd\u5b58\u5230 Secret \u4e2d\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728 Pod \u4e2d\u4ee5\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf\u7684\u5f62\u5f0f\u4f7f\u7528\u3002Secret \u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u654f\u611f\u4fe1\u606f\uff0c\u5982\u7528\u6237\u540d\u5bc6\u7801\u3001\u8bc1\u4e66\u7b49\u3002<\/p>\n<h5><strong>\u4f7f\u7528\u65b9\u5f0f<\/strong><\/h5>\n<p>\u4f7f\u7528\u5377\u65f6, \u5728 .spec.volumes \u5b57\u6bb5\u4e2d\u8bbe\u7f6e\u4e3a Pod \u63d0\u4f9b\u7684\u5377\uff0c\u5e76\u5728 .spec.containers[*].volumeMounts \u5b57\u6bb5\u4e2d\u58f0\u660e\u5377\u5728\u5bb9\u5668\u4e2d\u7684\u6302\u8f7d\u4f4d\u7f6e\u3002 \u5bb9\u5668\u4e2d\u7684\u8fdb\u7a0b\u770b\u5230\u7684\u6587\u4ef6\u7cfb\u7edf\u89c6\u56fe\u662f\u7531\u5b83\u4eec\u7684\u5bb9\u5668\u955c\u50cf\u7684\u521d\u59cb\u5185\u5bb9\u4ee5\u53ca\u6302\u8f7d\u5728\u5bb9\u5668\u4e2d\u7684\u5377\uff08\u5982\u679c\u5b9a\u4e49\u4e86\u7684\u8bdd\uff09\u6240\u7ec4\u6210\u7684\u3002 \u5176\u4e2d\u6839\u6587\u4ef6\u7cfb\u7edf\u540c\u5bb9\u5668\u955c\u50cf\u7684\u5185\u5bb9\u76f8\u543b\u5408\u3002 \u4efb\u4f55\u5728\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e0b\u7684\u5199\u5165\u64cd\u4f5c\uff0c\u5982\u679c\u88ab\u5141\u8bb8\u7684\u8bdd\uff0c\u90fd\u4f1a\u5f71\u54cd\u63a5\u4e0b\u6765\u5bb9\u5668\u4e2d\u8fdb\u7a0b\u8bbf\u95ee\u6587\u4ef6\u7cfb\u7edf\u65f6\u6240\u770b\u5230\u7684\u5185\u5bb9\u3002<\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: Pod\nmetadata:\n name: configmap-pod\nspec:\n containers:\n  - name: test\n   image: busybox:1.28\n   volumeMounts:\n   ..........\n volumes:\n ............<\/code><\/pre>\n<h5><strong>\u642d\u5efanfs\u6587\u4ef6\u7cfb\u7edf<\/strong><\/h5>\n<p>nfs(network filesystem ): \u7f51\u7edc\u6587\u4ef6\u5b58\u50a8\u7cfb\u7edf<\/p>\n<p><strong>\u5b89\u88c5nfs-server<\/strong><\/p>\n<pre><code class=\"language-shell\"># \u5728\u6bcf\u4e2a\u673a\u5668\u3002\nyum install -y nfs-utils\n# \u5728master \u6267\u884c\u4ee5\u4e0b\u547d\u4ee4 \necho &quot;\/nfs\/data\/ *(insecure,rw,sync,no_root_squash)&quot; &gt; \/etc\/exports\n# \u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u542f\u52a8 nfs \u670d\u52a1;\u521b\u5efa\u5171\u4eab\u76ee\u5f55\nmkdir -p \/nfs\/data\n# \u5728master\u6267\u884c\nsystemctl enable rpcbind\nsystemctl enable nfs-server\nsystemctl start rpcbind\nsystemctl start nfs-server\n# \u4f7f\u914d\u7f6e\u751f\u6548\nexportfs -r\n#\u68c0\u67e5\u914d\u7f6e\u662f\u5426\u751f\u6548\nexportfs<\/code><\/pre>\n<h5><strong>\u914d\u7f6enfs-client<\/strong><\/h5>\n<pre><code class=\"language-shell\"># nfs-server\u8282\u70b9\u7684ip\nshowmount -e 192.168.11.101\nmkdir -p \/nfs\/data\nmount -t nfs 192.168.11.101:\/nfs\/data \/nfs\/data<\/code><\/pre>\n<h5><strong>nfs\u65b9\u5f0f\u6570\u636e\u6302\u8f7d<\/strong><\/h5>\n<p>\u76f8\u5bf9\u4e8e emptyDir \u548c hostPath\uff0cnfs\u8fd9\u79cd Volume \u7c7b\u578b\u7684\u6700\u5927\u7279\u70b9\u5c31\u662f\u4e0d\u4f9d\u8d56 Kuberees Volume \u7684\u5e95\u5c42\u57fa\u7840\u8bbe\u65bd\u7531\u72ec\u7acb\u7684\u5b58\u50a8\u7cfb\u7edf\u7ba1\u7406\uff0c\u4e0e Kubernetes \u96c6\u7fa4\u662f\u5206\u79bb\u7684\u3002\u6570\u636e\u88ab\u6301\u4e45\u5316\u540e\uff0c\u5373\u4f7f\u6574\u4e2a Kubernetes \u5d29\u6e83\u4e5f\u4e0d\u4f1a\u53d7\u635f\u3002<\/p>\n<pre><code class=\"language-yaml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n labels:\n  app: nginx-pv-demo\n name: nginx-pv-demo\nspec:\n replicas: 2\n selector:\n  matchLabels:\n   app: nginx-pv-demo\n template:\n  metadata:\n   labels:\n     app: nginx-pv-demo\n  spec:\n   containers:\n   - image: nginx\n     name: nginx\n     volumeMounts:\n     - name: html\n     mountPath: \/usr\/share\/nginx\/html\n   volumes:\n     - name: html\n      nfs:\n       server: 192.168.11.101\n       path: \/nfs\/data\/nginx-pv<\/code><\/pre>\n<h4><strong>PV &amp;  PVC<\/strong><\/h4>\n<p>Volume \u63d0\u4f9b\u4e86\u975e\u5e38\u597d\u7684\u6570\u636e\u6301\u4e45\u5316\u65b9\u6848\uff0c\u4e0d\u8fc7\u5728\u53ef\u7ba1\u7406\u6027\u4e0a\u8fd8\u6709\u4e0d\u8db3\u3002\u524d\u9762 nfs \u4f8b\u5b50\u6765\u8bf4\uff0c\u8981\u4f7f\u7528 Volume\uff0c Pod \u5fc5\u987b\u4e8b\u5148\u77e5\u9053\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>\n<p>\u5f53\u524d\u7684 Volume \u7c7b\u578b\u5e76\u660e\u786e Volume \u5df2\u7ecf\u521b\u5efa\u597d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u77e5\u9053 Volume \u7684\u5177\u4f53\u5730\u5740\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f46\u662f Pod \u901a\u5e38\u662f\u7531\u5e94\u7528\u7684\u5f00\u53d1\u4eba\u5458\u7ef4\u62a4\uff0c\u800c Volume \u5219\u901a\u5e38\u662f\u7531\u5b58\u50a8\u7cfb\u7edf\u7684\u7ba1\u7406\u5458\u7ef4\u62a4\u3002\u5f00\u53d1\u4eba\u5458\u8981\u83b7\u5f97\u4e0a\u9762\u7684\u4fe1\u606f\uff0c\u8981\u4e48\u8be2\u95ee\u7ba1\u7406\u5458\uff0c\u8981\u4e48\u81ea\u5df1\u5c31\u662f\u7ba1\u7406\u5458\u3002\u8fd9\u6837\u5c31\u5e26\u6765\u4e00\u4e2a\u7ba1\u7406\u4e0a\u7684\u95ee\u9898\uff1a\u5e94\u7528\u5f00\u53d1\u4eba\u5458\u548c\u7cfb\u7edf\u7ba1\u7406\u5458\u7684\u804c\u8d23\u8026\u5408\u5728\u4e00\u8d77\u4e86\u3002\u5982\u679c\u7cfb\u7edf\u89c4\u6a21\u8f83\u5c0f\u6216\u8005\u5bf9\u4e8e\u5f00\u53d1\u73af\u5883\uff0c\u8fd9\u6837\u7684\u60c5\u51b5\u8fd8\u53ef\u4ee5\u63a5\u53d7\uff0c\u5f53\u96c6\u7fa4\u89c4\u6a21\u53d8\u5927\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u751f\u4ea7\u73af\u5883\uff0c\u8003\u8651\u5230\u6548\u7387\u548c\u5b89\u5168\u6027\uff0c\u8fd9\u5c31\u6210\u4e86\u5fc5\u987b\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>Kubernetes \u7ed9\u51fa\u7684\u89e3\u51b3\u65b9\u6848\u662f Persistent Volume \u548c Persistent Volume Claim\u3002<\/strong><\/p>\n<p>PersistentVolume(PV\uff09\u662f\u5916\u90e8\u5b58\u50a8\u7cfb\u7edf\u4e2d\u7684\u4e00\u5757\u5b58\u50a8\u7a7a\u95f4\uff0c\u7531\u7ba1\u7406\u5458\u521b\u5efa\u548c\u7ef4\u62a4\uff0c<strong>\u5c06\u5e94\u7528\u9700\u8981\u6301\u4e45\u5316\u7684\u6570\u636e\u4fdd\u5b58\u5230\u6307\u5b9a\u4f4d\u7f6e<\/strong>\u3002\u4e0e Volume \u4e00\u6837\uff0cPV \u5177\u6709\u6301\u4e45\u6027\uff0c\u751f\u547d\u5468\u671f\u72ec\u7acb\u4e8e Pod\u3002<\/p>\n<p>Persistent Volume Claim (PVC)\u662f\u5bf9 PV \u7684\u7533\u8bf7 (Claim\uff09\uff0c<strong>\u7533\u660e\u9700\u8981\u4f7f\u7528\u7684\u6301\u4e45\u5377\u89c4\u683c<\/strong>\u3002PVC \u901a\u5e38\u7531\u666e\u901a\u7528\u6237\u521b\u5efa\u548c\u7ef4\u62a4\u3002\u9700\u8981\u4e3a Pod \u5206\u914d\u5b58\u50a8\u8d44\u6e90\u65f6\uff0c\u7528\u6237\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aPVC\uff0c\u6307\u660e\u5b58\u50a8\u8d44\u6e90\u7684\u5bb9\u91cf\u5927\u5c0f\u548c\u8bbf\u95ee\u6a21\u5f0f \uff08\u6bd4\u5982\u53ea\u8bfb\uff09\u7b49\u4fe1\u606f\uff0cKubernetes \u4f1a\u67e5\u627e\u5e76\u63d0\u4f9b\u6ee1\u8db3\u6761\u4ef6\u7684 PV\u3002\u6709\u4e86 PersistentVolumeClaim\uff0c\u7528\u6237\u53ea\u9700\u8981\u544a\u8bc9 Kubernetes \u9700\u8981\u4ec0\u4e48\u6837\u7684\u5b58\u50a8\u8d44\u6e90\uff0c\u800c\u4e0d\u5fc5\u5173\u5fc3\u771f\u6b63\u7684\u7a7a\u95f4\u4ece\u54ea\u91cc\u5206\u914d\u3001\u5982\u4f55\u8bbf\u95ee\u7b49\u5e95\u5c42\u7ec6\u8282\u4fe1\u606f\u3002\u8fd9\u4e9b Storage Provider \u7684\u5e95\u5c42\u4fe1\u606f\u4ea4\u7ed9\u7ba1\u7406\u5458\u6765\u5904\u7406\uff0c\u53ea\u6709\u7ba1\u7406\u5458\u624d\u5e94\u8be5\u5173\u5fc3\u521b\u5efa PersistentVolume \u7684\u7ec6\u8282\u4fe1\u606f\u3002<\/p>\n<h5><strong>\u57fa\u672c\u4f7f\u7528<\/strong><\/h5>\n<p><strong>\u521b\u5efapv<\/strong><\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: nfs-pv\nspec:\n capacity:\n  storage: 1Gi #\u6307\u5b9a\u5bb9\u91cf\u5927\u5c0f\n accessModes: # \u8bbf\u95ee\u6a21\u5f0f \n  - ReadWriteMany\n persistentVolumeReclaimPolicy: Retain\n storageClassName: nfs\n nfs:\n  path: {nfs-server\u76ee\u5f55\u540d\u79f0}\n  server: {nfs-server IP \u5730\u5740}<\/code><\/pre>\n<ul>\n<li>\n<p>accessModes: \u652f\u6301\u7684\u8bbf\u95ee\u6a21\u5f0f\u67093\u79cd\uff1a<\/p>\n<ul>\n<li>eadWriteOnce \u8868\u793a PV \u80fd\u4ee5 readwrite \u6a21\u5f0f mount \u5230\u5355\u4e2a\u8282\u70b9<\/li>\n<li>\u8fd9\u4e2aPV\u53ea\u80fd\u88ab\u67d0\u4e2a\u8282\u70b9\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6302\u8f7d\uff0c\u610f\u5473\u7740\u8fd9\u4e2aPV\u53ea\u80fd\u88ab\u4e00\u4e2aPod\u6302\u8f7d\u5230\u67d0\u4e2a\u8282\u70b9\u4e0a\uff0c\u5e76\u4e14\u8fd9\u4e2aPod\u53ef\u4ee5\u5bf9\u8fd9\u4e2aPV\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\u3002\u5982\u679c\u5c1d\u8bd5\u5728\u5176\u4ed6\u8282\u70b9\u4e0a\u6302\u8f7d\u8fd9\u4e2aPV\uff0c\u5c31\u4f1a\u5931\u8d25\u3002<\/li>\n<li>ReadOnlyMany  \u8868\u793a PV \u80fd\u4ee5 read-only \u6a21\u5f0f mount \u5230\u591a\u4e2a\u8282\u70b9\uff0c<\/li>\n<li>\u8fd9\u4e2aPV\u80fd\u88ab\u591a\u4e2a\u8282\u70b9\u4ee5\u53ea\u8bfb\u65b9\u5f0f\u6302\u8f7d\uff0c\u610f\u5473\u7740\u8fd9\u4e2aPV\u53ef\u4ee5\u88ab\u591a\u4e2aPod\u6302\u8f7d\u5230\u591a\u4e2a\u8282\u70b9\u4e0a\u3002<\/li>\n<li>ReadWriteMany \u8868\u793a PV \u80fd\u4ee5 read-write \u6a21\u5f0f mount \u5230\u591a\u4e2a\u8282\u70b9\u3002<\/li>\n<li>\u8fd9\u4e2aPV\u80fd\u88ab\u591a\u4e2a\u8282\u70b9\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6302\u8f7d\uff0c\u610f\u5473\u7740\u8fd9\u4e2aPV\u53ef\u4ee5\u88ab\u591a\u4e2aPod\u6302\u8f7d\u5230\u591a\u4e2a\u8282\u70b9\u4e0a\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>persistentVolumeReclaimPolicy: \u6307\u5b9a\u5f53 PV \u7684\u56de\u6536\u7b56\u7565\u652f\u6301\u7684\u7b56\u7565\u67093\u79cd\uff1a<\/p>\n<ul>\n<li>Retain\uff1a\u5728 PVC \u88ab\u5220\u9664\u540e\uff0c\u4fdd\u7559 PV \u548c\u5176\u6570\u636e\uff0c\u624b\u52a8\u6e05\u7406 PV \u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li>Delete\uff1a\u5728 PVC \u88ab\u5220\u9664\u540e\uff0c\u81ea\u52a8\u5220\u9664 PV \u548c\u5176\u6570\u636e\u3002<\/li>\n<li>Recycle\uff1a\u5728 PVC \u88ab\u5220\u9664\u540e\uff0c\u901a\u8fc7\u5220\u9664 PV \u4e2d\u7684\u6570\u636e\u6765\u51c6\u5907 PV \u4ee5\u4f9b\u91cd\u65b0\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cpersistentVolumeReclaimPolicy\u53ea\u9002\u7528\u4e8e\u4e00\u4e9b\u7c7b\u578b\u7684 PV\uff0c\u5982 NFS\u3001HostPath\u3001iSCSI \u7b49\u3002\u5bf9\u4e8e\u4e00\u4e9b\u4e91\u5e73\u53f0\u63d0\u4f9b\u7684\u5b58\u50a8\uff0c\u5982 AWS EBS \u548c Azure Disk\uff0c\u7531\u4e8e\u5e95\u5c42\u63d0\u4f9b\u5546\u4f1a\u81ea\u52a8\u5904\u7406 PV \u7684\u56de\u6536\u95ee\u9898\uff0c\u56e0\u6b64\u8be5\u5c5e\u6027\u4e0d\u9002\u7528\u3002<\/p>\n<ul>\n<li>storageClassName: \u6307\u5b9a PV \u7684class \u4e3a nfs\u3002\u76f8\u5f53\u4e8e\u4e3a PV \u8bbe\u7f6e\u4e86\u4e00\u4e2a\u5206\u7c7b\uff0cPVC\u53ef\u4ee5\u6307\u5b9a class \u7533\u8bf7\u76f8\u5e94 class \u7684 PV\u3002<\/li>\n<\/ul>\n<p><strong>\u521b\u5efapvc<\/strong><\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n name: nfs-pvc\nspec:\n accessModes:\n  - ReadWriteMany\n resources:\n  requests:\n   storage: 1Gi\n storageClassName: nfs # \u901a\u8fc7\u540d\u5b57\u8fdb\u884c\u9009\u62e9\n #selector:  \u901a\u8fc7\u6807\u7b7e\u5f62\u5f0f\n #  matchLabels:\n #   pv-name: nfs-pv<\/code><\/pre>\n<h5><strong>\u9759\u6001\u4f9b\u5e94\u793a\u4f8b<\/strong><\/h5>\n<p><strong>\u521b\u5efaPV\u6c60<\/strong><\/p>\n<pre><code class=\"language-shell\">#nfs\u4e3b\u8282\u70b9\nmkdir -p \/nfs\/data\/01\nmkdir -p \/nfs\/data\/02\nmkdir -p \/nfs\/data\/03<\/code><\/pre>\n<p><strong>\u521b\u5efaPV<\/strong><\/p>\n<pre><code>apiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: pv01-10m\nspec:\n capacity:\n  storage: 10M  \n accessModes:  \n  - ReadWriteMany\n storageClassName: nfs\n nfs:\n  path: \/nfs\/data\/01\n  server: 192.168.11.101\n---\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: pv02-1gi\nspec:\n capacity:\n  storage: 1Gi\n accessModes:\n  - ReadWriteMany \n storageClassName: nfs\n nfs:\n  path: \/nfs\/data\/02\n  server: 192.168.11.101\n---\napiVersion: v1\nkind: PersistentVolume\nmetadata:\n name: pv03-3gi\nspec:\n capacity:\n  storage: 3Gi\n accessModes:\n  - ReadWriteMany\n storageClassName: nfs\n nfs:\n  path: \/nfs\/data\/03\n  server: 192.168.11.101<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps28.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u521b\u5efaPVC<\/strong><\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n name: nginx-pvc\nspec:\n accessModes:\n  - ReadWriteMany\n resources:\n  requests:\n   storage: 200Mi\n storageClassName: nfs<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps29.jpg\" alt=\"img\" \/> <\/p>\n<p><strong>\u521b\u5efaPod\u7ed1\u5b9aPVC<\/strong><\/p>\n<pre><code class=\"language-yaml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n labels:\n  app: nginx-deploy-pvc\n name: nginx-deploy-pvc\nspec:\n replicas: 2\n selector:\n  matchLabels:\n   app: nginx-deploy-pvc\n template:\n  metadata:\n   labels:\n     app: nginx-deploy-pvc\n  spec:\n   containers:\n   - image: nginx\n     name: nginx\n     volumeMounts:\n     - name: html\n      mountPath: \/usr\/share\/nginx\/html\n   volumes:\n     - name: html\n      persistentVolumeClaim:\n        claimName: nginx-pvc<\/code><\/pre>\n<h5><strong>\u52a8\u6001\u4f9b\u5e94<\/strong><\/h5>\n<p>\u5728\u524d\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u63d0\u524d\u521b\u5efa\u4e86PV\uff0c\u7136\u540e\u901a\u8fc7 PVC \u7533\u8bf7 PV \u5e76\u5728Pod \u4e2d\u4f7f\u7528\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53eb\u4f5c\u9759\u6001\u4f9b\u5e94 ( Static Provision)\u4e0e\u4e4b\u5bf9\u5e94\u7684\u662f\u52a8\u6001\u4f9b\u5e94 (Dynamical Provision\uff09\uff0c\u5373\u5982\u679c\u6ca1\u6709\u6ee1\u8db3PVC \u6761\u4ef6\u7684PV\uff0c\u4f1a\u52a8\u6001\u521b\u5efa PV\u3002\u76f8\u6bd4\u9759\u6001\u4f9b\u5e94\uff0c\u52a8\u6001\u4f9b\u5e94\u6709\u660e\u663e\u7684\u4f18\u52bf\uff1a\u4e0d\u9700\u8981\u63d0\u524d\u521b\u5efa PV\uff0c\u51cf\u5c11\u4e86\u7ba1\u7406\u5458\u7684\u5de5\u4f5c\u91cf\uff0c\u6548\u7387\u9ad8\u3002\u52a8\u6001\u4f9b\u5e94\u662f\u901a\u8fc7<a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/storage\/storage-classes\/\"> StorageClass<\/a> \u5b9e\u73b0\u7684\uff0cStorageClass \u5b9a\u4e49\u4e86\u5982\u4f55\u521b\u5efa PV\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\u6bcf\u4e2a StorageClass \u90fd\u6709\u4e00\u4e2a\u5236\u5907\u5668\uff08Provisioner\uff09\uff0c\u7528\u6765\u51b3\u5b9a\u4f7f\u7528\u54ea\u4e2a\u5377\u63d2\u4ef6\u5236\u5907 PV\uff0c \u8be5\u5b57\u6bb5\u5fc5\u987b\u6307\u5b9a\u624d\u80fd\u5b9e\u73b0\u52a8\u6001\u521b\u5efa\u3002<\/p>\n<p>\u914d\u7f6e\u52a8\u6001\u4f9b\u5e94\u7684\u9ed8\u8ba4\u5b58\u50a8\u7c7b<\/p>\n<pre><code class=\"language-yaml\">## \u521b\u5efa\u4e86\u4e00\u4e2a\u5b58\u50a8\u7c7b\napiVersion: storage.k8s.io\/v1\nkind: StorageClass\nmetadata:\n name: nfs-storage\n annotations:\n  storageclass.kubernetes.io\/is-default-class: &quot;true&quot;\nprovisioner: k8s-sigs.io\/nfs-subdir-external-provisioner\nparameters:\n archiveOnDelete: &quot;true&quot;  ## \u5220\u9664pv\u7684\u65f6\u5019\uff0cpv\u7684\u5185\u5bb9\u662f\u5426\u8981\u5907\u4efd \n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n name: nfs-client-provisioner\n labels:\n  app: nfs-client-provisioner\n # replace with namespace where provisioner is deployed\n namespace: default\nspec:\n replicas: 1\n strategy:\n  type: Recreate\n selector:\n  matchLabels:\n   app: nfs-client-provisioner\n template:\n  metadata:\n   labels:\n     app: nfs-client-provisioner\n  spec:\n   serviceAccountName: nfs-client-provisioner\n   containers:\n     - name: nfs-client-provisioner\n      image: registry.cn-hangzhou.aliyuncs.com\/lfy_k8s_images\/nfs-subdir-external-provisioner:v4.0.2\n      # resources:\n      #   limits:\n      #    cpu: 10m\n      #   requests:\n      #    cpu: 10m\n      volumeMounts:\n       - name: nfs-client-root\n        mountPath: \/persistentvolumes\n      env:\n       - name: PROVISIONER_NAME\n        value: k8s-sigs.io\/nfs-subdir-external-provisioner\n       - name: NFS_SERVER\n        value: 192.168.11.101 ## \u6307\u5b9a\u81ea\u5df1nfs\u670d\u52a1\u5668\u5730\u5740\n       - name: NFS_PATH  \n        value: \/nfs\/data  ## nfs\u670d\u52a1\u5668\u5171\u4eab\u7684\u76ee\u5f55\n   volumes:\n     - name: nfs-client-root\n      nfs:\n       server: 192.168.11.101\n       path: \/nfs\/data\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n name: nfs-client-provisioner\n # replace with namespace where provisioner is deployed\n namespace: default\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n name: nfs-client-provisioner-runner\nrules:\n - apiGroups: [&quot;&quot;]\n  resources: [&quot;nodes&quot;]\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;]\n - apiGroups: [&quot;&quot;]\n  resources: [&quot;persistentvolumes&quot;]\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;create&quot;, &quot;delete&quot;]\n - apiGroups: [&quot;&quot;]\n  resources: [&quot;persistentvolumeclaims&quot;]\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;update&quot;]\n - apiGroups: [&quot;storage.k8s.io&quot;]\n  resources: [&quot;storageclasses&quot;]\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;]\n - apiGroups: [&quot;&quot;]\n  resources: [&quot;events&quot;]\n  verbs: [&quot;create&quot;, &quot;update&quot;, &quot;patch&quot;]\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n name: run-nfs-client-provisioner\nsubjects:\n - kind: ServiceAccount\n  name: nfs-client-provisioner\n  # replace with namespace where provisioner is deployed\n  namespace: default\nroleRef:\n kind: ClusterRole\n name: nfs-client-provisioner-runner\n apiGroup: rbac.authorization.k8s.io\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: Role\nmetadata:\n name: leader-locking-nfs-client-provisioner\n # replace with namespace where provisioner is deployed\n namespace: default\nrules:\n - apiGroups: [&quot;&quot;]\n  resources: [&quot;endpoints&quot;]\n  verbs: [&quot;get&quot;, &quot;list&quot;, &quot;watch&quot;, &quot;create&quot;, &quot;update&quot;, &quot;patch&quot;]\n---\napiVersion: rbac.authorization.k8s.io\/v1\nkind: RoleBinding\nmetadata:\n name: leader-locking-nfs-client-provisioner\n # replace with namespace where provisioner is deployed\n namespace: default\nsubjects:\n - kind: ServiceAccount\n  name: nfs-client-provisioner\n  # replace with namespace where provisioner is deployed\n  namespace: default\nroleRef:\n kind: Role\n name: leader-locking-nfs-client-provisioner\n apiGroup: rbac.authorization.k8s.io <\/code><\/pre>\n<h3><strong>2.7 \u914d\u7f6e<\/strong><\/h3>\n<h4><strong>ConfigMap<\/strong><\/h4>\n<p>\u5728 Kubernetes \u4e2d\uff0c<strong>ConfigMap \u662f\u4e00\u79cd\u7528\u4e8e\u5b58\u50a8\u975e\u654f\u611f\u4fe1\u606f\u7684 Kubernetes \u5bf9\u8c61<\/strong>\u3002\u5b83\u7528\u4e8e\u5b58\u50a8\u914d\u7f6e\u6570\u636e\uff0c\u5982\u952e\u503c\u5bf9\u3001\u6574\u4e2a\u914d\u7f6e\u6587\u4ef6\u6216 JSON \u6570\u636e\u7b49\u3002ConfigMap \u901a\u5e38\u7528\u4e8e\u5bb9\u5668\u955c\u50cf\u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u3001\u547d\u4ee4\u884c\u53c2\u6570\u548c\u73af\u5883\u53d8\u91cf\u7b49\u3002<\/p>\n<p>ConfigMap \u53ef\u4ee5\u901a\u8fc7\u4e09\u79cd\u65b9\u5f0f\u8fdb\u884c\u914d\u7f6e\u6570\u636e\u7684\u6ce8\u5165\uff1a<\/p>\n<p>\u73af\u5883\u53d8\u91cf\u6ce8\u5165\uff1a\u5c06\u914d\u7f6e\u6570\u636e\u6ce8\u5165\u5230 Pod \u4e2d\u7684\u5bb9\u5668\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n<p>\u914d\u7f6e\u6587\u4ef6\u6ce8\u5165\uff1a\u5c06\u914d\u7f6e\u6570\u636e\u6ce8\u5165\u5230 Pod \u4e2d\u7684\u5bb9\u5668\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u5bb9\u5668\u53ef\u4ee5\u8bfb\u53d6\u8fd9\u4e9b\u6587\u4ef6\u3002<\/p>\n<p>\u547d\u4ee4\u884c\u53c2\u6570\u6ce8\u5165\uff1a\u5c06\u914d\u7f6e\u6570\u636e\u6ce8\u5165\u5230\u5bb9\u5668\u7684\u547d\u4ee4\u884c\u53c2\u6570\u4e2d\u3002<\/p>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<p>\u907f\u514d\u4e86\u786c\u7f16\u7801\uff0c\u5c06\u914d\u7f6e\u6570\u636e\u4e0e\u5e94\u7528\u4ee3\u7801\u5206\u79bb\u3002<\/p>\n<p>\u4fbf\u4e8e\u7ef4\u62a4\u548c\u66f4\u65b0\uff0c\u53ef\u4ee5\u5355\u72ec\u4fee\u6539 ConfigMap \u800c\u4e0d\u9700\u8981\u91cd\u65b0\u6784\u5efa\u955c\u50cf\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u6ce8\u5165\u914d\u7f6e\u6570\u636e\uff0c\u66f4\u52a0\u7075\u6d3b\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 Kubernetes \u7684\u81ea\u52a8\u5316\u673a\u5236\u5bf9 ConfigMap \u8fdb\u884c\u7248\u672c\u63a7\u5236\u548c\u56de\u6eda\u3002<\/p>\n<p>ConfigMap \u53ef\u4ee5\u88ab\u591a\u4e2a Pod \u5171\u4eab\uff0c\u51cf\u5c11\u4e86\u914d\u7f6e\u6570\u636e\u7684\u91cd\u590d\u5b58\u50a8\u3002 <\/p>\n<h5><strong>\u5b9a\u4e49 ConfigMap<\/strong><\/h5>\n<ul>\n<li>\u57fa\u672c\u64cd\u4f5c<\/li>\n<\/ul>\n<pre><code class=\"language-shell\"># \u67e5\u770b configmap\n$ kubectl get configmap\/cm  \n# \u67e5\u770b\u8be6\u7ec6\n$ kubectl describe configmap\/cm my-config\n# \u5220\u9664 cm\n$ kubectl delete cm my-config<\/code><\/pre>\n<ul>\n<li>\u547d\u4ee4\u884c\u521b\u5efa\uff1a\n<ul>\n<li>\u53ef\u4ee5\u4f7f\u7528kubectl create configmap\u547d\u4ee4\u6765\u521b\u5efaconfigmap\uff0c\u5177\u4f53\u547d\u4ee4\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code> kubectl create configmap my-config --from-literal=key1=value1 --from-literal=key2=value2<\/code><\/pre>\n<ul>\n<li>\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u521b\u5efa\uff1a<strong>\u63a8\u8350<\/strong>\n<ul>\n<li>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efaYAML\u6587\u4ef6\u7684\u65b9\u5f0f\u6765\u5b9a\u4e49configmap\u7684\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amy-config\u7684configmap\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/li>\n<li>\u7136\u540e\u4f7f\u7528kubectl apply -f\u547d\u4ee4\u6765\u521b\u5efaconfigmap\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: my-config\ndata:\n key1: value1\n key2: value2\n---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: app-config\ndata:\n application.yml: |\n   name: fox<\/code><\/pre>\n<ul>\n<li>\u901a\u8fc7\u6587\u4ef6\u521b\u5efa:<\/li>\n<\/ul>\n<pre><code class=\"language-shell\">echo-n admin &gt;.\/username\necho -n 123456 &gt; .\/password\nkubectl create configmap myconfigmap --from-file=.\/username --from-file=.\/password<\/code><\/pre>\n<ul>\n<li>\n<p>\u901a\u8fc7\u6587\u4ef6\u5939\u521b\u5efa\uff1a<\/p>\n<ul>\n<li>\u53ef\u4ee5\u5c06\u591a\u4e2a\u914d\u7f6e\u6587\u4ef6\u653e\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u5939\u4e0b\uff0c\u7136\u540e\u4f7f\u7528kubectl create configmap\u547d\u4ee4\u6765\u521b\u5efaconfigmap\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-shell\"> kubectl create configmap my-config --from-file=config-files\/<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amy-config\u7684configmap\uff0c\u5176\u4e2d\u5305\u542bconfig-files\/\u6587\u4ef6\u5939\u4e0b\u6240\u6709\u7684\u6587\u4ef6\u5185\u5bb9\u4f5c\u4e3a\u952e\u503c\u5bf9\u3002<\/p>\n<ul>\n<li>\n<p>\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u521b\u5efa\uff1a<\/p>\n<ul>\n<li>\u53ef\u4ee5\u5c06\u73af\u5883\u53d8\u91cf\u7684\u503c\u8f6c\u6362\u4e3aconfigmap\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5f53\u524d\u73af\u5883\u53d8\u91cf\u7684\u503c\u8f6c\u6362\u4e3aconfigmap\uff1a<\/li>\n<\/ul>\n<pre><code> kubectl create configmap my-config --from-env-file=<env><\/code><\/pre>\n<\/li>\n<\/ul>\n<h5><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/h5>\n<pre><code class=\"language-shell\"># docker\u5b89\u88c5redis \ndocker run -v \/data\/redis\/redis.conf:\/etc\/redis\/redis.conf \\\n-v \/data\/redis\/data:\/data \\\n-d --name myredis \\\n-p 6379:6379 \\\nredis:latest  redis-server \/etc\/redis\/redis.conf<\/code><\/pre>\n<p><strong>\u521b\u5efaConfigMap<\/strong><\/p>\n<p>\u901a\u8fc7\u6587\u4ef6\u7684\u65b9\u5f0f\u521b\u5efa<\/p>\n<pre><code class=\"language-shell\">#\u521b\u5efaredis.conf\ndaemonize yes\nrequirepass root\n# \u521b\u5efa\u914d\u7f6e\uff0credis\u4fdd\u5b58\u5230k8s\u7684etcd\nkubectl create cm redis-conf --from-file=redis.conf\n#\u67e5\u770b\u8d44\u6e90\u6e05\u5355\nkubectl get cm redis-conf -oyaml<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps30.jpg\" alt=\"img\" \/> <\/p>\n<p>\u901a\u8fc7yaml\u7684\u65b9\u5f0f\u521b\u5efa<\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: redis-conf\ndata:\n redis.conf: |\n  maxmemory-policy allkeys-lru   \n  requirepass root<\/code><\/pre>\n<p><strong>\u521b\u5efaPod<\/strong><\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: Pod\nmetadata:\n name: redis\nspec:\n containers:\n - name: redis\n  image: redis\n  command:\n   - redis-server\n   - &quot;\/redis-master\/redis.conf&quot;  #\u6307\u7684\u662fredis\u5bb9\u5668\u5185\u90e8\u7684\u4f4d\u7f6e\n  ports:\n  - containerPort: 6379\n  volumeMounts:\n  - mountPath: \/data\n   name: data\n  - mountPath: \/redis-master\n   name: config\n volumes:\n  - name: data\n   emptyDir: {}\n  - name: confi\n   configMap:\n     name: redis-conf\n     items:\n     - key: redis.conf\n      path: redis.conf<\/code><\/pre>\n<p><strong>\u6d4b\u8bd5<\/strong><\/p>\n<pre><code>kubectl exec -it redis -- redis-cli\n127.0.0.1:6379&gt; config get  maxmemory-policy<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps31.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>Secret<\/strong><\/h4>\n<p>Secret \u5bf9\u8c61\u7c7b\u578b\u7528\u6765\u4fdd\u5b58\u654f\u611f\u4fe1\u606f\uff0c\u4f8b\u5982\u5bc6\u7801\u3001OAuth \u4ee4\u724c\u548c SSH \u5bc6\u94a5\u3002 \u5c06\u8fd9\u4e9b\u4fe1\u606f\u653e\u5728 secret \u4e2d\u6bd4\u653e\u5728 <a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-overview\/\">Pod<\/a> \u7684\u5b9a\u4e49\u6216\u8005 <a href=\"https:\/\/kubernetes.io\/zh\/docs\/reference\/glossary\/?all=true#term-image\">\u5bb9\u5668\u955c\u50cf<\/a> \u4e2d\u6765\u8bf4\u66f4\u52a0\u5b89\u5168\u548c\u7075\u6d3b\u3002<\/p>\n<p>\u5728 Kubernetes \u4e2d\uff0cSecrets \u901a\u5e38\u88ab\u7528\u4e8e\u4ee5\u4e0b\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\n<p>\u4f5c\u4e3a\u5377\u6302\u8f7d\u5230 Pod \u4e2d\uff0c\u7528\u4e8e\u5b58\u50a8\u8bc1\u4e66\u3001\u5bc6\u94a5\u7b49\u654f\u611f\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u5728 Pod \u4e2d\u4f7f\u7528\u73af\u5883\u53d8\u91cf\uff0c\u7528\u4e8e\u5b58\u50a8\u7528\u6237\u540d\u548c\u5bc6\u7801\u7b49\u654f\u611f\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>\u7528\u4e8e\u5b58\u50a8 Docker \u955c\u50cf\u4ed3\u5e93\u7684\u767b\u5f55\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>\u7528\u4e8e\u5b58\u50a8\u5916\u90e8\u670d\u52a1\u7684 API \u5bc6\u94a5<\/p>\n<\/li>\n<\/ul>\n<h5><strong>\u5b9a\u4e49 Secret<\/strong><\/h5>\n<ul>\n<li>\u4f7f\u7528\u547d\u4ee4\u884c\u521b\u5efa\uff1a\n<ul>\n<li>\u53ef\u4ee5\u4f7f\u7528 kubectl create secret \u547d\u4ee4\u6765\u521b\u5efa secret\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code>kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=admin123<\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528 YAML \u6587\u4ef6\u5b9a\u4e49\uff1a\n<ul>\n<li>\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a YAML \u6587\u4ef6\u6765\u5b9a\u4e49 Secret \u5bf9\u8c61\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: Secret\nmetadata:\n name: my-secret\ntype: Opaque\ndata:\n username: YWRtaW4= # base64 \u7f16\u7801\u540e\u7684\u7528\u6237\u540d admin\n password: MWYyZDFlMmU2N2Rm # base64 \u7f16\u7801\u540e\u7684\u5bc6\u7801 1f2d1e2e67df<\/code><\/pre>\n<p>\u6ce8\u610f: \u8fd9\u4e2a YAML \u6587\u4ef6\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a my-secret \u7684 Secret \u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u4e24\u4e2a base64 \u7f16\u7801\u540e\u7684 key-value \u5bf9\uff1ausername \u548c password\u3002<\/p>\n<ul>\n<li>\u4f7f\u7528\u6587\u4ef6\u521b\u5efa:<\/li>\n<\/ul>\n<pre><code>echo -n admin &gt;.\/username\necho -n 123456 &gt; .\/password\nkubectl create secret generic mysecret --from-file=.\/username --from-file=.\/password<\/code><\/pre>\n<ul>\n<li>\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u521b\u5efa\uff1a\n<ul>\n<li>\u53ef\u4ee5\u5c06\u73af\u5883\u53d8\u91cf\u7684\u503c\u8f6c\u6362\u4e3asecret\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5f53\u524d\u73af\u5883\u53d8\u91cf\u7684\u503c\u8f6c\u6362\u4e3asecret\uff1a<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code>kubectl create secret generic  my-config --from-env-file=&lt;env&gt;<\/code><\/pre>\n<h5><strong>\u4f7f\u7528\u793a\u4f8b\uff1a\u4ece\u79c1\u6709docker\u4ed3\u5e93\u62c9\u53d6\u955c\u50cf<\/strong><\/h5>\n<pre><code>docker pull registry.cn-hangzhou.aliyuncs.com\/fox666\/tulingmall-product:0.0.5<\/code><\/pre>\n<p>\u65e0\u6cd5\u4ece\u79c1\u6709\u955c\u50cf\u4ed3\u5e93\u62c9\u53d6\u955c\u50cf\uff0c\u629b\u51fa\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps32.jpg\" alt=\"img\" \/> <\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u4f7f\u7528 docker \u7684\u7528\u6237\u4fe1\u606f\u6765\u751f\u6210 secret\uff1a<\/p>\n<pre><code class=\"language-bash\">##\u547d\u4ee4\u683c\u5f0f\nkubectl create secret docker-registry myregistrykey \\\n --docker-server=&lt;\u4f60\u7684\u955c\u50cf\u4ed3\u5e93\u670d\u52a1\u5668&gt; \\\n --docker-username=&lt;\u4f60\u7684\u7528\u6237\u540d&gt; \\\n --docker-password=&lt;\u4f60\u7684\u5bc6\u7801&gt; \\\n --docker-email=&lt;\u4f60\u7684\u90ae\u7bb1\u5730\u5740&gt;\n kubectl create secret docker-registry myregistrykey --docker-server=registry.cn-hangzhou.aliyuncs.com --docker-username=fox666 --docker-password=xxx<\/code><\/pre>\n<p>\u5728\u521b\u5efa Pod \u7684\u65f6\u5019\uff0c\u901a\u8fc7imagePullSecrets\u6765\u5f15\u7528\u521a\u521b\u5efa\u7684myregistrykey<\/p>\n<pre><code class=\"language-yaml\">apiVersion: v1\nkind: Pod\nmetadata:\n name: tulingmall-product\nspec:   \n containers:\n - name: tulingmall-product\n  image: registry.cn-hangzhou.aliyuncs.com\/fox666\/tulingmall-product:0.0.5\n imagePullSecrets:\n - name: myregistrykey   <\/code><\/pre>\n<h3><strong>2.8 Ingress<\/strong><\/h3>\n<p><a href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/services-networking\/ingress\/\"><strong>Ingress<\/strong><\/a> <strong>\u662f\u4e00\u79cd Kubernetes \u8d44\u6e90\u7c7b\u578b\uff0c\u5b83\u5141\u8bb8\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u66b4\u9732 HTTP \u548c HTTPS \u670d\u52a1<\/strong>\u3002\u901a\u8fc7 Ingress\uff0c\u60a8\u53ef\u4ee5\u5c06\u6d41\u91cf\u8def\u7531\u5230\u4e0d\u540c\u7684\u670d\u52a1\u548c\u7aef\u70b9\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u4e0d\u540c\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u3002Ingress \u901a\u5e38\u4f7f\u7528 Ingress Controller \u5b9e\u73b0\uff0c\u5b83\u662f\u4e00\u4e2a\u8fd0\u884c\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u5b83\u6839\u636eIngress \u89c4\u5219\u914d\u7f6e\u8def\u7531\u89c4\u5219\u5e76\u5c06\u6d41\u91cf\u8f6c\u53d1\u5230\u76f8\u5e94\u7684\u670d\u52a1\u3002<\/p>\n<h4><strong>Ingress \u548c Service \u533a\u522b<\/strong><\/h4>\n<p>Ingress \u548c Service\u90fd\u662f Kubernetes \u4e2d\u7528\u4e8e\u5c06\u6d41\u91cf\u8def\u7531\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u673a\u5236\uff0c\u4f46\u5b83\u4eec\u5728\u8def\u7531\u5c42\u9762\u4e0a\u6709\u6240\u4e0d\u540c\uff1a<\/p>\n<p>Service \u662f Kubernetes \u4e2d\u62bd\u8c61\u7684\u5e94\u7528\u7a0b\u5e8f\u670d\u52a1\uff0c\u5b83\u516c\u5f00\u4e86\u4e00\u4e2a\u5355\u4e00\u7684IP\u5730\u5740\u548c\u7aef\u53e3\uff0c\u53ef\u4ee5\u7528\u4e8e\u5728 Kubernetes \u96c6\u7fa4\u5185\u90e8\u7684 Pod \u4e4b\u95f4\u8fdb\u884c\u6d41\u91cf\u8def\u7531\u3002<\/p>\n<p>Ingress \u662f\u4e00\u4e2a Kubernetes \u8d44\u6e90\u5bf9\u8c61\uff0c\u5b83\u63d0\u4f9b\u4e86\u5bf9\u96c6\u7fa4\u5916\u90e8\u6d41\u91cf\u8def\u7531\u7684\u89c4\u5219\u3002Ingress \u901a\u8fc7\u4e00\u4e2a\u516c\u5171IP\u5730\u5740\u548c\u7aef\u53e3\u5c06\u6d41\u91cf\u8def\u7531\u5230\u4e00\u4e2a\u6216\u591a\u4e2aService\u3002<\/p>\n<h4><strong>\u5b89\u88c5Ingress<\/strong><\/h4>\n<p>1\uff09\u4e0b\u8f7dingress\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>wget https:\/\/raw.githubusercontent.com\/kubernetes\/ingress-nginx\/controller-v0.47.0\/deploy\/static\/provider\/baremetal\/deploy.yaml\n[root@k8s-master k8s]# grep image: deploy.yaml \n     image: k8s.gcr.io\/ingress-nginx\/controller:v0.46.0@sha256:52f0058bed0a17ab0fb35628ba97e8d52b5d32299fbc03cc0f6c7b9ff036b61a\n     image: docker.io\/jettech\/kube-webhook-certgen:v1.5.1\n     image: docker.io\/jettech\/kube-webhook-certgen:v1.5.1\n#\u4fee\u6539\u955c\u50cf\nvi deploy.yaml\n#1\u3001\u5c06image k8s.gcr.io\/ingress-nginx\/controller:v0.46.0@sha256:52f0058bed0a17ab0fb35628ba97e8d52b5d32299fbc03cc0f6c7b9ff036b61a\u7684\u503c\u6539\u4e3a\u5982\u4e0b\u503c\uff1a\nregistry.cn-hangzhou.aliyuncs.com\/lfy_k8s_images\/ingress-nginx-controller:v0.46.0<\/code><\/pre>\n<p>2\uff09\u5b89\u88c5ingress\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4<\/p>\n<pre><code>kubectl apply -f ingress-controller.yaml <\/code><\/pre>\n<p>3)\u67e5\u770b\u662f\u5426\u5b89\u88c5\u6210\u529f<\/p>\n<pre><code>kubectl get pod,svc -n ingress-nginx -owide<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps34.jpg\" alt=\"img\" \/> <\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps35.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u4f7f\u7528Ingress<\/strong><\/h4>\n<p>\u5b98\u7f51\u5730\u5740\uff1a<a href=\"https:\/\/kubernetes.github.io\/ingress-nginx\/\">https:\/\/kubernetes.github.io\/ingress-nginx\/<\/a><\/p>\n<p>\u914d\u7f6eingress\u8bbf\u95ee\u89c4\u5219\uff08\u5c31\u662f\u7c7b\u4f3c\u914d\u7f6enginx\u7684\u4ee3\u7406\u8f6c\u53d1\u914d\u7f6e\uff09\uff0c\u8ba9ingress\u5c06\u57df\u540dtomcat.tuling.com\u8f6c\u53d1\u7ed9\u540e\u7aef\u7684my-tomcat\u670d\u52a1\uff0c\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6ingress-tomcat.yaml\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-yaml\">apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\n name: web-ingress\nspec:\n rules:\n - host: tomcat.tuling.com  #\u8f6c\u53d1\u57df\u540d\n  http:\n   paths:\n   - pathType: Prefix\n     path: \/\n     backend:\n      service:\n       name: my-tomcat\n       port: \n        number: 8080  #service\u7684\u7aef\u53e3<\/code><\/pre>\n<p>\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u751f\u6548\u89c4\u5219\uff1a<\/p>\n<pre><code>kubectl apply -f ingress-tomcat.yaml <\/code><\/pre>\n<p>\u67e5\u770b\u751f\u6548\u7684ingress\u89c4\u5219\uff1a<\/p>\n<pre><code>kubectl get ing<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps36.jpg\" alt=\"img\" \/> <\/p>\n<p>\u5728\u8bbf\u95ee\u673a\u5668\u914d\u7f6ehost\uff0cwin10\u5ba2\u6237\u673a\u5728\u76ee\u5f55\uff1aC:\\Windows\\System32\\drivers\\etc\uff0c\u5728host\u91cc\u589e\u52a0\u5982\u4e0bhost(ingress\u90e8\u7f72\u7684\u673a\u5668ip\u5bf9\u5e94\u8bbf\u95ee\u7684\u57df\u540d)<\/p>\n<pre><code>192.168.65.82  tomcat.tuling.com<\/code><\/pre>\n<p>\u914d\u7f6e\u5b8c\u540e\u76f4\u63a5\u5728\u5ba2\u6237\u673a\u6d4f\u89c8\u5668\u8bbf\u95eehttp:\/\/tomcat.tuling.com:30940\u80fd\u6b63\u5e38\u8bbf\u95eetomcat\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps37.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>Service&amp;Ingress\u603b\u7ed3<\/strong><\/h4>\n<p><strong>Service \u662f K8S \u670d\u52a1\u7684\u6838\u5fc3\uff0c\u5c4f\u853d\u4e86\u670d\u52a1\u7ec6\u8282\uff0c\u7edf\u4e00\u5bf9\u5916\u66b4\u9732\u670d\u52a1\u63a5\u53e3\uff0c\u771f\u6b63\u505a\u5230\u4e86\u201c\u5fae\u670d\u52a1\u201d<\/strong>\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u7684\u4e00\u4e2a\u670d\u52a1 A\uff0c\u90e8\u7f72\u4e86 3 \u4e2a\u5907\u4efd\uff0c\u4e5f\u5c31\u662f 3 \u4e2a Pod\uff1b\u5bf9\u4e8e\u7528\u6237\u6765\u8bf4\uff0c\u53ea\u9700\u8981\u5173\u6ce8\u4e00\u4e2a Service \u7684\u5165\u53e3\u5c31\u53ef\u4ee5\uff0c\u800c\u4e0d\u9700\u8981\u64cd\u5fc3\u7a76\u7adf\u5e94\u8be5\u8bf7\u6c42\u54ea\u4e00\u4e2a Pod\u3002\u4f18\u52bf\u975e\u5e38\u660e\u663e\uff1a<strong>\u4e00\u65b9\u9762\u5916\u90e8\u7528\u6237\u4e0d\u9700\u8981\u611f\u77e5\u56e0\u4e3a Pod \u4e0a\u670d\u52a1\u7684\u610f\u5916\u5d29\u6e83\u3001K8S \u91cd\u65b0\u62c9\u8d77 Pod \u800c\u9020\u6210\u7684 IP \u53d8\u66f4\uff0c\u5916\u90e8\u7528\u6237\u4e5f\u4e0d\u9700\u8981\u611f\u77e5\u56e0\u5347\u7ea7\u3001\u53d8\u66f4\u670d\u52a1\u5e26\u6765\u7684 Pod \u66ff\u6362\u800c\u9020\u6210\u7684 IP \u53d8\u5316\uff0c\u53e6\u4e00\u65b9\u9762\uff0cService \u8fd8\u53ef\u4ee5\u505a\u6d41\u91cf\u8d1f\u8f7d\u5747\u8861<\/strong>\u3002<\/p>\n<p>\u4f46\u662f\uff0cService \u4e3b\u8981\u8d1f\u8d23 K8S \u96c6\u7fa4<strong>\u5185\u90e8\u7684\u7f51\u7edc\u62d3\u6251<\/strong>\u3002\u96c6\u7fa4\u5916\u90e8\u9700\u8981\u7528 Ingress \u3002<\/p>\n<p>Ingress \u662f\u6574\u4e2a K8S \u96c6\u7fa4\u7684\u63a5\u5165\u5c42\uff0c\u590d\u6742\u96c6\u7fa4\u5185\u5916\u901a\u8baf\u3002<\/p>\n<p>Ingress \u548c Service \u7684\u7f51\u7edc\u62d3\u6251\u5173\u7cfb\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps38.jpg\" alt=\"img\" \/> <\/p>\n<h2><strong>3. K8S\u6838\u5fc3\u539f\u7406<\/strong><\/h2>\n<h3><strong>3.1 K8S\u7684\u7f51\u7edc\u6a21\u578b<\/strong><\/h3>\n<p>K8S\u7684\u7f51\u7edc\u4e2d\u4e3b\u8981\u5b58\u57284\u79cd\u7c7b\u578b\u7684\u901a\u4fe1\uff1a<\/p>\n<ul>\n<li>\n<p>\u540c\u4e00Pod\u5185\u7684\u5bb9\u5668\u95f4\u901a\u4fe1<\/p>\n<\/li>\n<li>\n<p>\u5404\u4e2aPod\u5f7c\u6b64\u95f4\u7684\u901a\u4fe1<\/p>\n<\/li>\n<li>\n<p>Pod\u548cService\u95f4\u7684\u901a\u4fe1<\/p>\n<\/li>\n<li>\n<p>\u96c6\u7fa4\u5916\u90e8\u6d41\u91cf\u548cService\u4e4b\u95f4\u7684\u901a\u4fe1<\/p>\n<\/li>\n<\/ul>\n<p>K8S\u4e3aPod\u548cService\u8d44\u6e90\u5bf9\u8c61\u5206\u522b\u4f7f\u7528\u4e86\u5404\u81ea\u7684\u4e13\u6709\u7f51\u7edc\uff0cPod\u7f51\u7edc\u7531K8S\u7684\u7f51\u7edc\u63d2\u4ef6\u914d\u7f6e\u5b9e\u73b0\uff0c\u800cService\u7f51\u7edc\u5219\u7531K8S\u96c6\u7fa4\u8fdb\u884c\u6307\u5b9a\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps39.jpg\" alt=\"img\" \/> <\/p>\n<p>K8S\u4f7f\u7528\u7684\u7f51\u7edc\u63d2\u4ef6\u9700\u8981\u4e3a\u6bcf\u4e2aPod\u914d\u7f6e\u81f3\u5c11\u4e00\u4e2a\u7279\u5b9a\u7684\u5730\u5740\uff0c\u5373Pod IP\u3002Pod IP\u5730\u5740\u5b9e\u9645\u5b58\u5728\u4e8e\u67d0\u4e2a\u7f51\u5361\uff08\u53ef\u4ee5\u662f\u865a\u62df\u673a\u8bbe\u5907\uff09\u4e0a\u3002<\/p>\n<p>\u800cService\u7684\u5730\u5740\u5374\u662f\u4e00\u4e2a\u865a\u62dfIP\u5730\u5740\uff0c\u6ca1\u6709\u4efb\u4f55\u7f51\u7edc\u63a5\u53e3\u914d\u7f6e\u5728\u6b64\u5730\u5740\u4e0a\uff0c\u5b83\u7531Kube-proxy\u501f\u52a9iptables\u89c4\u5219\u6216ipvs\u89c4\u5219\u91cd\u5b9a\u5411\u5230\u672c\u5730\u7aef\u53e3\uff0c\u518d\u5c06\u5176\u8c03\u5ea6\u5230\u540e\u7aef\u7684Pod\u5bf9\u8c61\u3002Service\u7684IP\u5730\u5740\u662f\u96c6\u7fa4\u63d0\u4f9b\u670d\u52a1\u7684\u63a5\u53e3\uff0c\u4e5f\u79f0\u4e3aCluster IP\u3002<\/p>\n<p>Pod\u7f51\u7edc\u548cIP\u7531K8S\u7684\u7f51\u7edc\u63d2\u4ef6\u8d1f\u8d23\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u5177\u4f53\u4f7f\u7528\u7684\u7f51\u7edc\u5730\u5740\u53ef\u4ee5\u5728\u7ba1\u7406\u914d\u7f6e\u7f51\u7edc\u63d2\u4ef6\u65f6\u8fdb\u884c\u6307\u5b9a\uff0c\u598210.244.0.0\/16\u7f51\u7edc\u3002\u800cCluster\u7f51\u7edc\u548cIP\u662f\u7531K8S\u96c6\u7fa4\u8d1f\u8d23\u914d\u7f6e\u548c\u7ba1\u7406\uff0c\u598210.96.0.0\/12\u7f51\u7edc\u3002<\/p>\n<p>\u4ece\u4e0a\u56fe\u8fdb\u884c\u603b\u7ed3\u8d77\u6765\uff0c\u4e00\u4e2aK8S\u96c6\u7fa4\u5305\u542b\u662f\u4e09\u4e2a\u7f51\u7edc\u3002<\/p>\n<ul>\n<li>\n<p>\u8282\u70b9\u7f51\u7edc\uff1a\u5404\u4e3b\u673a\uff08Master\u3001Node\u3001ETCD\u7b49\uff09\u81ea\u8eab\u6240\u5c5e\u7684\u7f51\u7edc\uff0c\u5730\u5740\u914d\u7f6e\u5728\u4e3b\u673a\u7684\u7f51\u7edc\u63a5\u53e3\uff0c\u7528\u4e8e\u5404\u4e3b\u673a\u4e4b\u95f4\u7684\u901a\u4fe1\uff0c\u53c8\u79f0\u4e3a\u8282\u70b9\u7f51\u7edc\u3002<\/p>\n<\/li>\n<li>\n<p>Pod\u7f51\u7edc\uff1a\u4e13\u7528\u4e8ePod\u8d44\u6e90\u5bf9\u8c61\u7684\u7f51\u7edc\uff0c\u5b83\u662f\u4e00\u4e2a\u865a\u62df\u7f51\u7edc\uff0c\u7528\u4e8e\u4e3a\u5404Pod\u5bf9\u8c61\u8bbe\u5b9aIP\u5730\u5740\u7b49\u7f51\u7edc\u53c2\u6570\uff0c\u5176\u5730\u5740\u914d\u7f6e\u5728Pod\u4e2d\u5bb9\u5668\u7684\u7f51\u7edc\u63a5\u53e3\u4e0a\u3002Pod\u7f51\u7edc\u9700\u8981\u501f\u52a9kubenet\u63d2\u4ef6\u6216CNI\u63d2\u4ef6\u5b9e\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p>Service\u7f51\u7edc\uff1a\u4e13\u7528\u4e8eService\u8d44\u6e90\u5bf9\u8c61\u7684\u7f51\u7edc\uff0c\u5b83\u4e5f\u662f\u4e00\u4e2a\u865a\u62df\u7f51\u7edc\uff0c\u7528\u4e8e\u4e3aK8S\u96c6\u7fa4\u4e4b\u4e2d\u7684Service\u914d\u7f6eIP\u5730\u5740\uff0c\u4f46\u662f\u8be5\u5730\u5740\u4e0d\u4f1a\u914d\u7f6e\u5728\u4efb\u4f55\u4e3b\u673a\u6216\u5bb9\u5668\u7684\u7f51\u7edc\u63a5\u53e3\u4e0a\uff0c\u800c\u662f\u901a\u8fc7Node\u4e0a\u7684kube-proxy\u914d\u7f6e\u4e3aiptables\u6216ipvs\u89c4\u5219\uff0c\u4ece\u800c\u5c06\u53d1\u5f80\u8be5\u5730\u5740\u7684\u6240\u6709\u6d41\u91cf\u8c03\u5ea6\u5230\u540e\u7aef\u7684\u5404Pod\u5bf9\u8c61\u4e4b\u4e0a\u3002<\/p>\n<\/li>\n<\/ul>\n<h3><strong>3.2 K8S\u7684\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/h3>\n<p>\u7528K8S\u90e8\u7f72Nginx\u7684\u8fc7\u7a0b\u4e2d\uff0cK8S\u5185\u90e8\u5404\u7ec4\u4ef6\u662f\u5982\u4f55\u534f\u540c\u5de5\u4f5c\u7684\uff1a<\/p>\n<p><strong>\u6211\u4eec\u5728master\u8282\u70b9\u6267\u884c\u4e00\u6761\u547d\u4ee4\u8981master\u90e8\u7f72\u4e00\u4e2anginx\u5e94\u7528<\/strong>(kubectl create deployment nginx --image=nginx)<\/p>\n<ul>\n<li>\n<p>\u8fd9\u6761\u547d\u4ee4\u9996\u5148\u53d1\u5230master\u8282\u70b9\u7684\u7f51\u5173api server\uff0c\u8fd9\u662fmatser\u7684\u552f\u4e00\u5165\u53e3<\/p>\n<\/li>\n<li>\n<p>api server\u5c06\u547d\u4ee4\u8bf7\u6c42\u4ea4\u7ed9controller mannager\u8fdb\u884c\u63a7\u5236<\/p>\n<\/li>\n<li>\n<p>controller mannager \u8fdb\u884c\u5e94\u7528\u90e8\u7f72\u89e3\u6790<\/p>\n<\/li>\n<li>\n<p>controller mannager \u4f1a\u751f\u6210\u4e00\u6b21\u90e8\u7f72\u4fe1\u606f\uff0c\u5e76\u901a\u8fc7api server\u5c06\u4fe1\u606f\u5b58\u5165etcd\u5b58\u50a8\u4e2d<\/p>\n<\/li>\n<li>\n<p>scheduler\u8c03\u5ea6\u5668\u901a\u8fc7api server\u4eceetcd\u5b58\u50a8\u4e2d\uff0c\u62ff\u5230\u8981\u90e8\u7f72\u7684\u5e94\u7528\uff0c\u5f00\u59cb\u8c03\u5ea6\u770b\u54ea\u4e2a\u8282\u70b9\u6709\u8d44\u6e90\u9002\u5408\u90e8\u7f72<\/p>\n<\/li>\n<li>\n<p>scheduler\u628a\u8ba1\u7b97\u51fa\u6765\u7684\u8c03\u5ea6\u4fe1\u606f\u901a\u8fc7api server\u518d\u653e\u5230etcd\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u4e2anode\u8282\u70b9\u7684\u76d1\u63a7\u7ec4\u4ef6kubelet\uff0c\u968f\u65f6\u548cmaster\u4fdd\u6301\u8054\u7cfb\uff08\u7ed9api-server\u53d1\u9001\u8bf7\u6c42\u4e0d\u65ad\u83b7\u53d6\u6700\u65b0\u6570\u636e\uff09\uff0c\u62ff\u5230master\u8282\u70b9\u5b58\u50a8\u5728etcd\u4e2d\u7684\u90e8\u7f72\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>\u5047\u8bbenode2\u7684kubelet\u62ff\u5230\u90e8\u7f72\u4fe1\u606f\uff0c\u663e\u793a\u4ed6\u81ea\u5df1\u8282\u70b9\u8981\u90e8\u7f72\u67d0\u67d0\u5e94\u7528<\/p>\n<\/li>\n<li>\n<p>kubelet\u5c31\u81ea\u5df1run\u4e00\u4e2a\u5e94\u7528\u5728\u5f53\u524d\u673a\u5668\u4e0a\uff0c\u5e76\u968f\u65f6\u7ed9master\u6c47\u62a5\u5f53\u524d\u5e94\u7528\u7684\u72b6\u6001\u4fe1\u606f<\/p>\n<\/li>\n<li>\n<p>node\u548cmaster\u4e5f\u662f\u901a\u8fc7master\u7684api-server\u7ec4\u4ef6\u8054\u7cfb\u7684<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u4e2a\u673a\u5668\u4e0a\u7684kube-proxy\u80fd\u77e5\u9053\u96c6\u7fa4\u7684\u6240\u6709\u7f51\u7edc\uff0c\u53ea\u8981node\u8bbf\u95ee\u522b\u4eba\u6216\u8005\u522b\u4eba\u8bbf\u95eenode\uff0cnode\u4e0a\u7684kube-proxy\u7f51\u7edc\u4ee3\u7406\u81ea\u52a8\u8ba1\u7b97\u8fdb\u884c\u6d41\u91cf\u8f6c\u53d1<\/p>\n<\/li>\n<\/ul>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps40.jpg\" alt=\"img\" \/> <\/p>\n<h3><strong>3.3 k8s\u67b6\u6784\u539f\u7406\u516d\u8fde\u95ee<\/strong><\/h3>\n<p>K8S \u662f\u4e00\u4e2a\u57fa\u4e8e\u5bb9\u5668\u6280\u672f\u7684\u5206\u5e03\u5f0f\u96c6\u7fa4\u7ba1\u7406\u7cfb\u7edf\u3002\u65e2\u7136\u662f\u4e2a\u5206\u5e03\u5f0f\u7cfb\u7edf\uff0c\u90a3\u52bf\u5fc5\u6709\u591a\u4e2a Node \u8282\u70b9\uff08\u7269\u7406\u4e3b\u673a\u6216\u865a\u62df\u673a\uff09\uff0c\u5b83\u4eec\u5171\u540c\u7ec4\u6210\u4e00\u4e2a\u5206\u5e03\u5f0f\u96c6\u7fa4\uff0c\u5e76\u4e14\u8fd9\u4e9b\u8282\u70b9\u4e2d\u4f1a\u6709\u4e00\u4e2a Master \u8282\u70b9\uff0c\u7531\u5b83\u6765\u7edf\u4e00\u7ba1\u7406 Node \u8282\u70b9\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps41.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u4e00\uff1a\u4e3b\u8282\u70b9\u548c\u5de5\u4f5c\u8282\u70b9\u662f\u5982\u4f55\u901a\u4fe1\u7684\u5462\uff1f<\/strong><\/h4>\n<p>\u9996\u5148\uff0cMaster \u8282\u70b9\u542f\u52a8\u65f6\uff0c\u4f1a\u8fd0\u884c\u4e00\u4e2a kube-apiserver \u8fdb\u7a0b\uff0c\u5b83\u63d0\u4f9b\u4e86\u96c6\u7fa4\u7ba1\u7406\u7684 API \u63a5\u53e3\uff0c\u662f\u96c6\u7fa4\u5185\u5404\u4e2a\u529f\u80fd\u6a21\u5757\u4e4b\u95f4\u6570\u636e\u4ea4\u4e92\u548c\u901a\u4fe1\u7684\u4e2d\u5fc3\u67a2\u7ebd\uff0c\u5e76\u4e14\u5b83\u9875\u63d0\u4f9b\u4e86\u5b8c\u5907\u7684\u96c6\u7fa4\u5b89\u5168\u673a\u5236\u3002<\/p>\n<p>\u5728 Node \u8282\u70b9\u4e0a\uff0c\u4f7f\u7528 K8S \u4e2d\u7684 kubelet \u7ec4\u4ef6\uff0c\u5728\u6bcf\u4e2a Node \u8282\u70b9\u4e0a\u90fd\u4f1a\u8fd0\u884c\u4e00\u4e2a kubelet \u8fdb\u7a0b\uff0c\u5b83\u8d1f\u8d23\u5411 Master \u6c47\u62a5\u81ea\u8eab\u8282\u70b9\u7684\u8fd0\u884c\u60c5\u51b5\uff0c\u5982 Node \u8282\u70b9\u7684\u6ce8\u518c\u3001\u7ec8\u6b62\u3001\u5b9a\u65f6\u4e0a\u62a5\u5065\u5eb7\u72b6\u51b5\u7b49\uff0c\u4ee5\u53ca\u63a5\u6536 Master \u53d1\u51fa\u7684\u547d\u4ee4\uff0c\u521b\u5efa\u76f8\u5e94 Pod\u3002<\/p>\n<p>\u5728 K8S \u4e2d\uff0cPod \u662f\u6700\u57fa\u672c\u7684\u64cd\u4f5c\u5355\u5143\uff0c\u5b83\u4e0e docker \u7684\u5bb9\u5668\u6709\u7565\u5fae\u7684\u4e0d\u540c\uff0c\u56e0\u4e3a Pod \u53ef\u80fd\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u5bb9\u5668\uff08\u53ef\u4ee5\u662f docker \u5bb9\u5668\uff09\uff0c\u8fd9\u4e9b\u5185\u90e8\u7684\u5bb9\u5668\u662f\u5171\u4eab\u7f51\u7edc\u8d44\u6e90\u7684\uff0c\u5373\u53ef\u4ee5\u901a\u8fc7 localhost \u8fdb\u884c\u76f8\u4e92\u8bbf\u95ee\u3002<\/p>\n<p>\u5173\u4e8e Pod \u5185\u662f\u5982\u4f55\u505a\u5230\u7f51\u7edc\u5171\u4eab\u7684\uff0c\u6bcf\u4e2a Pod \u542f\u52a8\uff0c\u5185\u90e8\u90fd\u4f1a\u542f\u52a8\u4e00\u4e2a pause \u5bb9\u5668\uff08google\u7684\u4e00\u4e2a\u955c\u50cf\uff09\uff0c\u5b83\u4f7f\u7528\u9ed8\u8ba4\u7684\u7f51\u7edc\u6a21\u5f0f\uff0c\u800c\u5176\u4ed6\u5bb9\u5668\u7684\u7f51\u7edc\u90fd\u8bbe\u7f6e\u7ed9\u5b83\uff0c\u4ee5\u6b64\u6765\u5b8c\u6210\u7f51\u7edc\u7684\u5171\u4eab\u95ee\u9898\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps42.jpg\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u4e8c\uff1aMaster \u662f\u5982\u4f55\u5c06 Pod \u8c03\u5ea6\u5230\u6307\u5b9a\u7684 Node \u4e0a\u7684\uff1f<\/strong><\/h4>\n<p>\u8be5\u5de5\u4f5c\u7531 kube-scheduler \u6765\u5b8c\u6210\uff0c\u6574\u4e2a\u8c03\u5ea6\u8fc7\u7a0b\u901a\u8fc7\u6267\u884c\u4e00\u4e9b\u5217\u590d\u6742\u7684\u7b97\u6cd5\u6700\u7ec8\u4e3a\u6bcf\u4e2a Pod \u8ba1\u7b97\u51fa\u4e00\u4e2a\u6700\u4f73\u7684\u76ee\u6807 Node\uff0c\u8be5\u8fc7\u7a0b\u7531 kube-scheduler \u8fdb\u7a0b\u81ea\u52a8\u5b8c\u6210\u3002\u5e38\u89c1\u7684\u6709\u8f6e\u8be2\u8c03\u5ea6\uff08RR\uff09\u3002\u5f53\u7136\u4e5f\u6709\u53ef\u80fd\uff0c\u6211\u4eec\u9700\u8981\u5c06 Pod \u8c03\u5ea6\u5230\u4e00\u4e2a\u6307\u5b9a\u7684 Node \u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8282\u70b9\u7684\u6807\u7b7e\uff08Label\uff09\u548c Pod \u7684 nodeSelector \u5c5e\u6027\u7684\u76f8\u4e92\u5339\u914d\uff0c\u6765\u8fbe\u5230\u6307\u5b9a\u7684\u6548\u679c\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps43.png\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u4e09\uff1a\u5404\u8282\u70b9\u3001Pod \u7684\u4fe1\u606f\u90fd\u662f\u7edf\u4e00\u7ef4\u62a4\u5728\u54ea\u91cc\u7684\uff0c\u7531\u8c01\u6765\u7ef4\u62a4\uff1f<\/strong><\/h4>\n<p>\u4ece\u4e0a\u9762\u7684 Pod \u8c03\u5ea6\u7684\u89d2\u5ea6\u770b\uff0c\u6211\u4eec\u5f97\u6709\u4e00\u4e2a\u5b58\u50a8\u4e2d\u5fc3\uff0c\u7528\u6765\u5b58\u50a8\u5404\u8282\u70b9\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3001\u5065\u5eb7\u72b6\u6001\u3001\u4ee5\u53ca\u5404 Pod \u7684\u57fa\u672c\u4fe1\u606f\u7b49\uff0c\u8fd9\u6837 Pod \u7684\u8c03\u5ea6\u6765\u80fd\u6b63\u5e38\u8fdb\u884c\u3002<\/p>\n<p>\u5728 K8S \u4e2d\uff0c\u91c7\u7528 etcd \u7ec4\u4ef6 \u4f5c\u4e3a\u4e00\u4e2a\u9ad8\u53ef\u7528\u5f3a\u4e00\u81f4\u6027\u7684\u5b58\u50a8\u4ed3\u5e93\uff0c\u8be5\u7ec4\u4ef6\u53ef\u4ee5\u5185\u7f6e\u5728 K8S \u4e2d\uff0c\u4e5f\u53ef\u4ee5\u5916\u90e8\u642d\u5efa\u4f9b K8S \u4f7f\u7528\u3002<\/p>\n<p>\u96c6\u7fa4\u4e0a\u7684\u6240\u6709\u914d\u7f6e\u4fe1\u606f\u90fd\u5b58\u50a8\u5728\u4e86 etcd\uff0c\u4e3a\u4e86\u8003\u8651\u5404\u4e2a\u7ec4\u4ef6\u7684\u76f8\u5bf9\u72ec\u7acb\uff0c\u4ee5\u53ca\u6574\u4f53\u7684\u7ef4\u62a4\u6027\uff0c\u5bf9\u4e8e\u8fd9\u4e9b\u5b58\u50a8\u6570\u636e\u7684\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\uff0c\u7edf\u4e00\u7531 kube-apiserver \u6765\u8fdb\u884c\u8c03\u7528\uff0capiserver \u4e5f\u63d0\u4f9b\u4e86 REST \u7684\u652f\u6301\uff0c\u4e0d\u4ec5\u5bf9\u5404\u4e2a\u5185\u90e8\u7ec4\u4ef6\u63d0\u4f9b\u670d\u52a1\u5916\uff0c\u8fd8\u5bf9\u96c6\u7fa4\u5916\u90e8\u7528\u6237\u66b4\u9732\u670d\u52a1\u3002<\/p>\n<p>\u5916\u90e8\u7528\u6237\u53ef\u4ee5\u901a\u8fc7 REST \u63a5\u53e3\uff0c\u6216\u8005 kubectl \u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u96c6\u7fa4\u7ba1\u7406\uff0c\u5176\u5185\u5728\u90fd\u662f\u4e0e apiserver \u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps44.png\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u56db\uff1a\u5916\u90e8\u7528\u6237\u5982\u4f55\u8bbf\u95ee\u96c6\u7fa4\u5185\u8fd0\u884c\u7684 Pod \uff1f<\/strong><\/h4>\n<p>\u524d\u9762\u8bb2\u4e86\u5916\u90e8\u7528\u6237\u5982\u4f55\u7ba1\u7406 K8S\uff0c\u800c\u6211\u4eec\u66f4\u5173\u5fc3\u7684\u662f\u5185\u90e8\u8fd0\u884c\u7684 Pod \u5982\u4f55\u5bf9\u5916\u8bbf\u95ee\u3002\u4f7f\u7528\u8fc7Docker \u7684\u540c\u5b66\u5e94\u8be5\u77e5\u9053\uff0c\u5982\u679c\u4f7f\u7528 bridge \u6a21\u5f0f\uff0c\u5728\u5bb9\u5668\u521b\u5efa\u65f6\uff0c\u90fd\u4f1a\u5206\u914d\u4e00\u4e2a\u865a\u62df IP\uff0c\u8be5 IP \u5916\u90e8\u662f\u6ca1\u6cd5\u8bbf\u95ee\u5230\u7684\uff0c\u6211\u4eec\u9700\u8981\u505a\u4e00\u5c42\u7aef\u53e3\u6620\u5c04\uff0c\u5c06\u5bb9\u5668\u5185\u7aef\u53e3\u4e0e\u5bbf\u4e3b\u673a\u7aef\u53e3\u8fdb\u884c\u6620\u5c04\u7ed1\u5b9a\uff0c\u8fd9\u6837\u5916\u90e8\u901a\u8fc7\u8bbf\u95ee\u5bbf\u4e3b\u673a\u7684\u6307\u5b9a\u7aef\u53e3\uff0c\u5c31\u53ef\u4ee5\u8bbf\u95ee\u5230\u5185\u90e8\u5bb9\u5668\u7aef\u53e3\u4e86\u3002<\/p>\n<p>\u90a3\u4e48\uff0cK8S \u7684\u5916\u90e8\u8bbf\u95ee\u662f\u5426\u4e5f\u662f\u8fd9\u6837\u5b9e\u73b0\u7684\uff1f\u7b54\u6848\u662f\u5426\u5b9a\u7684\uff0cK8S \u4e2d\u60c5\u51b5\u8981\u590d\u6742\u4e00\u4e9b\u3002\u56e0\u4e3a\u4e0a\u9762\u8bb2\u7684 Docker \u662f\u5355\u673a\u6a21\u5f0f\u4e0b\u7684\uff0c\u800c\u4e14\u4e00\u4e2a\u5bb9\u5668\u5bf9\u5916\u5c31\u66b4\u9732\u4e00\u4e2a\u670d\u52a1\u3002\u5728\u5206\u5e03\u5f0f\u96c6\u7fa4\u4e0b\uff0c\u4e00\u4e2a\u670d\u52a1\u5f80\u5f80\u7531\u591a\u4e2a Application \u63d0\u4f9b\uff0c\u7528\u6765\u5206\u62c5\u8bbf\u95ee\u538b\u529b\uff0c\u800c\u4e14\u8fd9\u4e9b Application \u53ef\u80fd\u4f1a\u5206\u5e03\u5728\u591a\u4e2a\u8282\u70b9\u4e0a\uff0c\u8fd9\u6837\u53c8\u6d89\u53ca\u5230\u4e86\u8de8\u4e3b\u673a\u7684\u901a\u4fe1\u3002<\/p>\n<p>\u8fd9\u91cc\uff0cK8S \u5f15\u5165\u4e86 Service \u7684\u6982\u5ff5\uff0c\u5c06\u591a\u4e2a\u76f8\u540c\u7684 Pod \u5305\u88c5\u6210\u4e00\u4e2a\u5b8c\u6574\u7684 service \u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u81f3\u4e8e\u83b7\u53d6\u5230\u8fd9\u4e9b\u76f8\u540c\u7684 Pod\uff0c\u6bcf\u4e2a Pod \u542f\u52a8\u65f6\u90fd\u4f1a\u8bbe\u7f6e labels \u5c5e\u6027\uff0c\u5728 Service \u4e2d\u6211\u4eec\u901a\u8fc7\u9009\u62e9\u5668 Selector\uff0c\u9009\u62e9\u5177\u6709\u76f8\u540c Name \u6807\u7b7e\u5c5e\u6027\u7684 Pod\uff0c\u4f5c\u4e3a\u6574\u4f53\u670d\u52a1\uff0c\u5e76\u5c06\u670d\u52a1\u4fe1\u606f\u901a\u8fc7 Apiserver \u5b58\u5165 etcd \u4e2d\uff0c\u8be5\u5de5\u4f5c\u7531 Service Controller \u6765\u5b8c\u6210\u3002\u540c\u65f6\uff0c\u6bcf\u4e2a\u8282\u70b9\u4e0a\u4f1a\u542f\u52a8\u4e00\u4e2a kube-proxy \u8fdb\u7a0b\uff0c\u7531\u5b83\u6765\u8d1f\u8d23\u670d\u52a1\u5730\u5740\u5230 Pod \u5730\u5740\u7684\u4ee3\u7406\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u7b49\u5de5\u4f5c\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps45.png\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u4e94\uff1aPod \u5982\u4f55\u52a8\u6001\u6269\u5bb9\u548c\u7f29\u653e\uff1f<\/strong><\/h4>\n<p>\u65e2\u7136\u77e5\u9053\u4e86\u670d\u52a1\u662f\u7531 Pod \u7ec4\u6210\u7684\uff0c\u90a3\u4e48\u670d\u52a1\u7684\u6269\u5bb9\u4e5f\u5c31\u610f\u5473\u7740 Pod \u7684\u6269\u5bb9\u3002\u901a\u4fd7\u70b9\u8bb2\uff0c\u5c31\u662f\u5728\u9700\u8981\u65f6\u5c06 Pod \u590d\u5236\u591a\u4efd\uff0c\u5728\u4e0d\u9700\u8981\u540e\uff0c\u5c06 Pod \u7f29\u51cf\u81f3\u6307\u5b9a\u4efd\u6570\u3002K8S \u4e2d\u901a\u8fc7 Replication Controller \u6765\u8fdb\u884c\u7ba1\u7406\uff0c\u4e3a\u6bcf\u4e2a Pod \u8bbe\u7f6e\u4e00\u4e2a\u671f\u671b\u7684\u526f\u672c\u6570\uff0c\u5f53\u5b9e\u9645\u526f\u672c\u6570\u4e0e\u671f\u671b\u4e0d\u7b26\u65f6\uff0c\u5c31\u52a8\u6001\u7684\u8fdb\u884c\u6570\u91cf\u8c03\u6574\uff0c\u4ee5\u8fbe\u5230\u671f\u671b\u503c\u3002\u671f\u671b\u6570\u503c\u53ef\u4ee5\u7531\u6211\u4eec\u624b\u52a8\u66f4\u65b0\uff0c\u6216\u81ea\u52a8\u6269\u5bb9\u4ee3\u7406\u6765\u5b8c\u6210\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps46.png\" alt=\"img\" \/> <\/p>\n<h4><strong>\u95ee\u9898\u516d\uff1a\u5404\u4e2a\u7ec4\u4ef6\u4e4b\u95f4\u662f\u5982\u4f55\u76f8\u4e92\u534f\u4f5c\u7684\uff1f<\/strong><\/h4>\n<p>\u6700\u540e\uff0c\u8bb2\u4e00\u4e0b kube-controller-manager \u8fd9\u4e2a\u8fdb\u7a0b\u7684\u4f5c\u7528\u3002\u6211\u4eec\u77e5\u9053\u4e86 ectd \u662f\u4f5c\u4e3a\u96c6\u7fa4\u6570\u636e\u7684\u5b58\u50a8\u4e2d\u5fc3\uff0c apiserver \u662f\u7ba1\u7406\u6570\u636e\u4e2d\u5fc3\uff0c\u4f5c\u4e3a\u5176\u4ed6\u8fdb\u7a0b\u4e0e\u6570\u636e\u4e2d\u5fc3\u901a\u4fe1\u7684\u6865\u6881\u3002\u800c Service Controller\u3001Replication Controller \u8fd9\u4e9b\u7edf\u4e00\u4ea4\u7531 kube-controller-manager \u6765\u7ba1\u7406\uff0ckube-controller-manager \u4f5c\u4e3a\u4e00\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff0c\u6bcf\u4e2a Controller \u90fd\u662f\u4e00\u4e2a\u63a7\u5236\u5faa\u73af\uff0c\u901a\u8fc7 apiserver \u76d1\u89c6\u96c6\u7fa4\u7684\u5171\u4eab\u72b6\u6001\uff0c\u5e76\u5c1d\u8bd5\u5c06\u5b9e\u9645\u72b6\u6001\u4e0e\u671f\u671b\u4e0d\u7b26\u7684\u8fdb\u884c\u6539\u53d8\u3002\u5173\u4e8e Controller\uff0cmanager \u4e2d\u8fd8\u5305\u542b\u4e86 Node \u8282\u70b9\u63a7\u5236\u5668\uff08Node Controller\uff09\u3001\u8d44\u6e90\u914d\u989d\u7ba1\u63a7\u5236\u5668\uff08ResourceQuota Controller\uff09\u3001\u547d\u540d\u7a7a\u95f4\u63a7\u5236\u5668\uff08Namespace Controller\uff09\u7b49\u3002<\/p>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/wps47.png\" alt=\"img\" \/> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. K8S \u6982\u89c8 1.1 K8S \u662f\u4ec0\u4e48 K8S\u5b98\u7f51\u6587\u6863\uff1ahttps:\/\/kubernetes.io\/zh\/docs\/home\/ K8   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[291],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9517"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9517"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9517\/revisions"}],"predecessor-version":[{"id":9518,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/9517\/revisions\/9518"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9517"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}