{"id":7813,"date":"2020-02-27T16:44:13","date_gmt":"2020-02-27T08:44:13","guid":{"rendered":"https:\/\/www.microfusion.cloud\/hk\/?p=7813"},"modified":"2023-08-18T13:51:20","modified_gmt":"2023-08-18T05:51:20","slug":"kubernetes-gke-1","status":"publish","type":"post","link":"https:\/\/www.microfusion.cloud\/hk\/2020\/02\/27\/kubernetes-gke-1\/","title":{"rendered":"\u79c1\u623f\u7b46\u8a18\uff1aKubernetes &#038; GKE"},"content":{"rendered":"\n<p>\u4e4b\u524d\u8209\u8fa6\u904e\u6578\u6b21\u7dda\u4e0a\u7814\u8a0e\u6703\u4ecb\u7d39 Kubernetes (K8S) \u4ee5\u53ca <a href=\"https:\/\/www.microfusion.cloud\/hk\/cloud-solution\/gcp\/\">Google Cloud Platform<\/a> (GCP) \u4e0a\u6240\u63d0\u4f9b\u7684\u4ee3\u7ba1\u670d\u52d9 Google Kubernetes Engine (GKE)\uff0c\u90fd\u7372\u5f97\u4e0d\u932f\u7684\u8ff4\u97ff\u4ee5\u53ca\u5ba2\u6236\u6b63\u9762\u7684\u80af\u5b9a\uff0c\u7576\u7136\u4e5f\u6709\u4e9b\u670b\u53cb\u53cd\u6620\u6c92\u6709\u53c3\u52a0\u5230\uff0c\u5e0c\u671b\u6709\u6a5f\u6703\u518d\u6b21\u8209\u8fa6\u3002\u70ba\u4e86\u80fd\u8b93\u66f4\u591a\u670b\u53cb\u53ef\u4ee5\u4e86\u89e3 K8S \u4ee5\u53ca GKE\uff0c\u6211\u5011\u5c07\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\u70ba\u5927\u5bb6\u4ecb\u7d39 K8S \u53ca GKE \u7684\u76f8\u95dc\u670d\u52d9\u3002<\/p>\n<p>\u7531\u65bc K8S \u548c GKE \u529f\u80fd\u5df2\u76f8\u7576\u5b8c\u6574\uff0c\u5f8c\u7e8c\u6703\u5c07\u91cd\u8981\u67b6\u69cb\u89c0\u5ff5\u3001\u6700\u5e38\u4f7f\u7528\u5230\u7684\u670d\u52d9\u529f\u80fd\u4ee5\u53ca\u6700\u4f73\u5be6\u8e10 (Best practice) \u5448\u73fe\u5728\u7cfb\u5217\u6587\u7ae0\u4e2d\uff0c\u5e0c\u671b\u8b93\u60a8\u5c0d K8S \u53ca GKE \u6709\u66f4\u6df1\u7684\u8a8d\u8b58\u3002\u672c\u7bc7\u6703\u5148\u4ecb\u7d39 Kubernetes \u7684\u91cd\u8981\u57fa\u672c\u89c0\u5ff5\u3002<\/p>\n<p>\u5927\u5bb6\u90fd\u77e5\u9053 Kubernetes (K8S) \u662f\u5bb9\u5668 (Container) \u670d\u52d9\u8cc7\u6e90\u7ba1\u7406\u8abf\u5ea6\u7684\u5de5\u5177 (Orchestrator)\uff0c\u53ef\u4ee5\u7d71\u4e00\u96c6\u4e2d\u8abf\u5ea6\u7531\u5bb9\u5668\u7d44\u6210\u7684\u5fae\u670d\u52d9 (Micro-service)\u3002<\/p>\n<p>\u4e00\u822c\u800c\u8a00\uff0c\u61c9\u7528\u7a0b\u5f0f\u958b\u767c\u8005\u53ef\u4ee5\u5c08\u6ce8\u65bc\u61c9\u7528\u7a0b\u5f0f\u7684\u958b\u767c\uff0c\u53ea\u9700\u5c07\u670d\u52d9\u6253\u5305\u6210\u5bb9\u5668\u7684\u683c\u5f0f (ex: Docker Container)\uff0c\u63a5\u8457\u5c07\u5bb9\u5668\u6620\u50cf\u6a94 (Image) \u63d0\u4ea4\u81f3 Registry\uff0c\u7531\u7dad\u904b\u5718\u968a\u4f86\u9032\u884c\u61c9\u7528\u7a0b\u5f0f\u7248\u672c\u7684\u66f4\u65b0\u3002\u900f\u904e K8S \u7684\u5fae\u670d\u52d9\u7ba1\u7406\u6846\u67b6 (Framework)\uff0c\u7dad\u904b\u5718\u968a\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8a72\u6620\u50cf\u6a94\u5e03\u5efa\u81f3 Kubernetes\uff0c\u5373\u53ef\u7531 Kubernetes \u81ea\u52d5\u5730\u9032\u884c\u5bb9\u5668\u61c9\u7528\u670d\u52d9\u7684\u5e03\u5efa\u53ca\u7ba1\u7406\u3002<\/p>\n<p>\u4e00\u822c\u5e38\u898b\u7684\u5efa\u7f6e\u65b9\u5f0f\u70ba\u4f7f\u7528\u6578\u53f0\u5be6\u9ad4\u6a5f\u5668 (Physical Server) \u6216\u8005\u662f\u865b\u64ec\u6a5f (Virtual Machine)\uff0c\u5206\u5225\u5b89\u88dd\u5efa\u7f6e\u6210\u70ba K8S Master node \u4ee5\u53ca\u6578\u53f0 K8S node\u3002\u900f\u904eK8S\u7684\u8cc7\u6e90\u7ba1\u7406\u53ca\u8abf\u5ea6\u6a5f\u5236\uff0c\u53ef\u4ee5\u5c07\u591a\u53f0 node \u7684\u5be6\u9ad4\u904b\u7b97\u53ca\u5132\u5b58 (Storage) \u8cc7\u6e90\u4ee5\u53e2\u96c6 (Cluster) \u65b9\u5f0f\u63d0\u4f9b\u7d66\u7cfb\u7d71\u7dad\u904b\u7ba1\u7406\u8005\uff0c\u7528\u4ee5\u7ba1\u7406\u670d\u52d9\u8cc7\u6e90\u4ee5\u53ca\u5916\u90e8\u4f7f\u7528\u8005\u5b58\u53d6\u7684\u61c9\u7528\u670d\u52d9\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5982 K8S <a style=\"color: #000000;\" href=\"https:\/\/kubernetes.io\/\" target=\"_blank\" rel=\"noopener\">\u5b98\u7db2<\/a>\u6240\u8ff0\uff0cK8S\u63d0\u4f9b\u4e86 \u201cAutomated container deployment, scaling, and management\u201d\uff0c\u5927\u5e45\u63d0\u5347\u61c9\u7528\u7a0b\u5f0f\u670d\u52d9\u7684\u53ef\u9760\u5ea6\u53ca\u6e1b\u8f15\u7cfb\u7d71\u7ba1\u7406\u7684\u8ca0\u64d4\uff0c\u9019\u4e5f\u662f\u70ba\u4ec0\u9ebc\u8fd1\u5e74\u4f86\u53ea\u8981\u8ac7\u5230 CI\/CD\u3001DevOps \u4e3b\u984c\uff0c\u5927\u5bb6\u5c31\u6703\u76f4\u63a5\u806f\u60f3\u5230 Kubernetes \u7684\u539f\u56e0\u3002\u5176\u91cd\u8981\u529f\u80fd\u5982\u4e0b:<\/p>\n<ul>\n<li>\u5bb9\u5668\u81ea\u52d5\u90e8\u5c6c (Automated deployment) : \u4f7f\u7528\u8005\u50c5\u9700\u6307\u5b9a\u670d\u52d9\u6240\u9700\u7684\u5bb9\u5668\u6578\u91cf\uff0cK8S \u4fbf\u6703\u81ea\u52d5\u5c07\u4f7f\u7528\u8005\u7684\u5bb9\u5668\u670d\u52d9\u5e03\u5efa\u65bc\u53e2\u96c6\u5167\u7684\u591a\u500b\u5de5\u4f5c\u7bc0\u9ede (worker node) \u4e0a\u3002<\/li>\n<li>\u670d\u52d9\u81ea\u52d5\u64f4\u5c55 (Automated scaling) : \u7576\u7cfb\u7d71\u555f\u7528 auto-scaling \u529f\u80fd\uff0c\u4e00\u4f46\u5bb9\u5668\u670d\u52d9\u5de5\u4f5c\u8ca0\u8f09 (loading) \u8d85\u904e\u6307\u5b9a\u7684\u9580\u6abb\u503c\uff0cK8S \u5373\u53ef\u81ea\u52d5\u64f4\u5c55\u5bb9\u5668\u7684\u6578\u91cf\uff0c\u627f\u63a5\u5916\u90e8\u6e90\u6e90\u4e0d\u7d55\u7684\u9023\u7dda\u8acb\u6c42\u3002\u7576\u7136\uff0c\u524d\u63d0\u662f\u8981\u6709\u8db3\u5920\u53ef\u64f4\u5145\u52a0\u5165 Cluster \u7684 node \u8cc7\u6e90\u3002<\/li>\n<li>\u5bb9\u5668\u81ea\u52d5\u5316\u7ba1\u7406 (Automated management) : K8S \u6703\u7dad\u6301\u4f7f\u7528\u8005\u914d\u7f6e\u7684\u7cfb\u7d71\u5bb9\u5668\u6578\u91cf\uff0c\u7576 K8S master node \u5075\u6e2c\u5230\u6709\u4efb\u4f55\u5bb9\u5668\u6216\u662f Pod \u4e0d\u6b63\u5e38\u6642\uff0c master node \u6703\u81ea\u52d5\u555f\u52d5\u65b0\u7684 Pod \u8b93\u7cfb\u7d71\u7dad\u6301\u4e00\u5b9a\u7684\u670d\u52d9\u5bb9\u91cf (capacity)\u3002\u6b64\u5916\uff0c\u82e5\u6709\u670d\u52d9\u7248\u672c\u7684\u66f4\u52d5\uff0cK8S \u4e5f\u80fd\u63d0\u4f9b\u76f8\u7576\u4fbf\u5229\u7684\u9032\u7248\u53ca\u9000\u7248\u529f\u80fd\uff0c\u8b93\u7ba1\u7406\u8005\u5728\u670d\u52d9\u4e0d\u4e2d\u65b7\u7684\u524d\u63d0\u4e0b\u9032\u884c\u7248\u672c\u66f4\u52d5\u3002<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<p>Kubernete \u9700\u5efa\u7f6e\u65bc\u53e2\u96c6\u5f0f (Cluster) \u904b\u7b97\u8cc7\u6e90\u4e4b\u4e0a\uff0c\u904b\u884c\u67b6\u69cb\u5716\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/02\/k8s-1.png\" alt=\"\" width=\"700\" height=\"503\" \/><\/p>\n<p style=\"text-align: left;\"><strong>\u63a5\u4e0b\u4f86\u6211\u5011\u5c07\u8457\u91cd\u5728 Kubernetes \u7684\u61c9\u7528\u7a0b\u5f0f\u76f8\u95dc\u5143\u4ef6\u4e0a\uff0c\u67b6\u69cb\u5e2b\u6703\u9010\u4e00\u4ecb\u7d39\u56db\u500b\u4e3b\u8981\u5143\u4ef6\uff0c\u4e8b\u4e0d\u5b9c\u9072\uff0c\u5c31\u8b93\u6211\u5011\u4e00\u8d77\u4f86\u770b\u770b\u5427!<\/strong><\/p>\n<p>\u00a0<\/p>\n<h2>K8S\u56db\u500b\u4e3b\u8981\u5143\u4ef6<\/h2>\n<h3><strong>\u2013 K8S\u4e3b\u8981\u5143\u4ef6 Master Node<\/strong><\/h3>\n<p>Master Node \u57f7\u884c Kubernetes \u63a7\u5236\u5c64\u7a0b\u5e8f (Control Plane)\uff0c\u5305\u542b Kubernetes API \u4f3a\u670d\u5668 (kube-apiserver)\u3001\u6392\u7a0b\u5668 (scheduler) \u548c\u6838\u5fc3\u8cc7\u6e90\u63a7\u5236\u5668 (Core resource controllers)\u3002\u7cfb\u7d71\u7ba1\u7406\u8005\u6240\u6709\u8207 K8S Cluster \u7684\u4e92\u52d5\u90fd\u900f\u904e Kubernetes API \u547c\u53eb\u4f86\u5b8c\u6210\uff0c\u4e14 Master Node \u6703\u57f7\u884c Kubernetes API Server \u4f86\u8655\u7406\u9019\u4e9b\u8981\u6c42\u3002Master Node \u7684 API server \u7a0b\u5e8f\u662f Cluster \u4e2d\u6240\u6709\u901a\u8a0a\u7684\u4e2d\u6a1e\u3002\u4ee5\u4e0b\u662f Master Node \u5167\u91cd\u8981\u5143\u4ef6\uff1a<\/p>\n<ul>\n<li>kube-apiserver\uff1a\u63d0\u4f9b\u4f7f\u7528\u8005\u9023\u63a5\u7ba1\u7406 K8S Cluster \u7684\u524d\u7aef\u5165\u53e3\u3002<\/li>\n<li>etcd\uff1a\u5b58\u653e Cluster \u914d\u7f6e\u8a2d\u5b9a\u4ee5\u53ca\u5404\u9805\u5de5\u4f5c\u72c0\u614b\u53ca\u8cc7\u8a0a\uff0c\u53ef\u4ee5\u8996\u70ba\u662f Cluster \u7684\u7cfb\u7d71\u8cc7\u6599\u5eab\u3002<\/li>\n<li>kube-scheduler\uff1a\u8ca0\u8cac\u7ba1\u7406 Pod \u57f7\u884c\u4ee5\u53ca\u5206\u914d\u57f7\u884c Pod \u6240\u5c0d\u61c9\u7684 worker node\u3002<\/li>\n<li>kube-controller manager\uff1a\u5176\u4e2d\u5305\u542b\u6578\u500b controller \u6a21\u7d44\uff0c\u5305\u542b\u7ba1\u7406 Cluster \u5167 node \u7684\u72c0\u614b\uff0cPod \u7684\u526f\u672c\u6578\u91cf(Replication)\uff0c\u670d\u52d9\u5b58\u53d6\u7bc0\u9ede\u7684\u7ba1\u7406(service endpoint)\uff0caccount \u4ee5\u53ca namespace \u7ba1\u7406\u3002<\/li>\n<\/ul>\n<h3><strong>\u2013\u00a0K8S\u4e3b\u8981\u5143\u4ef6\u00a0Node<\/strong><\/h3>\n<p>Node \u7bc0\u9ede\u662f\u5be6\u969b\u904b\u884c\u5bb9\u5668\u5316\u61c9\u7528\u7a0b\u5f0f\u548c\u61c9\u7528\u7a0b\u5f0f\u670d\u52d9\u7684\u5de5\u4f5c\u7ad9\u6a5f\u5668 (worker node)\uff0c\u6bcf\u500b Node \u90fd\u900f\u904e Master Node \u7ba1\u7406\uff0c\u4e14\u5404 Node \u6703\u81ea\u884c\u56de\u5831\u6700\u65b0\u72c0\u614b\u8cc7\u8a0a\u7d66 Master Node\u3002\u5728 Worker Node \u4e2d\uff0c\u6703\u6709\u4ee5\u4e0b\u5e7e\u500b\u4e3b\u8981\u5143\u4ef6:<\/p>\n<ul>\n<li>kublet\uff1a\u8207 Master Node \u4e0a\u7684\u00a0 apiserver \u76f8\u4e92\u6e9d\u901a\u4e14\u7ba1\u7406\u53ca\u53ca\u5065\u5eb7\u76e3\u63a7 Pod \u904b\u884c\u72c0\u614b\u7684\u5de5\u5177 (agent)<\/li>\n<li>kube-proxy\uff1a\u7db2\u8def\u7ba1\u7406\u5de5\u5177<\/li>\n<li>Container runtime\uff1a\u57f7\u884c Container \u7684\u8edf\u9ad4\u5957\u4ef6 (ex: Docker\uff0c Containerd\uff0c CRI-O )<\/li>\n<\/ul>\n<h3>\u00a0<\/h3>\n<h3><strong>\u2013 K8S\u4e3b\u8981\u5143\u4ef6 Pod<\/strong><\/h3>\n<p>Pod \u662f Kubernetes \u4e2d\u6700\u5c0f\u3001\u6700\u57fa\u672c\u7684\u53ef\u90e8\u7f72\u7269\u4ef6\u3002Pod \u4ee3\u8868\u53e2\u96c6\u4e2d\u4e00\u500b\u904b\u4f5c\u4e2d\u7a0b\u5e8f\u7684\u55ae\u4e00\u57f7\u884c\u500b\u9ad4\u3002Pod \u542b\u6709\u4e00\u6216\u591a\u500b\u300c\u5bb9\u5668\u300d\uff0c\u5982 Docker \u5bb9\u5668\u3002\u82e5 Pod \u57f7\u884c\u591a\u500b\u5bb9\u5668\uff0c\u7cfb\u7d71\u6703\u5c07\u9019\u4e9b\u5bb9\u5668\u8996\u70ba\u55ae\u500b\u5be6\u9ad4\u9032\u884c\u7ba1\u7406\uff0c\u9019\u4e9b\u5bb9\u5668\u4e5f\u5171\u7528 Pod \u7684\u8cc7\u6e90\u3002<\/p>\n<p>\u4e00\u822c\u9664\u4e86\u6709\u9ad8\u5ea6\u76f8\u95dc\u806f (Tightly Coupled) \u7684\u5bb9\u5668\u670d\u52d9\u70ba\u4e86\u589e\u9032\u61c9\u7528\u7a0b\u5f0f\u7684\u6548\u7387\uff0c\u624d\u5efa\u8b70\u628a\u4e00\u500b\u4ee5\u4e0a\u7684\u5bb9\u5668\u670d\u52d9\u5305\u88dd\u9032\u540c\u4e00Pod\u5167\u3002\u4ee5\u4e0b\u5716\u70ba\u4f8b\uff0c\u8a72\u55ae\u4e00Pod\u63d0\u4f9b\u7684\u670d\u52d9\u70baWeb Server\u7db2\u9801\u670d\u52d9\uff0c\u800c\u5176\u5167\u90e8\u6709\u53e6\u4e00\u500b\u6a94\u6848\u7ba1\u7406\u670d\u52d9\uff0c\u5169\u5bb9\u5668\u53ef\u5171\u4eabPod\u5167\u7684\u5132\u5b58\u8cc7\u6e90( Shared Volume)\uff0c\u76f8\u8f14\u76f8\u6210\u63d0\u4f9b\u5916\u90e8\u4f7f\u7528\u8005\u5b58\u53d6\u7db2\u9801\u670d\u52d9\u4e26\u900f\u904e\u7db2\u9801\u9801\u9762\u986f\u793a\u5c0d\u61c9\u7684\u6a94\u6848\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-2-282x300.png\" \/><\/p>\n<p style=\"text-align: center;\">\u5716\u7247\u4f86\u6e90: Kubernetes<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod\/\" target=\"_blank\" rel=\"noopener\">\u5b98\u7db2<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-1-1024x477.png\" width=\"689\" height=\"321\" \/><\/p>\n<h3><strong>\u2013 K8S\u4e3b\u8981\u5143\u4ef6 Deployment<\/strong><\/h3>\n<p>Deployment \u53ef\u4ee5\u8996\u70ba\u4e00\u7d44\u76f8\u540c Pod \u6240\u7d44\u6210\u7684\u670d\u52d9\u7ba1\u7406\u55ae\u5143\uff0c\u5176\u4e2d\u53ef\u4ee5\u900f\u904e\u526f\u672c (Replicas) \u53c3\u6578\u6307\u5b9a\u6240\u9700\u7684 Pod \u6578\u91cf\u3002Deployment \u53ef\u5354\u52a9\u78ba\u4fdd\u61c9\u7528\u7a0b\u5f0f\u53ef\u4ee5\u6709\u4e00\u6216\u591a\u500b\u57f7\u884c\u500b\u9ad4\u8655\u7406\u4f7f\u7528\u8005\u8981\u6c42\u4e26\u6703\u81ea\u52d5\u53d6\u4ee3\u5931\u6557\u6216\u5df2\u5f9e\u7bc0\u9ede\u4e2d\u79fb\u9664\u7684 Pod\u3002\u4ee5\u4e0b\u5716\u70ba\u4f8b\uff0c\u8a72 Deployment \u5167\u6307\u5b9a K8S Cluster \u9700\u5efa\u7f6e\u5169\u7d44\u76f8\u540c\u670d\u52d9\u7684 Pod\uff0c\u800c\u6b64\u5169\u7d44 Pod \u6703\u7531 Cluster \u5e03\u5efa\u65bc node \u4e4b\u4e2d\uff0c\u4e14 K8S \u6703\u65bc\u7cfb\u7d71\u5167\u6301\u7e8c\u7dad\u6301\u5169\u7d44\u904b\u884c\u4e2d\u7684 Pod \u4f86\u63d0\u4f9b\u670d\u52d9\u8b93\u7528\u6236\u7aef\u5b58\u53d6\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8008\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3-1024x593.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3-1024x593.png 1024w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3-300x174.png 300w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3-768x445.png 768w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3-600x348.png 600w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-3.png 1253w\" alt=\"\" width=\"700\" height=\"406\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8031 aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2.png 1064w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2-300x140.png 300w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2-768x358.png 768w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2-1024x477.png 1024w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-2-600x280.png 600w\" alt=\"\" width=\"700\" height=\"326\" \/><\/p>\n<p>\u00a0<\/p>\n<p><strong>\u65e2\u7136\u5927\u5bb6\u90fd\u5df2\u7d93\u4e86\u89e3\u61c9\u7528\u7a0b\u5f0f\u76f8\u95dc\u5143\u4ef6\u5982\u4f55\u65bc K8S \u5167\u7d44\u6210\u53ca\u904b\u884c\uff0c \u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u5c07\u89e3\u91cb\u5982\u4f55\u5c07\u61c9\u7528\u7a0b\u5f0f\u670d\u52d9\u63d0\u4f9b\u7d66\u5176\u4ed6\u4f7f\u7528\u8005\u6216\u61c9\u7528\u7a0b\u5f0f\uff0c \u4e26\u516c\u958b\u63d0\u4f9b\u7d66\u5916\u90e8\u4f7f\u7528\u7684\u91cd\u8981K8S\u5143\u4ef6(Component)!<\/strong><\/p>\n<h3><strong>\u2013 Service<\/strong><\/h3>\n<p>Service \u7684\u6982\u5ff5\uff0c\u5c31\u662f\u5c07\u4e00\u7d44 Pod \u7aef\u9ede (Endpoint) \u805a\u96c6\u6210\u55ae\u4e00\u8cc7\u6e90\uff0c\u800c\u4f7f\u7528\u8005\u53ef\u4ee5\u8a2d\u5b9a\u5229\u7528\u591a\u7a2e\u65b9\u5f0f\u4f86\u5b58\u53d6\u9019\u7d44 Pod \u7aef\u9ede (Endpoint)\u3002\u6839\u64da\u9810\u8a2d\uff0cK8S \u6703\u7522\u751f\u4e00\u500b\u7a69\u5b9a\u7684\u53e2\u96c6\u5167\u90e8 IP (Internal Cluster IP) \u4f4d\u5740\uff0c\u80fd\u8b93\u53e2\u96c6\u4e2d\u7684\u7528\u6236\u7aef\u62ff\u4f86\u9023\u63a5 Service \u4e2d\u7684 Pod\u3002\u7576\u7528\u6236\u7aef\u767c\u8d77\u670d\u52d9\u9023\u7dda\u8acb\u6c42\u5230 Cluster IP \u4f4d\u5740\uff0cK8S \u7cfb\u7d71\u4fbf\u6703\u5c07\u8a72\u8acb\u6c42\u8f49\u9001\u81f3 Service \u4e2d\u7684\u67d0\u500b Pod \u4f86\u63d0\u4f9b\u670d\u52d9\u7d66\u7528\u6236\u7aef\u3002\u5176\u4e2d K8S \u652f\u63f4 Service \u7a2e\u985e\u6709\u4ee5\u4e0b\u5e7e\u7a2e: Cluster IP (\u9810\u8a2d)\u3001NodePort\u3001Load Balancer\u3001ExternalName\uff0c\u800c\u5404\u7a2e\u985e\u5225\u90fd\u5404\u81ea\u6709\u4e0d\u540c\u7684\u60c5\u5883\uff0c\u9019\u90e8\u5206\u6211\u5011\u4e4b\u5f8c\u518d\u4f86\u7d30\u90e8\u4ecb\u7d39\u3002<\/p>\n<p>\u5982\u4e0b\u5716\u6240\u793a\uff0c\u4f7f\u7528\u8005\u50c5\u9700\u5c07\u8acb\u6c42 (Request) \u50b3\u9001\u81f3 Service \u7684\u7aef\u9ede\u5730\u5740\uff0c\u8a72\u8acb\u6c42\u4fbf\u6703\u88ab\u6d3e\u767c\u81f3\u76f8\u5c0d\u61c9\u7684 Pod \u53bb\u57f7\u884c\u4f7f\u7528\u8005\u7684\u670d\u52d9\u8acb\u6c42\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8154 size-full aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-4.png\" sizes=\"auto, (max-width: 471px) 100vw, 471px\" srcset=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-4.png 471w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-4-240x300.png 240w\" alt=\"\" width=\"471\" height=\"589\" \/><\/p>\n<p>\u81f3\u65bc\u70ba\u4ec0\u9ebc\u8981\u4f7f\u7528 Service\uff1f\u56e0\u70ba\u5728 Kubernetes \u53e2\u96c6\u4e2d\uff0c\u6bcf\u500b Pod \u90fd\u6709\u5167\u90e8 IP \u4f4d\u5740\uff0c\u4f46\u90e8\u7f72\u4e2d\u7684 Pod \u6703\u8b8a\u52d5\uff0c\u5176 IP \u4f4d\u5740\u4e5f\u6703\u8b8a\u66f4\uff0c\u56e0\u6b64\uff0c\u76f4\u63a5\u4f7f\u7528 Pod IP \u4f4d\u5740\u4e26\u4e0d\u5408\u7406\u3002\u900f\u904e K8S Service\uff0c\u4f7f\u7528\u8005\u53ef\u7372\u5f97\u6301\u7e8c\u5b58\u5728\u7684\u7a69\u5b9a IP \u5730\u5740\uff0c\u751a\u81f3\u5728 Pod \u7684 IP \u4f4d\u5740\u8b8a\u66f4\u6642\u4ecd\u4e0d\u6703\u6539\u8b8a\u3002\u6b64\u5916\uff0cService \u4e5f\u80fd\u63d0\u4f9b\u8ca0\u8f09\u5e73\u8861\uff0c\u4f7f\u7528\u8005\u50c5\u9700\u5c07\u9023\u7dda\u8acb\u6c42\u50b3\u9001\u81f3\u8a72 Service IP \u4f4d\u5740\uff0c\u4f7f\u7528\u8005\u7684\u8acb\u6c42\u5c31\u6703\u5e73\u5747\u5206\u914d\u5230\u5c6c\u65bc\u670d\u52d9\u6210\u54e1\u7684 Pod \u4e4b\u9593\u3002<\/p>\n<p>\u7d93\u7531\u4ee5\u4e0a\u7684\u4ecb\u7d39\uff0c\u76f8\u4fe1\u5927\u5bb6\u5c0d\u65bc K8S \u67b6\u69cb\u53ca\u5176\u91cd\u8981\u5143\u4ef6\u6709\u4e86\u521d\u6b65\u8a8d\u8b58\u3002\u5f9e High Level \u5c64\u9762\u4f86\u770b\uff0c\u4e0b\u9762\u7684\u793a\u610f\u5716\u76f8\u4fe1\u80fd\u8b93\u5404\u4f4d\u66f4\u5b8c\u6574\u5730\u7406\u89e3 Kubernetes \u7684\u7d44\u6210\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8156 aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5-1024x641.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5-1024x641.png 1024w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5-300x188.png 300w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5-768x481.png 768w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5-600x375.png 600w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/k8s-5.png 1269w\" alt=\"\" width=\"700\" height=\"438\" \/><\/p>\n<p>\u00a0<\/p>\n<p>\u4e00\u822c\u800c\u8a00\uff0c\u81ea\u5efaK8S\u5c0d\u65bc\u7cfb\u7d71\u7ba1\u7406\u8005\u6703\u6709\u5e7e\u9805\u4e3b\u8981\u7684\u5de5\u4f5c\u8ca0\u64d4:<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 1. Cluster \u5efa\u7f6e\u8207\u5b89\u88dd\u66e0\u65e5\u5ee2\u6642\u3002<br \/>\u00a0 \u00a0 \u00a0 \u00a0 2. \u96a8\u8457\u696d\u52d9\u91cf\u7684\u589e\u9577\uff0c\u56fa\u5b9a\u8cc7\u6e90\u7684 K8S \u53e2\u96c6\u4e0d\u6613\u52d5\u614b\u4e14\u5373\u6642\u7684\u5f48\u6027\u64f4\u5145 worker node\uff0c\u5f71\u97ff\u5546\u696d\u904b\u71df\u3002<br \/>\u00a0 \u00a0 \u00a0 \u00a0 3. Node \u7570\u5e38\u6642\uff0c\u5bb9\u6613\u5c0e\u81f4\u7cfb\u7d71\u8ca0\u8f09\u904e\u91cd\uff0c\u9020\u6210\u670d\u52d9\u4e0d\u7a69\u5b9a\uff0c\u82e5\u6c92\u6709\u984d\u5916\u7dad\u6301\u4e00\u5b9a\u7a0b\u5ea6\u5197\u9918\u7684\u8cc7\u6e90\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u670d\u52d9\u4e0d\u7a69\u5b9a\uff0c\u751a\u81f3\u662f Master node \u767c\u751f\u7570\u5e38\uff0c\u7ba1\u7406\u8005\u5c31\u7121\u6cd5\u7e7c\u7e8c\u7dad\u904b\u6574\u500b\u7cfb\u7d71\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8158 aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3-1024x477.png\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" srcset=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3-1024x477.png 1024w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3-300x140.png 300w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3-768x358.png 768w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3-600x280.png 600w, https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/03\/gcp-tips-3.png 1064w\" alt=\"\" width=\"700\" height=\"326\" \/><\/p>\n<p>\u6b63\u662f\u70ba\u4e86\u63a1\u7d0d Kubernetes \u7684\u597d\u8655\u53ca\u512a\u52e2\uff0c\u4e26\u6e1b\u8f15\u7cfb\u7d71\u7ba1\u7406\u8005\u3001\u7dad\u904b\u8005\u5c0d\u65bc K8S \u53e2\u96c6\u5efa\u7f6e\u53ca\u904b\u71df\u7684\u7ba1\u7406\u8ca0\u64d4\uff0cGoogle Cloud Platform (GCP) \u96f2\u5e73\u53f0\u4e5f\u63a8\u51fa K8S \u7684\u4ee3\u7ba1\u670d\u52d9 (Managed Service)\uff0c\u7a31\u4e4b\u70ba Google Kubernetes Engine (GKE)\uff0c\u53ef\u4ee5\u8b93\u7cfb\u7d71\u7ba1\u7406\u8005\u53ca\u7dad\u904b\u8005\u7701\u53bb K8S Cluster \u5b89\u88dd\u53ca\u7dad\u8b77\u7684\u6642\u9593\uff0c\u50c5\u9700\u5e7e\u5206\u9418\uff0cGKE \u4fbf\u80fd\u5efa\u7f6e\u51fa\u4e00\u5957\u5b8c\u6574\u7684 K8S \u670d\u52d9\uff0c\u4e26\u5feb\u901f\u5e03\u5efa\u958b\u767c\u8005\u7684\u5bb9\u5668\u5316\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n<p>\u00a0<\/p>\n<p><strong>\u81f3\u65bc GKE \u670d\u52d9\u7684\u7279\u8272\u4ecb\u7d39\u53ca\u4f7f\u7528 Kubenetes \u6216 GKE \u7684\u6700\u4f73\u5be6\u8e10 (Best Practice)\uff0c\u6211\u5011\u5c07\u65bc\u5f8c\u7e8c\u6587\u7ae0\u9678\u7e8c\u4ecb\u7d39\uff0c\u656c\u8acb\u671f\u5f85\u3002<\/strong><strong>\u8acb\u6301\u7e8c\u9396\u5b9a\u00a0<a href=\"https:\/\/www.microfusion.cloud\/hk\/blog\/\">Microfusion \u5b8f\u5ead\u67b6\u69cb\u5e2b\u5c08\u6b04<\/a>\uff0c\u4ee5\u7372\u5f97\u6700\u65b0\u5c08\u696d\u8cc7\u8a0a\u5594!<\/strong><\/p>\n<p style=\"text-align: center;\">\u00a0<\/p>\n<p style=\"text-align: center;\">\u82e5\u6709\u4efb\u4f55 GCP \u9700\u6c42\uff0c\u6b61\u8fce\u8207\u6211\u5011\u806f\u7e6b!<a href=\"https:\/\/www.microfusion.cloud\/hk\/contact\/\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/mf-web-plugin-hk.storage.googleapis.com\/wp-content\/uploads\/2020\/02\/%E8%81%AF%E7%B5%A1%E6%88%91%E5%80%91.png\" alt=\"\" width=\"185\" height=\"103\" \/><\/a><\/p>\n<p><iframe loading=\"lazy\" style=\"border: none; overflow: hidden;\" src=\"https:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fpg%2FMicrofusionTechnology%2Fposts%2F%3Fref%3Dpage_internal&amp;width=450&amp;layout=standard&amp;action=like&amp;size=small&amp;share=true&amp;height=35&amp;appId\" width=\"450\" height=\"35\" frameborder=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u65bc K8S \u548c GKE \u529f\u80fd\u5df2\u76f8\u7576\u5b8c\u6574\uff0c\u5f8c\u7e8c\u6703\u5c07\u91cd\u8981\u67b6\u69cb\u89c0\u5ff5\u3001\u6700\u5e38\u4f7f\u7528\u5230\u7684\u670d\u52d9\u529f\u80fd\u4ee5\u53ca\u6700\u4f73\u5be6\u8e10 (Best practice) \u5448\u73fe\u5728\u7cfb\u5217\u6587\u7ae0\u4e2d\uff0c\u5e0c\u671b\u8b93\u60a8\u5c0d K8S \u53ca GKE \u6709\u66f4\u6df1\u7684\u8a8d\u8b58\u3002\u672c\u7bc7\u6703\u4ecb\u7d39 Kubernetes \u7684\u91cd\u8981\u57fa\u672c\u89c0\u5ff5\u3001Kubernetes \u7684\u61c9\u7528\u7a0b\u5f0f\u76f8\u95dc\u5143\u4ef6\uff0c\u4ee5\u53ca\u63d0\u4f9b\u5916\u90e8\u4f7f\u7528\u7684 K8S \u5143\u4ef6\u3002<\/p>\n","protected":false},"author":3,"featured_media":7826,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[173],"tags":[172],"class_list":["post-7813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical_gcp","tag-gcp"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/posts\/7813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/comments?post=7813"}],"version-history":[{"count":32,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/posts\/7813\/revisions"}],"predecessor-version":[{"id":20397,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/posts\/7813\/revisions\/20397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/media\/7826"}],"wp:attachment":[{"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/media?parent=7813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/categories?post=7813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.microfusion.cloud\/hk\/wp-json\/wp\/v2\/tags?post=7813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}