{"id":16730,"date":"2024-11-27T10:10:59","date_gmt":"2024-11-27T02:10:59","guid":{"rendered":"https:\/\/92it.top\/?p=16730"},"modified":"2024-11-27T10:10:59","modified_gmt":"2024-11-27T02:10:59","slug":"docker%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9fk8s%e5%8f%88%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e4%bb%8e0%e5%88%b01%e5%ae%9e%e6%88%98docker%e4%b8%8ek8s%e5%85%a8%e6%b5%81%e7%a8%8b%e9%83%a8","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=16730","title":{"rendered":"Docker\u662f\u4ec0\u4e48\uff1fK8s\u53c8\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4ece0\u52301\u5b9e\u6218Docker\u4e0eK8s\u5168\u6d41\u7a0b\u90e8\u7f72\uff1f"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/mp.weixin.qq.com\/s?__biz=MzIwNDAyOTI2Nw==&amp;mid=2247500706&amp;idx=1&amp;sn=9bca65dc466ac5862d544f5be510a3d9&amp;chksm=96c4ef9ea1b366889ada813062dd0e517f5cea96b0407b26d8b9dedfb2f207055220b213ce95&amp;cur_album_id=2818595943724974083&amp;scene=190#rd\">Docker\u662f\u4ec0\u4e48\uff1fK8s\u53c8\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4ece0\u52301\u5b9e\u6218Docker\u4e0eK8s\u5168\u6d41\u7a0b\u90e8\u7f72\uff1f<\/a><\/p>\n\n\n\n<p>\u4e91\u539f\u751f\u65f6\u4ee3\uff0c\u4f5c\u4e3a\u6280\u672f\u4eba\u5458\uff0c\u5982\u679c\u4e0d\u4e86\u89e3 Docker \u548c Kubernetes\uff0c\u90a3\u7edd\u5bf9\u662f\u6280\u672f\u6808\u4e0a\u7684\u4e00\u4e2a\u77ed\u677f\u3002\u90a3\u4e48\uff0c\u4ec0\u4e48\u662f Docker\uff1f\u4ec0\u4e48\u53c8\u662f Kubernetes\uff1f\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u600e\u6837\u7684\u5173\u7cfb\uff1f\u8fd9\u7bc7\u6587\u7ae0\uff0c\u6211\u5c06\u901a\u8fc7\u7406\u8bba\u52a0\u4ee3\u7801\u5b9e\u6218\u7684\u65b9\u5f0f\uff0c\u8be6\u7ec6\u5730\u5256\u6790\u4ed6\u4eec\u3002<\/p>\n\n\n\n<p><strong>1. \u539f\u7406\u90e8\u5206<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>1.1 Docker<\/strong><\/p>\n\n\n\n<p>Docker\u662f\u4e00\u4e2a\u5bb9\u5668\u5316\u5e73\u53f0\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u5e94\u7528\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u5230\u4e00\u4e2a\u79f0\u4e3a\u5bb9\u5668\u7684\u6807\u51c6\u5316\u5355\u5143\u4e2d\uff0c\u4ee5\u4fbf\u53ef\u4ee5\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u5feb\u901f\u3001\u53ef\u9760\u5730\u8fd0\u884c\u8fd9\u4e9b\u5e94\u7528\u3002\u5b83\u7684\u672c\u8d28\u662f\u5229\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684<code>Cgroups<\/code>\u548c<code>Namespace<\/code>\u673a\u5236\u521b\u5efa\u51fa\u6765\u7684\u9694\u79bb\u73af\u5883\u3002\u66f4\u591a\u8be6\u60c5\u53c2\u8003\u6211\u4ee5\u5f80\u7684\u6587\u7ae0\uff1a\u5bb9\u5668 = Namespace + Cgroups + rootfs<\/p>\n\n\n\n<p>Docker\u6838\u5fc3\u6982\u5ff5\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\uff1a<\/p>\n\n\n\n<p><strong>1.1.1 Kubernetes\u6838\u5fc3\u6982\u5ff5<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>1. \u955c\u50cf<\/strong>\uff1aDocker\uff08Image\uff09\u955c\u50cf\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u3001\u72ec\u7acb\u3001\u53ef\u6267\u884c\u7684\u8f6f\u4ef6\u5305\uff0c\u5176\u4e2d\u5305\u542b\u8fd0\u884c\u67d0\u4e2a\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u5185\u5bb9\uff0c\u5305\u62ec\u4ee3\u7801\u3001\u8fd0\u884c\u65f6\u3001\u5e93\u3001\u73af\u5883\u53d8\u91cf\u548c\u914d\u7f6e\u6587\u4ef6\u3002\u955c\u50cf\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u57fa\u4e8e\u955c\u50cf\u53ef\u4ee5\u521b\u5efa\u5bb9\u5668\u3002<\/li>\n\n\n\n<li><strong>2. \u5bb9\u5668<\/strong>\uff1a\u5bb9\u5668\uff08Container\uff09\u662f\u955c\u50cf\u7684\u8fd0\u884c\u5b9e\u4f8b\uff0c\u5b83\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u3001\u72ec\u7acb\u7684\u73af\u5883\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u652f\u6301 Docker\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u3002\u5bb9\u5668\u4e0e\u4e3b\u673a\u7cfb\u7edf\u5171\u4eab\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\uff0c\u4f46\u5728\u8fdb\u7a0b\u7a7a\u95f4\u4e0a\u662f\u9694\u79bb\u7684\u3002<\/li>\n\n\n\n<li><strong>3. Dockerfile<\/strong>\uff1aDockerfile\u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u5305\u542b\u6784\u5efa Docker\u955c\u50cf\u7684\u6240\u6709\u547d\u4ee4\uff0c\u53ef\u4ee5\u901a\u8fc7 Dockerfile\u6765\u81ea\u52a8\u5316\u955c\u50cf\u7684\u521b\u5efa\u8fc7\u7a0b\u3002<\/li>\n\n\n\n<li><strong>4. Docker Hub<\/strong>\uff1aDocker Hub\u662f\u4e00\u4e2a\u4e91\u7aef\u7684 Docker\u955c\u50cf\u5b58\u50a8\u5e93\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u4e0a\u9762\u53d1\u5e03\u548c\u83b7\u53d6\u955c\u50cf\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5e73\u53f0\u6765\u5171\u4eab\u548c\u7ba1\u7406\u955c\u50cf\u3002<\/li>\n\n\n\n<li><strong>5. \u5bb9\u5668\u7f16\u6392<\/strong>\uff1aDocker Compose\u662f\u4e00\u79cd\u5b9a\u4e49\u548c\u8fd0\u884c\u591a\u5bb9\u5668 Docker\u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u5177\uff0c\u901a\u8fc7\u4e00\u4e2a<code>docker-compose.yml<\/code>\u6587\u4ef6\uff0c\u7528\u6237\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5e94\u7528\u5305\u542b\u7684\u6240\u6709\u670d\u52a1\uff0c\u5e76\u4f7f\u7528\u7b80\u5355\u7684\u547d\u4ee4\u542f\u52a8\u6216\u505c\u6b62\u5b83\u4eec\u3002<\/li>\n<\/ul>\n\n\n\n<p>Docker\u5bb9\u5668\u53ef\u4ee5\u63cf\u8ff0\u6210\u4ee5\u4e0b\u5168\u666f\u56fe\uff08\u56fe\u7247\u6765\u81ea\u6781\u5ba2\u5f20\u78ca\uff09\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"620\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-1024x620.png\" alt=\"\" class=\"wp-image-16732\" style=\"width:422px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-1024x620.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-300x182.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-768x465.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-830x502.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-230x139.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-350x212.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185-480x290.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-185.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>1.1.2 Docker\u7684\u4f18\u70b9<\/strong><\/p>\n\n\n\n<p>Docker\u7684\u4f18\u70b9\u53ef\u4ee5\u7528\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a<code>\u4e00\u6b21\u6253\u5305\uff0c\u5230\u5904\u90e8\u7f72<\/code>\u3002\u8fd9\u4e2a\u548c JVM<code>\u4e00\u6b21\u7f16\u8bd1\uff0c\u5230\u5904\u8fd0\u884c<\/code>\u7684\u8bbe\u8ba1\u6709\u7740\u5f02\u66f2\u540c\u5de5\u4e4b\u5999\uff0c\u6240\u4ee5\u8bf4\uff0c\u8ba1\u7b97\u673a\u9886\u57df\u5f88\u591a\u601d\u7ef4\u662f\u76f8\u901a\u7684\uff01<\/p>\n\n\n\n<p>\u4e0b\u56fe\u5bf9\u6bd4\u4e86\u4f7f\u7528\u4e0e\u4e0d\u4f7f\u7528 Docker\u7684\u573a\u666f\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"673\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-1024x673.png\" alt=\"\" class=\"wp-image-16734\" style=\"width:412px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-1024x673.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-300x197.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-768x505.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-830x546.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-230x151.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-350x230.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187-480x316.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-187.png 1028w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<ul>\n<li>\u4e0d\u4f7f\u7528 Docker\uff1a\u6bcf\u6b21\u5c06\u5e94\u7528\u90e8\u7f72\u65b0\u4e3b\u673a\u65f6\uff0c\u90fd\u9700\u8981\u91cd\u65b0\u5b89\u88c5\u4e00\u904d\u5e94\u7528\u9700\u8981\u7684\u73af\u5883\uff0c\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u591a\uff0c\u8fd0\u8425\u5546\u53ef\u80fd\u4e5f\u4e0d\u540c\uff0c\u5b89\u88c5\u73af\u5883\u662f\u4e00\u4ef6\u75db\u82e6\u7684\u4e8b\u60c5\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 Docker\uff1a\u5236\u4f5c Docker\u955c\u50cf\u65f6\uff0c\u5df2\u7ecf\u5305\u542b\u5e94\u7528\u53ca\u5176\u6240\u9700\u7684\u73af\u5883\uff0c\u56e0\u6b64\u53ef\u4ee5\u5230\u4efb\u4f55\u8fd0\u8425\u5546\u63d0\u4f9b\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>1.2 Kubernetes<\/strong><\/p>\n\n\n\n<p>K<strong>ubernete<\/strong>s\uff08K8s\uff09 \u4e00\u8bcd\u6e90\u81ea\u5e0c\u814a\uff0c\u610f\u4e3a\u201c\u8235\u624b\u201d\u6216\u201c\u638c\u8235\u8005\u201d\uff0c\u7528\u4e8e\u6307\u5bfc\u548c\u7ba1\u7406\u8239\u53ea\u7684\u822a\u884c\u3002\u5b83\u662f\u4e00\u4e2a\u5bb9\u5668\u7f16\u6392\u5e73\u53f0\uff0c\u8d1f\u8d23\u81ea\u52a8\u5316\u5bb9\u5668\u7684\u90e8\u7f72\u3001\u6269\u5c55\uff08\u6c34\u5e73\u6269\u5c55\uff09\u3001\u8d1f\u8f7d\u5747\u8861\u3001\u4ee5\u53ca\u6545\u969c\u6062\u590d\u7b49\u5de5\u4f5c\u3002<\/p>\n\n\n\n<p>Kubernetes\u7684\u6838\u5fc3\u6982\u5ff5\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\uff1a<\/p>\n\n\n\n<p><strong>1.2.1 Kubernetes\u6838\u5fc3\u6982\u5ff5<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>1. \u8282\u70b9<\/strong>\uff1a\u8282\u70b9\uff08Node\uff09\u662f Kubernetes\u96c6\u7fa4\u4e2d\u7684\u4e00\u53f0\u7269\u7406\u673a\u6216\u865a\u62df\u673a\uff0c\u8d1f\u8d23\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u4f5c\u8d1f\u8f7d\u3002\u6bcf\u4e2a\u8282\u70b9\u8fd0\u884c\u4e00\u4e2aKubelet\uff08\u7528\u4e8e\u7ba1\u7406\u8282\u70b9\u4e0a\u7684\u5bb9\u5668\uff09\u548c\u4e00\u4e2a\u5bb9\u5668\u8fd0\u884c\u65f6\uff08\u4f8b\u5982Docker\uff09\u3002<\/li>\n\n\n\n<li><strong>2. Pod<\/strong>\uff1aPod\u662f Kubernetes\u4e2d\u6700\u5c0f\u7684\u53ef\u90e8\u7f72\u5355\u5143\uff0c\u901a\u5e38\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u5bb9\u5668\u3002Pod\u4e2d\u7684\u5bb9\u5668\u5171\u4eab\u7f51\u7edc\u548c\u5b58\u50a8\uff0c\u53ef\u4ee5\u534f\u540c\u5de5\u4f5c\u3002<\/li>\n\n\n\n<li><strong>3. \u63a7\u5236\u5668<\/strong>\uff1a\u63a7\u5236\u5668\uff08Controller\uff09\u8d1f\u8d23\u7ba1\u7406\u548c\u7ef4\u62a4\u96c6\u7fa4\u4e2d\u7684Pod\u548c\u76f8\u5173\u7684\u670d\u52a1\u3002\u5e38\u89c1\u7684\u63a7\u5236\u5668\u6709 ReplicaSet\uff08\u786e\u4fdd\u6307\u5b9a\u6570\u91cf\u7684Pod\u526f\u672c\u5728\u8fd0\u884c\uff09\u3001Deployment\uff08\u7ba1\u7406\u65e0\u72b6\u6001\u5e94\u7528\uff09\u548c StatefulSet\uff08\u7ba1\u7406\u6709\u72b6\u6001\u5e94\u7528\uff09\u3002<\/li>\n\n\n\n<li><strong>4. \u670d\u52a1<\/strong>\uff1a\u670d\u52a1\uff08Service\uff09\u662f\u4e00\u4e2a\u62bd\u8c61\u7684\u65b9\u5f0f\uff0c\u7528\u4e8e\u5b9a\u4e49\u4e00\u7ec4Pod\u7684\u903b\u8f91\u96c6\u5408\u4ee5\u53ca\u8bbf\u95ee\u8fd9\u4e9b Pod\u7684\u7b56\u7565\u3002Kubernetes\u4e2d\u7684\u670d\u52a1\u63d0\u4f9b\u4e86\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>5. \u547d\u540d\u7a7a\u95f4<\/strong>\uff1a\u547d\u540d\u7a7a\u95f4\uff08Namespace\uff09\u7528\u4e8e\u5728\u540c\u4e00\u4e2a Kubernetes\u96c6\u7fa4\u4e2d\u5c06\u8d44\u6e90\u8fdb\u884c\u903b\u8f91\u4e0a\u7684\u9694\u79bb\u3002\u5b83\u5141\u8bb8\u591a\u4e2a\u56e2\u961f\u6216\u9879\u76ee\u5171\u4eab\u4e00\u4e2a\u96c6\u7fa4\u800c\u4e0d\u4f1a\u76f8\u4e92\u5f71\u54cd\u3002<\/li>\n\n\n\n<li><strong>6. \u914d\u7f6e\u7ba1\u7406<\/strong>\uff1a\u914d\u7f6e\u7ba1\u7406\u5305\u542b ConfigMap \u548c Secret\u3002ConfigMap \u7528\u4e8e\u5b58\u50a8\u975e\u673a\u5bc6\u7684\u6570\u636e\uff0c\u7c7b\u4f3c\u914d\u7f6e\u6587\u4ef6\u3002Secret\u7528\u4e8e\u5b58\u50a8\u673a\u5bc6\u6570\u636e\uff0c\u5982\u5bc6\u7801\u3001OAuth\u4ee4\u724c\u548cSSH\u5bc6\u94a5\u3002<\/li>\n\n\n\n<li><strong>7. Ingress<\/strong>\uff1aIngress\u662f\u4e00\u4e2a API\u5bf9\u8c61\uff0c\u7ba1\u7406\u5916\u90e8\u8bbf\u95ee\u5230\u96c6\u7fa4\u4e2d\u670d\u52a1\u7684 HTTP\u548c HTTPS\u8def\u7531\u3002\u5b83\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\u3001SSL\u7ec8\u6b62\u548c\u57fa\u4e8e\u540d\u79f0\u7684\u865a\u62df\u6258\u7ba1\u7b49\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>8. Deployment<\/strong>\uff1aDeployment\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u65e0\u72b6\u6001\u5e94\u7528\u7a0b\u5e8f\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u58f0\u660e\u5f0f\u7684\u65b9\u6cd5\u6765\u7ba1\u7406 Pod\u548c ReplicaSet\uff0c\u4ece\u800c\u5b9e\u73b0\u5e94\u7528\u7a0b\u5e8f\u7684\u90e8\u7f72\u3001\u5347\u7ea7\u548c\u6269\u7f29\u3002<\/li>\n<\/ul>\n\n\n\n<p>Kubernetes\u53ef\u4ee5\u63cf\u8ff0\u6210\u4ee5\u4e0b\u5168\u666f\u56fe\uff08\u56fe\u7247\u6765\u81ea\u6781\u5ba2\u5f20\u78ca\uff09\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"562\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-1024x562.png\" alt=\"\" class=\"wp-image-16736\" style=\"width:510px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-1024x562.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-300x165.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-768x421.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-830x455.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-350x192.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189-480x263.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-189.png 1046w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>1.2.2 Kubernetes \u7684\u5de5\u4f5c\u6d41\u7a0b<\/strong><\/p>\n\n\n\n<p>Kubernetes \u7684\u6574\u4f53\u5de5\u4f5c\u6d41\u7a0b\u53ef\u4ee5\u603b\u7ed3\u6210\u4e0b\u9762 6\u4e2a\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ol>\n<li><strong>\u7528\u6237\u5b9a\u4e49\u548c\u63d0\u4ea4\u6587\u4ef6<\/strong>\uff1a\u7528\u6237\u901a\u8fc7 kubectl\u63d0\u4ea4\u63cf\u8ff0\u6587\u4ef6\uff0c\u4f8b\u5982 Deployment \u548c Service \u5b9a\u4e49\uff0c\u8fd9\u4e9b\u6587\u4ef6\u63cf\u8ff0\u4e86\u5e94\u7528\u526f\u672c\u6570\u91cf\u3001\u8d1f\u8d23\u9009\u62e9\u8d1f\u8f7d\u5747\u8861\u7684\u6807\u7b7e\u3001\u8d44\u6e90\u9700\u6c42\u7b49\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>API Server \u63a5\u53d7\u8bf7\u6c42<\/strong>\uff1aAPI Server\u5904\u7406\u7528\u6237\u7684\u5bf9\u8c61\u521b\u5efa\u8bf7\u6c42\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u4f1a\u88ab\u8bb0\u5f55\u5728 etcd \u4e2d\u3002<\/li>\n\n\n\n<li><strong>\u8c03\u5ea6\u5668\u51b3\u5b9a Pod \u7684\u4f4d\u7f6e<\/strong>\uff1aScheduler\u6839\u636e\u96c6\u7fa4\u7684\u6574\u4f53\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3001\u8282\u70b9\u5065\u5eb7\u72b6\u51b5\u3001Pod \u7684\u8d44\u6e90\u8981\u6c42\u7b49\u8c03\u5ea6\u7b56\u7565\uff0c\u5c06 Pod\u5b89\u6392\u5230\u96c6\u7fa4\u4e2d\u7684\u67d0\u4e2a Node\u4e0a\u3002<\/li>\n\n\n\n<li><strong>Kubelet \u5904\u7406\u5e76\u8fd0\u884cPod<\/strong>\uff1a\u5728\u9009\u5b9a\u7684 Node\u4e0a\uff0cKubelet\u8c03\u7528 Container Runtime\uff08\u4f8b\u5982 Docker \u6216 Container\uff09\u542f\u52a8\u5bb9\u5668\uff0c\u5e76\u6839\u636e\u8bf7\u6c42\u7684\u89c4\u683c\u62c9\u53d6\u955c\u50cf\u3001\u5206\u914d\u8d44\u6e90\u3001\u542f\u52a8\u5e94\u7528\u3002<\/li>\n\n\n\n<li><strong>Kube Proxy \u5b9e\u73b0\u670d\u52a1\u8bbf\u95ee<\/strong>\uff1a\u96c6\u7fa4\u4e2d\u7684 Kube Proxy\u8d1f\u8d23\u4e3a\u6bcf\u4e2a Pod\u751f\u6210\u865a\u62df IP\uff0c\u901a\u8fc7\u8fd9\u4e9b IP\uff0c\u96c6\u7fa4\u5185\u5916\u90e8\u7684\u8bbf\u95ee\u53ef\u4ee5\u901a\u8fc7 Kubernetes Services \u6765\u8bbf\u95ee\u8fd9\u4e9b Pod\uff0c\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002<\/li>\n\n\n\n<li><strong>\u72b6\u6001\u4fdd\u6301\u548c\u81ea\u52a8\u4fee\u590d<\/strong>\uff1aKubernetes\u7684\u63a7\u5236\u5668\u4f1a\u6301\u7eed\u76d1\u63a7 Pod\u548c\u8282\u70b9\u7684\u72b6\u6001\uff0c\u5e76\u5728\u68c0\u6d4b\u5230\u67d0\u4e9b Pod\u4e0d\u53ef\u7528\u6216\u8282\u70b9\u5931\u6548\u65f6\uff0c\u81ea\u52a8\u91cd\u542f\u6216\u8c03\u5ea6\u65b0\u7684 Pod\u5230\u5065\u5eb7\u7684\u8282\u70b9\u4e0a\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6574\u4e2a\u6d41\u7a0b\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"624\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-1024x624.png\" alt=\"\" class=\"wp-image-16738\" style=\"width:432px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-1024x624.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-300x183.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-768x468.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-830x506.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-230x140.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-350x213.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191-480x293.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-191.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>1.3 \u4e24\u8005\u5173\u7cfb<\/strong><\/p>\n\n\n\n<p>Docker\u63d0\u4f9b\u5bb9\u5668\u5316\u673a\u5236\uff0c\u7528\u4e8e\u5c01\u88c5\u548c\u6253\u5305\u5e94\u7528\uff0c\u5e76\u5229\u7528 CI\/CD\u7ba1\u9053\u5c06\u5bb9\u5668\u955c\u50cf\u63a8\u9001\u81f3\u4e2d\u592e\u5bb9\u5668\u6ce8\u518c\u4e2d\u5fc3\uff08\u5982 Docker Hub \u6216 Harbor\uff09\uff0c\u800c Kubernetes\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5bb9\u5668\u7f16\u6392\u5e73\u53f0\uff0c\u8d1f\u8d23\u8c03\u5ea6\u3001\u6269\u5c55\u548c\u7ba1\u7406 Docker\u5bb9\u5668\u5316\u5e94\u7528\uff0c\u4fdd\u8bc1\u7cfb\u7edf\u9ad8\u53ef\u7528\u3001\u6545\u969c\u81ea\u52a8\u6062\u590d\u3002<\/p>\n\n\n\n<p>\u4ece\u5b8f\u89c2\u4e0a\u770b\uff0c\u4e24\u8005\u5173\u7cfb\u53ef\u4ee5\u901a\u8fc7\u4e0b\u56fe\u6765\u5f62\u8c61\u7684\u8868\u8fbe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"362\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-1024x362.png\" alt=\"\" class=\"wp-image-16740\" style=\"width:528px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-1024x362.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-300x106.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-768x272.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-830x294.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-230x81.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-350x124.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193-480x170.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-193.png 1074w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u597d\u4e86\uff0c\u7406\u8bba\u90e8\u5206\u8bb2\u89e3\u5b8c\u540e\uff0c\u6211\u4eec\u6b63\u5f0f\u8fdb\u5165\u4ee3\u7801\u5b9e\u6218\u90e8\u5206\uff0c\u4fd7\u8bdd\u8bf4\uff1a\u8bf4\u8d77\u6765\u5bb9\u6613\u505a\u8d77\u6765\u96be\uff0c\u5bf9\u4e8e Kubernetes\u96c6\u7fa4\u8fd8\u771f\u6709\u70b9\u96be\u5ea6\uff0c\u6765\uff0c\u4e0a\u5e72\u8d27\uff01\uff01\uff01<\/p>\n\n\n\n<p><strong>2. \u4ee3\u7801\u5b9e\u6218<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>2.1 \u76ee\u7684<\/strong><\/p>\n\n\n\n<p>\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684 Java Web\u5e94\u7528\uff0c\u5e76\u5c06\u5176 Docker\u5bb9\u5668\u5316\u90e8\u7f72\u5230 Kubernetes\u96c6\u7fa4\u4e2d\uff0c\u7136\u540e\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee\uff0c\u5c55\u793a\uff1a<code>Hello world, This is my docker running in Kubernetes!<\/code>\u3002<\/p>\n\n\n\n<p><strong>2.2 \u6b65\u9aa4<\/strong><\/p>\n\n\n\n<p>\u6574\u4f53\u6d41\u7a0b\u6838\u5fc3\u6b65\u9aa4\u6709\u4e0b\u9762 4\u4e2a\uff1a<\/p>\n\n\n\n<ol>\n<li>\u5b89\u88c5\u73af\u5883<\/li>\n\n\n\n<li>\u521b\u5efa Web\u5e94\u7528<\/li>\n\n\n\n<li>\u5e94\u7528 Docker \u5bb9\u5668\u5316<\/li>\n\n\n\n<li>\u90e8\u7f72\u5230 Kubernetes \u96c6\u7fa4<\/li>\n\n\n\n<li>\u6d4f\u89c8\u5668\u9a8c\u8bc1<\/li>\n<\/ol>\n\n\n\n<p><strong>2.2.1 \u5b89\u88c5\u73af\u5883<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u6211\u4eec\u5b89\u88c5\u4e86\u4ee5\u4e0b\u73af\u5883\uff1aJDK\uff08Java Development Kit\uff09\uff0c Gradle(Maven)\uff0cDocker\uff0c Kubernetes\uff0c\u4e0b\u9762\u662f\u6211\u5b89\u88c5\u7684\u7248\u672c\uff1a<\/p>\n\n\n\n<p>JDK \u7248\u672c\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"176\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-1024x176.png\" alt=\"\" class=\"wp-image-16741\" style=\"width:582px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-1024x176.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-300x52.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-768x132.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-830x143.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-230x40.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-350x60.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194-480x82.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-194.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>Gradle\u7248\u672c\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"439\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-1024x439.png\" alt=\"\" class=\"wp-image-16743\" style=\"width:566px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-1024x439.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-300x129.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-768x329.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-830x356.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-230x99.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-350x150.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196-480x206.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-196.png 1092w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>Docker \u7248\u672c\uff1a\u6211\u4f7f\u7528\u7684\u662f Mac Pro \u7535\u8111\uff0c\u76f4\u63a5\u4f7f\u7528 brew\u5b89\u88c5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">brew install --cask docker<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-1024x242.png\" alt=\"\" class=\"wp-image-16744\" style=\"width:566px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-1024x242.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-300x71.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-768x181.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-830x196.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-230x54.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-350x83.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197-480x113.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-197.png 1092w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>Kubernetes \u7248\u672c\uff1a<\/p>\n\n\n\n<p>\u6211\u4f7f\u7528\u7684\u662f Mac Pro\u7535\u8111\uff0c\u76f4\u63a5\u4f7f\u7528 brew\u5b89\u88c5\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">brew install kubectl<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-1024x211.png\" alt=\"\" class=\"wp-image-16746\" style=\"width:558px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-1024x211.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-300x62.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-768x158.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-830x171.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-230x47.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-350x72.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199-480x99.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-199.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u6ce8\u610f\uff1aGradle \u548c Maven \u662f\u9879\u76ee\u7ba1\u7406\u5de5\u5177\uff0c\u53ea\u8981\u5b89\u88c5\u4e00\u4e2a\u5c31OK\uff0c\u81ea\u5df1\u719f\u6089\u54ea\u4e2a\u5c31\u5b89\u88c5\u54ea\u4e2a\u3002<\/p>\n\n\n\n<p><strong>2.2.2 \u521b\u5efaJava Web\u5e94\u7528<\/strong><\/p>\n\n\n\n<p><strong>1. \u521b\u5efaGradle(Maven)\u9879\u76ee<\/strong><\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a Springboot \u9879\u76ee\uff0c\u6574\u4e2a\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"464\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-1024x464.png\" alt=\"\" class=\"wp-image-16747\" style=\"width:448px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-1024x464.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-300x136.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-768x348.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-830x376.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-230x104.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-350x159.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200-480x218.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-200.png 1112w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5728<code>src\/main\/cloud\/com\/yuanjava\/docker<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Java\u7c7b\uff0c\u5982<code>HelloController.java<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package com.yuanjava.docker;\n\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\/**\n * @author \u733fjava\n *\/\n@RestController\npublic class HelloController {\n   @GetMapping(\"\/test\")\n   public String test() {\n      return \"Hello world, This is my docker running in Kubernetes!\";\n   }\n}<\/pre>\n\n\n\n<p><strong>2. Gradle(Maven)\u6253\u5305\u9879\u76ee<\/strong>:<\/p>\n\n\n\n<p>Gradle\u6253\u5305\u6307\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">gradle build<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u5728 build\/libs \u76ee\u5f55\u4e0b\u5c31\u5c31\u4f1a\u770b\u5230\u6253\u5305\u540e\u7684 jar\u5305\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"380\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-1024x380.png\" alt=\"\" class=\"wp-image-16748\" style=\"width:506px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-1024x380.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-300x111.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-768x285.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-830x308.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-230x85.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-350x130.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201-480x178.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-201.png 1100w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>2.2.3 \u5bb9\u5668\u5316 Java Web\u5e94\u7528<\/strong><\/p>\n\n\n\n<p><strong>1. \u7f16\u5199Dockerfile<\/strong>:<\/p>\n\n\n\n<p>\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>Dockerfile<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">FROM openjdk:17-jdk-slim\nCOPY build\/libs\/yuanjava-1.0.jar app.jar\nENTRYPOINT [\"java\",\"-jar\",\"\/app.jar\"]<\/pre>\n\n\n\n<p><strong>2. \u6784\u5efaDocker\u955c\u50cf<\/strong>:<\/p>\n\n\n\n<p>\u5728\u5f53\u524d\u76ee\u5f55\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c31\u53ef\u4ee5\u6784\u5efa Docker\u955c\u50cf\uff0c<code>-t<\/code>\u7684\u4f5c\u7528\u662f\u7ed9\u8fd9\u4e2a\u955c\u50cf\u52a0\u4e00\u4e2aTag\uff0c\u4e5f\u5c31\u662f\u8d77\u4e00\u4e2a\u597d\u542c\u7684\u540d\u5b57\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker build -t yuanjava:1.0 .<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"657\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-1024x657.png\" alt=\"\" class=\"wp-image-16750\" style=\"width:492px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-1024x657.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-300x193.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-768x493.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-830x533.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-230x148.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-350x225.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203-480x308.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-203.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u8fd0\u884c\u5b8c\u4e0a\u9762\u7684\u6307\u4ee4\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5728 Docker\u955c\u50cf\u5e93\u770b\u5230\u521a\u624d\u6253\u7684\u955c\u50cf\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528<code>docker images<\/code>\u6307\u4ee4\u67e5\u770b\u955c\u50cf\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker images<\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7 Docker\u7684\u53ef\u89c6\u5316\u5de5\u5177\u67e5\u770b\u955c\u50cf\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"451\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-1024x451.png\" alt=\"\" class=\"wp-image-16752\" style=\"width:514px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-1024x451.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-300x132.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-768x338.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-830x366.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-230x101.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-350x154.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205-480x211.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-205.png 1090w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>3. \u8fd0\u884cDocker\u5bb9\u5668<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u542f\u52a8 Docker\u5bb9\u5668\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run -p 9999:9999 yuanjava:1.0<\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee<code>http:\/\/localhost:9999\/test<\/code>\u6765\u6d4b\u8bd5 Docker\u662f\u5426\u542f\u52a8\u5b8c\u6210\u3002\u8bbf\u95ee\u7ed3\u679c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"217\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-1024x217.png\" alt=\"\" class=\"wp-image-16753\" style=\"width:530px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-1024x217.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-300x64.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-768x163.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-830x176.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-230x49.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-350x74.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206-480x102.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-206.png 1114w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>4. \u63a8\u9001 Docker\u955c\u50cf\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u4e0b\u9762\u5c06 Docker\u955c\u50cf\u90e8\u7f72\u5230 Kubernetes\u96c6\u7fa4\u505a\u51c6\u5907\uff0c\u63a8\u9001\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker push yuanjava:1.0<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"293\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-1024x293.png\" alt=\"\" class=\"wp-image-16754\" style=\"width:550px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-1024x293.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-300x86.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-768x220.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-830x237.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-230x66.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-350x100.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207-480x137.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-207.png 1084w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u63a8\u9001\u5b8c\u4e4b\u540e\uff0c\u8fdc\u7a0b\u4ed3\u5e93\u5c31\u591a\u4e86\u4e00\u4e2a\u955c\u50cf\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"419\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-1024x419.png\" alt=\"\" class=\"wp-image-16755\" style=\"width:568px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-1024x419.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-300x123.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-768x314.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-830x339.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-230x94.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-350x143.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208-480x196.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-208.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u6ce8\u610f\uff1a\u5982\u679c\u6ca1\u6709 Docker\u8d26\u53f7\uff0c\u9700\u8981\u5148\u521b\u5efa\u8d26\u53f7\u3002<\/p>\n\n\n\n<p><strong>2.2.4 \u90e8\u7f72\u5230Kubernetes\u96c6\u7fa4<\/strong><\/p>\n\n\n\n<p><strong>1. \u542f\u52a8 Kubernetes\u96c6\u7fa4<\/strong><\/p>\n\n\n\n<p>\u901a\u5e38\u6765\u8bf4\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528<code>minikube<\/code>\u547d\u4ee4\u6765\u542f\u52a8\u548c\u7ba1\u7406 Kubernetes \u96c6\u7fa4\uff0c\u5b89\u88c5\u548c\u542f\u52a8\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u5b89\u88c5 minikube\ncurl -Lo minikube https:\/\/storage.googleapis.com\/minikube\/releases\/latest\/minikube-linux-amd64\nchmod +x minikube\nsudo mv minikube \/usr\/local\/bin\/\n\n# \u542f\u52a8 Kubernetes\u96c6\u7fa4\nminikube start<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"529\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-1024x529.png\" alt=\"\" class=\"wp-image-16757\" style=\"width:576px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-1024x529.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-300x155.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-768x397.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-830x429.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-230x119.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-350x181.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210-480x248.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-210.png 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>2. \u7f16\u5199Kubernetes Deployment\u914d\u7f6e<\/strong><\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a<code>deployment.yaml<\/code>\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: apps\/v1 # \u5b9a\u4e49\u4e86 Kubernetes API \u7684\u7248\u672c\nkind: Deployment    # \u58f0\u660e\u8fd9\u4e2a Kubernetes \u8d44\u6e90\u7684\u7c7b\u578b\nmetadata:\n name: yuanjava     # \u5305\u542b\u8d44\u6e90\u7684\u5143\u6570\u636e\uff0cKubernetes \u901a\u8fc7 metadata \u5b57\u6bb5\u4e2d\u7684\u5404\u7c7b\u4fe1\u606f\u6765\u8ddf\u8e2a\u548c\u7ba1\u7406\u8d44\u6e90\nspec:\n replicas: 2       # Pod\u7684\u526f\u672c\u6570\u91cf\uff0c\u5373 Deployment\u5c06\u8fd0\u884c 2\u4e2a\u76f8\u540c\u7684 Pod\n selector:\n   matchLabels:\n     app: yuanjava # \u544a\u8bc9 Deployment \u5982\u4f55\u627e\u5230\u5b83\u7ba1\u7406\u7684 Pod\n template:\n   metadata:\n     labels:\n       app: yuanjava # \u5b9a\u4e49 Pod \u7684\u6a21\u677f\n   spec:\n     containers:\n     - name: yuanjava\n       image: yuanjava\/yuanjava:1.0 #\u5b9a\u4e49\u5bb9\u5668\u4f7f\u7528\u7684\u955c\u50cf\uff0cKubernetes \u4f1a\u4ece\u5bb9\u5668\u955c\u50cf\u4ed3\u5e93\u4e2d\u62c9\u53d6\u5b83\n       ports:\n       - containerPort: 9999     # \u6307\u5b9a\u5bb9\u5668\u5185\u90e8\u76d1\u542c\u7684\u5e94\u7528\u7aef\u53e3<\/pre>\n\n\n\n<p><strong>3. \u7f16\u5199Kubernetes Service\u914d\u7f6e<\/strong><\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a<code>service.yaml<\/code>\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Service # \u7528\u4e8e\u63cf\u8ff0\u548c\u7ba1\u7406\u5411\u5916\u90e8\u6216\u8005\u5185\u90e8\u66b4\u9732\u5e94\u7528\u7684\u7f51\u7edc\u8bbf\u95ee\u65b9\u5f0f\nmetadata:\n  name: yuanjava # \u5305\u542b\u8d44\u6e90\u7684\u5143\u6570\u636e\u4fe1\u606f\nspec:\n  type: LoadBalancer # \u5b9a\u4e49\u4e86\u670d\u52a1\u7684\u7c7b\u578b\uff0cLoadBalancer \u7c7b\u578b\u4f1a\u5c06\u670d\u52a1\u66b4\u9732\u7ed9\u5916\u90e8\u7f51\u7edc\n  ports:\n  - port: 80  # \u8fd9\u662f\u5bf9\u5916\u66b4\u9732\u7684\u7aef\u53e3\uff0c\u8868\u793a\u5916\u90e8\u5ba2\u6237\u7aef\u8bbf\u95ee\u670d\u52a1\u65f6\u4f7f\u7528\u7684\u7aef\u53e3\u53f7\n    targetPort: 9999 # \u8fd9\u662f\u96c6\u7fa4\u5185\u90e8\u76ee\u6807 Pod \u4e0a\u8fd0\u884c\u7684\u5bb9\u5668\u6240\u76d1\u542c\u7684\u7aef\u53e3\n  selector:\n    app: yuanjava<\/pre>\n\n\n\n<p><strong>4. \u90e8\u7f72\u5230Kubernetes<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>kubectl<\/code>\u547d\u4ee4\u5e94\u7528\u914d\u7f6e\uff0c\u547d\u4ee4\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><code>kubectl apply -f deployment.yaml<\/code>\uff1a\u6839\u636e deployment.yaml \u6587\u4ef6\u4e2d\u7684\u5b9a\u4e49\uff0c\u521b\u5efa\u6216\u66f4\u65b0 Kubernetes\u4e2d\u76f8\u5e94\u7684 Deployment\u3002<code>kubectl apply -f service.yaml<\/code>\uff1a\u6839\u636e service.yaml \u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\uff0cKubernetes\u4f1a\u521b\u5efa\u4e00\u4e2a Service\uff0c\u5e76\u5c06\u5176\u4e0e\u8fd0\u884c Deployment \u4e2d\u7684 Pod\u5173\u8054\u8d77\u6765\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f deployment.yaml\nkubectl apply -f service.yaml<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-1024x559.png\" alt=\"\" class=\"wp-image-16758\" style=\"width:520px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-1024x559.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-768x419.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-830x453.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211-480x262.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-211.png 1092w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>5. \u9a8c\u8bc1\u90e8\u7f72<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 Pods\u548c Service\u72b6\u6001\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl get pods\nkubectl get services<\/pre>\n\n\n\n<p>\u5982\u4e0b\u56fe\uff0c2\u4e2a Pod\u90fd\u5904\u4e8e Running \u72b6\u6001\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"556\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-1024x556.png\" alt=\"\" class=\"wp-image-16759\" style=\"width:530px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-1024x556.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-300x163.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-768x417.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-830x451.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-230x125.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-350x190.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212-480x261.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-212.png 1108w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>2.2.5 \u6d4f\u89c8\u5668\u9a8c\u8bc1<\/strong><\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\uff0c\u9a8c\u8bc1\u5e94\u7528\u662f\u5426\u6210\u529f\u90e8\u7f72\u5230 Kubernetes \u96c6\u7fa4\uff0c\u8bbf\u95ee\u5730\u5740\u662f\uff1a<code>http:\/\/EXTERNAL-IP\/hello<\/code> \uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"371\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-1024x371.png\" alt=\"\" class=\"wp-image-16760\" style=\"width:542px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-1024x371.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-300x109.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-768x278.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-830x301.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-230x83.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-350x127.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213-480x174.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-213.png 1098w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u56e0\u4e3a\uff0c\u6211\u662f\u672c\u5730\u90e8\u7f72\uff0c\u6240\u4ee5<code>EXTERNAL-IP<\/code>\u5730\u5740\u4e3a<code>&lt;pending><\/code>\uff0c\u5373\u672a\u5206\u914d\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7<code>minikube service yuanjava<\/code>\u67e5\u770b IP\u5730\u5740\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"380\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-1024x380.png\" alt=\"\" class=\"wp-image-16762\" style=\"width:530px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-1024x380.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-300x111.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-768x285.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-830x308.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-230x85.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-350x130.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215-480x178.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-215.png 1110w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u6700\u540e\uff0c\u6253\u5f00\u5730\u5740<code>http:\/\/192.168.49.2:63213\/test<\/code>\uff0c \u89c1\u8bc1\u5947\u8ff9\u7684\u65f6\u523b\u5230\u4e86\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"286\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-1024x286.png\" alt=\"\" class=\"wp-image-16764\" style=\"width:506px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-1024x286.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-300x84.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-768x215.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-830x232.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-230x64.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-350x98.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217-480x134.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/11\/image-217.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u56e0\u4e3a\u662f\u672c\u5730\u73af\u5883\uff0c\u6240\u4ee5\u94fe\u63a5\u6700\u7ec8\u4f1a\u8df3\u8f6c\u5230<code>http:\/\/127.0.0.1:63213\/test<\/code> \u3002<\/p>\n\n\n\n<p>\u5230\u6b64\uff0c\u6211\u4eec\u5c31\u6210\u529f\u5730\u624b\u52a8\u5c06 Docker\u955c\u50cf\u90e8\u7f72\u5230 Kubernetes\u96c6\u7fa4\uff0c\u5e76\u4e14\u901a\u8fc7 URL\u80fd\u591f\u8bbf\u95ee\uff0c\u8fc7\u7a0b\u5f88\u8270\u8f9b\uff0c\u7ed3\u679c\u8fd8\u662f\u6bd4\u8f83\u7f8e\u597d\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u5982\u679c\u8981\u90e8\u7f72\u5927\u91cf\u7684\u673a\u5668\uff0c\u8fd9\u6837\u624b\u52a8\u64cd\u4f5c\u80af\u5b9a\u662f\u4e0d\u884c\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u7ed3\u7ec4\u4e00\u4e9b CI\/CD\u5de5\u5177\uff08\u5982 GitHub Actions\u3001GitLab CI\/CD \u6216 Jenkins\uff09\u5b9e\u73b0\u81ea\u52a8\u5316 Docker\u955c\u50cf\u6784\u5efa\u548c Kubernetes \u90e8\u7f72\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4ee5 GitHub Actions\u4e3a\u4f8b\uff0c\u521b\u5efa .github\/workflows\/auto-deploy.yaml\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name: Auto Deploy Application to Kubernetes\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  build-and-deploy:\n    runs-on: ubuntu-latest\n    steps:\n    # Step 1: \u68c0\u51fa\u4ee3\u7801\n    - name: Checkout code\n      uses: actions\/checkout@v3\n\n    # Step 2: \u767b\u5f55 Docker Registry\n    - name: Log in to Docker Hub\n      run: echo \"${{ secrets.DOCKER_PASSWORD }}\" | docker login -u \"${{ secrets.DOCKER_USERNAME }}\" --password-stdin\n\n    # Step 3: \u6784\u5efa\u5e76\u63a8\u9001 Docker \u955c\u50cf\n    - name: Build and push Docker image\n      run: |\n        docker build -t ${{ secrets.DOCKER_USERNAME }}\/yuanjava:latest .\n        docker push ${{ secrets.DOCKER_USERNAME }}\/yuanjava:latest\n\n    # Step 4: \u8bbe\u7f6e kubectl\n    - name: Set up kubectl\n      uses: azure\/setup-kubectl@v3\n      with:\n        version: 'latest'\n\n    # Step 5: \u914d\u7f6e kubeconfig \u6587\u4ef6\n    - name: Configure kubeconfig\n      run: |\n        echo \"${{ secrets.KUBECONFIG }}\" > kubeconfig\n        export KUBECONFIG=kubeconfig\n\n    # Step 6: \u90e8\u7f72\u5230 Kubernetes\n    - name: Apply Kubernetes manifests\n      run: |\n        kubectl apply -f deployment.yaml\n        kubectl apply -f service.yaml<\/pre>\n\n\n\n<p><strong>\u5173\u952e\u8bf4\u660e\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li>\u914d\u7f6e\u91cc\u9762\u7684 DOCKER_USERNAME, DOCKER_PASSWORD, KUBECONFIG\uff0c\u9700\u5728\u9879\u76ee\u7684 Settings > Secrets \u4e2d\u914d\u7f6e\u3002<\/li>\n\n\n\n<li>\u5728\u89e6\u53d1\u9636\u6bb5\uff08push \u5230 main \u5206\u652f\uff09\u65f6\uff0c\u4e0a\u8ff0\u6d41\u6c34\u7ebf\u5c06\u81ea\u52a8\u5b8c\u6210 Docker \u6784\u5efa\u3001\u63a8\u9001\uff0c\u5e76\u5c06\u5e94\u7528\u90e8\u7f72\u5230 Kubernetes\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>3. \u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u672c\u6587\uff0c\u6211\u4eec\u5148\u4ece\u7406\u8bba\u4e0a\u5206\u6790\u4e86 Docker \u548c Kubernetes\u7684\u6838\u5fc3\u6982\u5ff5\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u4ece\u4ee3\u7801\u5b9e\u6218\u7684\u89d2\u5ea6\uff0c\u5e26\u5927\u5bb6\u4e00\u6b65\u4e00\u6b65\u5b9e\u64cd\u4e86\u5982\u4f55\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684 Java Web\u5e94\u7528\uff0c\u5e76\u5c06\u5176 Docker\u5bb9\u5668\u5316\uff0c\u6700\u540e\u90e8\u7f72\u5230 Kubernetes\u96c6\u7fa4\u4e2d\uff0c\u7136\u540e\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee\u3002\u5728\u5b9e\u64cd\u7684\u671f\u95f4\uff0c\u56e0\u4e3a\u6240\u6709\u7684\u73af\u5883\u90fd\u662f\u672c\u5730\u73af\u5883\u4e34\u65f6\u642d\u5efa\uff0c\u6240\u4ee5\u9047\u5230\u4e86\u5f88\u591a\u7684\u95ee\u9898\uff0c\u4f46\u6700\u7ec8\u8fd8\u662f\u6210\u529f\u4e86\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u6b21\u5b9e\u64cd\uff0c\u518d\u6b21\u8bf4\u660e\u4e86\u505a\u6280\u672f\u4e0d\u80fd\u53ea\u505c\u7559\u5728\u7406\u8bba\uff0c\u5b9e\u64cd\u5f88\u91cd\u8981\uff0c\u5b9e\u64cd\u671f\u95f4\u6211\u4eec\u53ef\u80fd\u9047\u5230\u5f88\u591a\u95ee\u9898\uff0c\u4f46\u662f\uff0c\u5f53\u6211\u4eec\u901a\u8fc7\u5404\u79cd\u65b9\u5f0f\u53bb\u89e3\u51b3\u95ee\u9898\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5176\u5b9e\u5c31\u662f\u5bf9\u6280\u672f\u66f4\u6df1\u5165\u7684\u5b66\u4e60\u548c\u638c\u63e1\u3002<\/p>\n\n\n\n<p><strong>\u4e2a\u4eba\u5efa\u8bae\uff1a<\/strong><\/p>\n\n\n\n<p>Docker\u662f\u4e91\u539f\u751f\u5f88\u91cd\u8981\u76f8\u5bf9\u7b80\u5355\u7684\u4e00\u4e2a\u6280\u672f\u57fa\u7840\uff0c\u5f3a\u70c8\u5efa\u8bae\u638c\u63e1\u5e76\u4e14\u4e00\u5b9a\u8981\u53bb\u5b9e\u6218\u3002Kubernetes\u7684\u96be\u5ea6\u7cfb\u7edf\u4f1a\u6bd4 Docker\u5927\uff0c\u5b83\u4e3a\u5927\u91cf\u5bb9\u5668\u63d0\u4f9b\u8c03\u5ea6\u3001\u8d44\u6e90\u7ba1\u7406\u3001\u5f39\u6027\u4f38\u7f29\u7b49\u529f\u80fd\uff0c\u5982\u679c\u4f7f\u7528\u7684\u673a\u5668\u6570\u91cf\u6bd4\u8f83\u5c11\uff0cKubernetes\u5176\u5b9e\u5f88\u96be\u7528\u4e0a\uff0c\u4f46\u662f\uff0c\u5982\u679c\u53ef\u4ee5\uff0c\u8fd8\u662f\u5efa\u8bae\u6211\u4eec\u521b\u9020\u6761\u4ef6\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u53bb\u4f7f\u7528\u548c\u5b66\u4e60 Kubernetes\u3002\u76f8\u4fe1\u6211\uff0c\u8fd9\u79cd\u6709\u538b\u529b\u7684\u5b66\u4e60\u6548\u679c\u8d3c\u68d2\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1aDocker\u662f\u4ec0\u4e48\uff1fK8s\u53c8\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4ece0\u52301\u5b9e\u6218Docker\u4e0eK8s\u5168\u6d41\u7a0b\u90e8\u7f72\uff1f \u4e91\u539f\u751f\u65f6\u4ee3\uff0c\u4f5c\u4e3a\u6280 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16730"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16730"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16730\/revisions"}],"predecessor-version":[{"id":16765,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/16730\/revisions\/16765"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}