{"id":124431,"date":"2026-11-19T01:08:31","date_gmt":"2026-11-18T17:08:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/124431.html"},"modified":"2026-11-19T01:08:31","modified_gmt":"2026-11-18T17:08:31","slug":"devops-%e8%bf%9b%e9%98%b6-kubernetes-%e4%b8%8e-devops-%e6%95%b4%e5%90%88%e5%ae%9e%e6%88%98%ef%bc%9ak8s-%e9%9b%86%e7%be%a4%e6%90%ad%e5%bb%ba-jenkins-%e8%87%aa%e5%8a%a8%e9%83%a8%e7%bd%b2-pipeline","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/124431.html","title":{"rendered":"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<h2>\u3010DevOps \u8fdb\u9636\u3011Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218&#xff1a;K8s \u96c6\u7fa4\u642d\u5efa &#043; Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528<\/h2>\n<p>\u524d\u4e24\u7ae0\u6211\u4eec\u628a\u955c\u50cf\u63a8\u5230\u4e86 Harbor&#xff0c;\u7528 docker run \u5728\u5355\u673a\u4e0a\u8dd1\u8d77\u6765\u3002\u8fd9\u4e00\u7ae0\u6362\u4e00\u79cd\u4ea4\u4ed8\u65b9\u5f0f&#xff1a;\u8ba9 Kubernetes \u63a5\u7ba1\u8fd0\u884c\u6001\u2014\u2014Jenkins \u53ea\u8d1f\u8d23\u6784\u5efa\u548c\u63a8\u9001&#xff0c;kubectl apply \u8d1f\u8d23\u8ba9\u5b83\u8dd1\u8d77\u6765\u3001\u625b\u4f4f\u3001\u6269\u7f29\u5bb9\u3002<\/p>\n<h3>\u9605\u8bfb\u5bfc\u822a<\/h3>\n<li>\u5148\u8865\u4e0a\u4e0a\u671f\u5f69\u86cb \u2014\u2014 deploy.sh \u7684\u5e42\u7b49\u4f18\u5316&#xff0c;\u8ba9\u95ed\u73af\u5b8c\u7f8e\u6536\u53e3<\/li>\n<li>\u4e3a\u4ec0\u4e48\u4ece docker run \u8d70\u5411 Kubernetes \u2014\u2014 \u4e24\u79cd\u4ea4\u4ed8\u65b9\u5f0f\u5bf9\u6bd4<\/li>\n<li>\u96c6\u7fa4\u89c4\u5212\u4e0e\u73af\u5883\u51c6\u5907 \u2014\u2014 hosts \/ \u9632\u706b\u5899 \/ SELinux \/ \u9759\u6001 IP<\/li>\n<li>\u5b89\u88c5 Docker \u4e0e kubelet \u2014\u2014 kuboard \u4e00\u952e\u811a\u672c&#xff0c;\u9501\u5b9a 1.19.5<\/li>\n<li>\u521d\u59cb\u5316 Master \u8282\u70b9<\/li>\n<li>\u52a0\u5165 Worker \u8282\u70b9<\/li>\n<li>\u9a8c\u8bc1\u96c6\u7fa4\u72b6\u6001<\/li>\n<li>\u51c6\u5907 YAML&#xff1a;Deployment &#043; Service<\/li>\n<li>\u521b\u5efa harbor-secret&#xff08;\u6700\u5173\u952e\u7684\u4e00\u6b65&#xff09;<\/li>\n<li>\u8ba9\u6240\u6709\u8282\u70b9\u4fe1\u4efb Harbor<\/li>\n<li>Jenkins \u628a YAML \u63a8\u5230 master<\/li>\n<li>Jenkins \u514d\u5bc6 SSH \u767b\u5f55 master<\/li>\n<li>\u6d41\u6c34\u7ebf\u589e\u52a0 kubectl \u90e8\u7f72\u9636\u6bb5<\/li>\n<li>\u7248\u672c\u540c\u6b65&#xff1a;tag\u3001YAML\u3001\u4ee3\u7801\u4e09\u5904\u5bf9\u9f50<\/li>\n<li>\u9a8c\u8bc1\u7ed3\u679c<\/li>\n<li>\u8e29\u5751\u6e05\u5355<\/li>\n<li>\u603b\u7ed3<\/li>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u8865\u4e0a\u4e0a\u671f\u5f69\u86cb<\/h3>\n<p>\u4e0a\u671f\u7559\u4e86\u4e2a\u95ee\u9898&#xff1a;\u8dd1\u5b8c pipeline \u540e mytest \u5bb9\u5668\u9000\u51fa\u4e86\u3002\u539f\u56e0\u662f deploy.sh \u6bcf\u6b21\u6267\u884c\u90fd systemctl restart docker&#xff0c;\u628a\u6ca1\u6709\u91cd\u542f\u7b56\u7565\u7684\u5bb9\u5668\u5168\u5e26\u8d70\u4e86\u3002<\/p>\n<p>\u4f18\u5316\u540e\u7684 deploy.sh&#xff08;\u5728 Jenkins \u670d\u52a1\u5668 \/usr\/local\/docker\/jenkins_docker\/data\/workspace\/mytest \u4e0b&#xff09;\u6838\u5fc3\u6539\u52a8\u5c31\u4e00\u5904\u2014\u2014\u5148\u5224\u65ad\u662f\u5426\u914d\u7f6e\u8fc7&#xff0c;\u907f\u514d\u91cd\u590d\u91cd\u542f Docker&#xff1a;<\/p>\n<p><span class=\"token shebang important\">#! \/bin\/bash<\/span><br \/>\n<span class=\"token assign-left variable\">harbor_ip<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$1<\/span><br \/>\n<span class=\"token assign-left variable\">harbor_repo<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$2<\/span><br \/>\n<span class=\"token assign-left variable\">project<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$3<\/span><br \/>\n<span class=\"token assign-left variable\">version<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$4<\/span><br \/>\n<span class=\"token assign-left variable\">container_port<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$5<\/span><br \/>\n<span class=\"token assign-left variable\">host_port<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$6<\/span><\/p>\n<p><span class=\"token assign-left variable\">imageName<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\">$harbor_ip<\/span>\/<span class=\"token variable\">$harbor_repo<\/span>\/<span class=\"token variable\">$project<\/span><span class=\"token builtin class-name\">:<\/span><span class=\"token variable\">$version<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token variable\">$imageName<\/span><\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u5f53\u524d\u5bb9\u5668\u6b63\u5728\u8fd0\u884c&#xff0c;\u5219\u5220\u9664<\/span><br \/>\n<span class=\"token assign-left variable\">container_id<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\"><span class=\"token variable\">&#096;<\/span><span class=\"token function\">docker<\/span> <span class=\"token function\">ps<\/span> <span class=\"token parameter variable\">-a<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> $<span class=\"token punctuation\">{<\/span>project<span class=\"token punctuation\">}<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;{print $1}&#039;<\/span><span class=\"token variable\">&#096;<\/span><\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token variable\">$container_id<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">[<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">$container_id<\/span>&#034;<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token string\">&#034;&#034;<\/span> <span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token keyword\">then<\/span><br \/>\n  <span class=\"token function\">docker<\/span> stop <span class=\"token variable\">$container_id<\/span><br \/>\n  <span class=\"token function\">docker<\/span> <span class=\"token function\">rm<\/span> <span class=\"token variable\">$container_id<\/span><br \/>\n<span class=\"token keyword\">fi<\/span><\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u5f53\u524d\u955c\u50cf\u5df2\u5b58\u5728&#xff0c;\u5219\u5220\u9664<\/span><br \/>\n<span class=\"token assign-left variable\">tag<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token variable\"><span class=\"token variable\">&#096;<\/span><span class=\"token function\">docker<\/span> images <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> $<span class=\"token punctuation\">{<\/span>project<span class=\"token punctuation\">}<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">awk<\/span> <span class=\"token string\">&#039;{print $2}&#039;<\/span><span class=\"token variable\">&#096;<\/span><\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token variable\">$tag<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">[<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">$tag<\/span>&#034;<\/span> <span class=\"token operator\">&#061;~<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">$version<\/span>&#034;<\/span> <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token keyword\">then<\/span><br \/>\n  <span class=\"token function\">docker<\/span> rmi <span class=\"token variable\">$imageName<\/span><br \/>\n<span class=\"token keyword\">fi<\/span><\/p>\n<p><span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u6b64\u5904\u4f18\u5316&#xff1a;\u975e\u672c\u5730\u767b\u5f55\u955c\u50cf\u4ed3\u5e93&#xff0c;\u5e42\u7b49\u5904\u7406 &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-q<\/span> &#8212; <span class=\"token string\">&#034;&#8211;insecure-registry&#034;<\/span> \/lib\/systemd\/system\/docker.service<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">then<\/span><br \/>\n    <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;\u5df2\u914d\u7f6e\u8fc7 &#034;<\/span><br \/>\n<span class=\"token keyword\">else<\/span><br \/>\n    <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;\u521d\u6b21\u914d\u7f6e &#034;<\/span><br \/>\n    <span class=\"token function\">cp<\/span> \/lib\/systemd\/system\/docker.service \/lib\/systemd\/system\/docker.service.bak<br \/>\n    <span class=\"token function\">sed<\/span> <span class=\"token parameter variable\">-i<\/span> <span class=\"token string\">&#039;s|ExecStart&#061;\/usr\/bin\/dockerd -H fd:\/\/ &#8211;containerd&#061;\/run\/containerd\/containerd.sock|ExecStart&#061;\/usr\/bin\/dockerd -H fd:\/\/ &#8211;insecure-registry 192.168.100.154 &#8211;containerd&#061;\/run\/containerd\/containerd.sock|g&#039;<\/span> \/lib\/systemd\/system\/docker.service<br \/>\n    systemctl daemon-reload <span class=\"token operator\">&amp;&amp;<\/span> systemctl restart <span class=\"token function\">docker<\/span><br \/>\n<span class=\"token keyword\">fi<\/span><br \/>\n<span class=\"token function\">docker<\/span> login <span class=\"token parameter variable\">-u<\/span> admin <span class=\"token parameter variable\">-p<\/span> harbor123 <span class=\"token variable\">$harbor_ip<\/span><br \/>\n<span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/span><\/p>\n<p><span class=\"token comment\"># \u62c9\u53d6\u955c\u50cf<\/span><br \/>\n<span class=\"token function\">docker<\/span> pull <span class=\"token variable\">$imageName<\/span><br \/>\n<span class=\"token comment\"># \u8fd0\u884c\u5bb9\u5668<\/span><br \/>\n<span class=\"token function\">docker<\/span> run <span class=\"token parameter variable\">-d<\/span> <span class=\"token parameter variable\">-p<\/span> <span class=\"token variable\">$host_port<\/span><span class=\"token builtin class-name\">:<\/span><span class=\"token variable\">$container_port<\/span> <span class=\"token parameter variable\">&#8211;name<\/span> <span class=\"token variable\">$project<\/span> <span class=\"token variable\">$imageName<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;SUCCESS&#034;<\/span><\/p>\n<p>\u5173\u952e\u5c31\u662f\u8fd9\u4e09\u884c\u5224\u65ad&#xff1a;<\/p>\n<p><span class=\"token keyword\">if<\/span> <span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-q<\/span> &#8212; <span class=\"token string\">&#034;&#8211;insecure-registry&#034;<\/span> \/lib\/systemd\/system\/docker.service<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">then<\/span><br \/>\n    <span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;\u5df2\u914d\u7f6e\u8fc7 &#034;<\/span><br \/>\n<span class=\"token keyword\">else<\/span><br \/>\n    <span class=\"token punctuation\">..<\/span>. \u914d\u7f6e &#043; \u91cd\u542f <span class=\"token punctuation\">..<\/span>.<br \/>\n<span class=\"token keyword\">fi<\/span><\/p>\n<p>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u6539\u5c31\u89e3\u51b3\u4e86\u5f69\u86cb\u95ee\u9898&#xff1a;&#8211;insecure-registry \u662f\u4e00\u6b21\u6027\u914d\u7f6e&#xff0c;\u7b2c\u4e00\u6b21\u90e8\u7f72\u65f6\u6539\u4e00\u6b21\u3001\u91cd\u542f\u4e00\u6b21 Docker \u5c31\u591f\u4e86&#xff1b;\u4e4b\u540e\u6bcf\u6b21\u90e8\u7f72\u8d70 else \u5206\u652f&#xff0c;\u4e0d\u518d\u91cd\u542f Docker&#xff0c;\u90a3\u4e9b\u6ca1\u8bbe &#8211;restart \u7b56\u7565\u7684\u8001\u5bb9\u5668&#xff08;\u6bd4\u5982 mytest&#xff09;\u81ea\u7136\u4e0d\u4f1a\u88ab\u8bef\u4f24\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u8fd0\u7ef4\u811a\u672c\u91cc\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u539f\u5219&#xff1a;\u5e42\u7b49&#xff08;Idempotent&#xff09;\u2014\u2014\u540c\u4e00\u4e2a\u811a\u672c\u6267\u884c\u4e00\u6b21\u548c\u6267\u884c\u4e00\u767e\u6b21&#xff0c;\u7ed3\u679c\u5e94\u8be5\u4e00\u6837&#xff0c;\u526f\u4f5c\u7528\u4e5f\u5e94\u8be5\u53ea\u53d1\u751f\u4e00\u6b21\u3002<\/p>\n<p>\u5148\u8fd0\u884c mytest&#xff0c;\u518d\u8fd0\u884c pipeline&#xff0c;\u4e24\u4e2a\u5bb9\u5668\u5404\u81ea\u72ec\u7acb\u5b58\u6d3b&#xff0c;\u95ed\u73af\u624d\u7b97\u771f\u6b63\u5b8c\u7f8e\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4e3a\u4ec0\u4e48\u4ece docker run \u8d70\u5411 Kubernetes<\/h3>\n<p>\u5355\u673a docker run \u80fd\u8dd1\u8d77\u6765&#xff0c;\u4f46\u4e00\u5230\u751f\u4ea7\u5c31\u66b4\u9732\u77ed\u677f&#xff1a;<\/p>\n<table>\n<tr>\u7ef4\u5ea6docker run&#xff08;\u7b2c 3 \u90e8\u65b9\u6848&#xff09;Kubernetes&#xff08;\u672c\u7ae0\u65b9\u6848&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u8fd0\u884c\u4f4d\u7f6e<\/td>\n<td>\u56fa\u5b9a\u67d0\u53f0\u673a\u5668<\/td>\n<td>\u96c6\u7fa4\u8c03\u5ea6&#xff0c;\u81ea\u52a8\u9009\u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td>\u526f\u672c\u6570<\/td>\n<td>\u624b\u52a8\u8d77\u51e0\u4e2a\u5c31\u662f\u51e0\u4e2a<\/td>\n<td>replicas \u58f0\u660e\u5f0f&#xff0c;\u81ea\u52a8\u8865\u9f50<\/td>\n<\/tr>\n<tr>\n<td>\u6545\u969c\u6062\u590d<\/td>\n<td>\u5bb9\u5668\u6302\u4e86\u5c31\u6302\u4e86<\/td>\n<td>Pod \u6302\u4e86\u81ea\u52a8\u91cd\u5efa<\/td>\n<\/tr>\n<tr>\n<td>\u6eda\u52a8\u5347\u7ea7<\/td>\n<td>\u5148\u505c\u540e\u8d77&#xff0c;\u670d\u52a1\u4e2d\u65ad<\/td>\n<td>\u9010\u4e2a\u66ff\u6362&#xff0c;\u96f6\u505c\u673a<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u6108\/\u63a2\u9488<\/td>\n<td>\u65e0<\/td>\n<td>liveness \/ readiness \u63a2\u9488<\/td>\n<\/tr>\n<tr>\n<td>\u670d\u52a1\u53d1\u73b0<\/td>\n<td>\u8bb0 IP &#043; \u7aef\u53e3<\/td>\n<td>Service \u7edf\u4e00\u5165\u53e3&#xff0c;ClusterIP\/NodePort<\/td>\n<\/tr>\n<tr>\n<td>\u6269\u7f29\u5bb9<\/td>\n<td>\u6539\u811a\u672c\u91cd\u65b0\u8dd1<\/td>\n<td>\u6539 replicas \u6216 HPA<\/td>\n<\/tr>\n<tr>\n<td>\u914d\u7f6e\u7ba1\u7406<\/td>\n<td>\u6563\u843d\u5728\u811a\u672c\u53c2\u6570<\/td>\n<td>YAML \u58f0\u660e\u5f0f&#xff0c;\u53ef\u7248\u672c\u63a7\u5236<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5bf9\u6211\u4eec\u8fd9\u6761\u6d41\u6c34\u7ebf\u6765\u8bf4&#xff0c;\u6539\u9020\u70b9\u975e\u5e38\u5c0f&#xff1a;Jenkins \u4ecd\u7136\u8d1f\u8d23&#034;\u6784\u5efa &#043; \u63a8\u9001\u955c\u50cf&#034;&#xff0c;\u53ea\u662f\u628a\u6700\u540e\u4e00\u6b65\u4ece&#034;SSH \u6267\u884c docker run&#034;\u6362\u6210&#034;SSH \u6267\u884c kubectl apply&#034;\u3002\u4ea4\u4ed8\u7269\u4ece&#034;\u4e00\u6761\u547d\u4ee4&#034;\u53d8\u6210\u4e86&#034;\u4e00\u4efd YAML&#034;\u3002<\/p>\n<p>Jenkins \u6784\u5efa \u2192 \u63a8\u9001 Harbor \u2192 SSH \u5230 master \u2192 kubectl apply -f pipeline.yml<br \/>\n                                                      \u2502<br \/>\n                                                      \u25bc<br \/>\n                                        Deployment \u62c9\u955c\u50cf\u3001\u8d77 2 \u4e2a Pod<br \/>\n                                        Service \u66b4\u9732 NodePort \u5bf9\u5916\u63d0\u4f9b\u8bbf\u95ee<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u96c6\u7fa4\u89c4\u5212\u4e0e\u73af\u5883\u51c6\u5907<\/h3>\n<p>\u672c\u7ae0\u7528 1 master &#043; 1 worker \u7684\u6700\u5c0f\u96c6\u7fa4&#xff08;\u751f\u4ea7\u5efa\u8bae 3 master&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u89d2\u8272\u4e3b\u673a\u540dIP\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>Master<\/td>\n<td>master<\/td>\n<td>192.168.100.145<\/td>\n<td>\u63a7\u5236\u9762&#xff0c;kubectl \u64cd\u4f5c\u5165\u53e3<\/td>\n<\/tr>\n<tr>\n<td>Worker<\/td>\n<td>node1<\/td>\n<td>192.168.100.146<\/td>\n<td>\u8fd0\u884c\u4e1a\u52a1 Pod<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4ed6\u73af\u5883\u4fe1\u606f&#xff1a;<\/p>\n<table>\n<tr>\u9879\u503c<\/tr>\n<tbody>\n<tr>\n<td>\u7cfb\u7edf<\/td>\n<td>CentOS Linux 7 (Core)&#xff0c;\u5185\u6838 3.10.0-693.el7.x86_64<\/td>\n<\/tr>\n<tr>\n<td>Kubernetes<\/td>\n<td>v1.19.5<\/td>\n<\/tr>\n<tr>\n<td>\u5bb9\u5668\u8fd0\u884c\u65f6<\/td>\n<td>docker:\/\/19.3.11<\/td>\n<\/tr>\n<tr>\n<td>Pod \u7f51\u6bb5<\/td>\n<td>10.100.0.1\/16<\/td>\n<\/tr>\n<tr>\n<td>Harbor<\/td>\n<td>192.168.100.154:80&#xff08;\u6cbf\u7528\u524d\u4e24\u7ae0&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e3a\u4ec0\u4e48\u9009 1.19&#xff1f; kuboard.cn \u7684\u5feb\u901f\u5b89\u88c5\u811a\u672c\u9ed8\u8ba4\u652f\u6301 Docker \u7684\u7248\u672c\u5c31\u662f 1.19\u3002\u4ece K8s 1.24 \u5f00\u59cb&#xff0c;dockershim \u88ab\u79fb\u9664&#xff0c;\u5bb9\u5668\u8fd0\u884c\u65f6\u9700\u8981\u6362\u6210 containerd \u6216 cri-dockerd\u3002\u5bf9\u521d\u5b66\u9636\u6bb5\u6765\u8bf4&#xff0c;1.19 &#043; Docker \u662f\u6700\u7701\u5fc3\u7684\u7ec4\u5408\u2014\u2014\u4f60\u5df2\u6709\u7684 Docker \u77e5\u8bc6\u3001docker images \/ docker ps \u6392\u969c\u624b\u6bb5\u5168\u90e8\u8fd8\u80fd\u7528\u3002<\/p>\n<h4>3.1 \u4e3b\u673a\u540d\u89e3\u6790<\/h4>\n<p>\u6bcf\u53f0\u673a\u5668\u628a\u81ea\u5df1\u7684\u4e3b\u673a\u540d\u89e3\u6790\u5230 127.0.0.1&#xff08;kubelet \u76f8\u5173\u7ec4\u4ef6\u4f1a\u7528\u5230&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\"># master \u8282\u70b9<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># echo &#034;127.0.0.1   $(hostname)&#034; &gt;&gt; \/etc\/hosts<\/span><\/p>\n<p><span class=\"token comment\"># node1 \u8282\u70b9<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;node1 ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># echo &#034;127.0.0.1   $(hostname)&#034; &gt;&gt; \/etc\/hosts<\/span><\/p>\n<p>\u6ce8\u610f\u8ffd\u52a0\u7684\u662f\u672c\u673a\u4e3b\u673a\u540d&#xff0c;\u4e24\u53f0\u673a\u5668\u5206\u522b\u6267\u884c&#xff0c;\u522b\u5728 master \u4e0a\u66ff node1 \u5199\u3002<\/p>\n<h4>3.2 \u5173\u95ed\u9632\u706b\u5899\u3001\u7981\u7528 SELinux<\/h4>\n<p><span class=\"token comment\"># master \u4e0e node1 \u90fd\u6267\u884c<\/span><br \/>\nsystemctl disable firewalld.service <span class=\"token parameter variable\">&#8211;now<\/span><br \/>\nsetenforce <span class=\"token number\">0<\/span><\/p>\n<ul>\n<li>systemctl disable &#8230; &#8211;now&#xff1a;\u65e2\u505c\u6b62\u5f53\u524d\u670d\u52a1&#xff0c;\u53c8\u53d6\u6d88\u5f00\u673a\u81ea\u542f&#xff08;\u7b49\u4ef7\u4e8e stop &#043; disable&#xff09;\u3002<\/li>\n<li>setenforce 0&#xff1a;\u4e34\u65f6\u628a SELinux \u5207\u6210 permissive&#xff0c;\u91cd\u542f\u540e\u4f1a\u6062\u590d\u3002\u5f7b\u5e95\u7981\u7528\u8981\u6539\u914d\u7f6e\u6587\u4ef6&#xff1a;<\/li>\n<\/ul>\n<p><span class=\"token function\">vim<\/span> \/etc\/selinux\/config<br \/>\n<span class=\"token comment\"># SELINUX&#061;disabled<\/span><\/p>\n<p>K8s \u7ec4\u4ef6\u9700\u8981\u4e92\u76f8\u901a\u4fe1&#xff0c;\u9632\u706b\u5899\u4e0e SELinux \u662f\u65b0\u624b\u9636\u6bb5\u6700\u5e38\u89c1\u7684&#034;\u96c6\u7fa4\u8d77\u4e0d\u6765&#034;\u539f\u56e0&#xff0c;\u5148\u5173\u6389\u6362\u786e\u5b9a\u6027\u3002<\/p>\n<h4>3.3 \u914d\u7f6e\u56fa\u5b9a IP<\/h4>\n<p><span class=\"token function\">vim<\/span> \/etc\/sysconfig\/network-scripts\/ifcfg-ens33<\/p>\n<p>master&#xff08;192.168.100.145&#xff09;&#xff1a;<\/p>\n<p>TYPE&#061;&#034;Ethernet&#034;<br \/>\nPROXY_METHOD&#061;&#034;none&#034;<br \/>\nBROWSER_ONLY&#061;&#034;no&#034;<br \/>\nBOOTPROTO&#061;&#034;static&#034;<br \/>\nDEFROUTE&#061;&#034;yes&#034;<br \/>\nIPV4_FAILURE_FATAL&#061;&#034;no&#034;<br \/>\nIPV6INIT&#061;&#034;yes&#034;<br \/>\nIPV6_AUTOCONF&#061;&#034;yes&#034;<br \/>\nIPV6_DEFROUTE&#061;&#034;yes&#034;<br \/>\nIPV6_FAILURE_FATAL&#061;&#034;no&#034;<br \/>\nIPV6_ADDR_GEN_MODE&#061;&#034;stable-privacy&#034;<br \/>\nNAME&#061;&#034;ens33&#034;<br \/>\nUUID&#061;&#034;f0967cdb-cfb4-4ed8-973b-03a171214395&#034;<br \/>\nDEVICE&#061;&#034;ens33&#034;<br \/>\nONBOOT&#061;&#034;yes&#034;<br \/>\nIPADDR&#061;&#034;192.168.100.145&#034;<br \/>\nNETMASK&#061;&#034;255.255.255.0&#034;<br \/>\nGATEWAY&#061;&#034;192.168.100.2&#034;<br \/>\nDNS1&#061;&#034;192.168.100.2&#034;<\/p>\n<p>node1&#xff08;192.168.100.146&#xff09;&#xff1a;\u9664 UUID \u4e0e IPADDR \u5916\u5b8c\u5168\u76f8\u540c&#xff1a;<\/p>\n<p>UUID&#061;&#034;6b9a9262-0da7-4fb0-a558-c4680234b273&#034;<br \/>\nIPADDR&#061;&#034;192.168.100.146&#034;<\/p>\n<p>\u6539\u5b8c\u91cd\u542f\u7f51\u7edc&#xff1a;<\/p>\n<p>systemctl restart network<br \/>\n<span class=\"token function\">ip<\/span> a          <span class=\"token comment\"># \u786e\u8ba4 IP \u751f\u6548<\/span><br \/>\n<span class=\"token function\">ping<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token number\">2<\/span> <span class=\"token number\">192.168<\/span>.100.145   <span class=\"token comment\"># \u4e24\u53f0\u673a\u5668\u4e92 ping \u9a8c\u8bc1<\/span><\/p>\n<p>\u8981\u70b9&#xff1a;UUID \u6bcf\u53f0\u673a\u5668\u552f\u4e00&#xff08;\u514b\u9686\u865a\u62df\u673a\u540e\u5fc5\u987b\u6539&#xff0c;\u5426\u5219\u7f51\u7edc\u670d\u52a1\u5f02\u5e38&#xff09;&#xff1b;BOOTPROTO \u5fc5\u987b\u662f static\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001\u5b89\u88c5 Docker \u4e0e kubelet<\/h3>\n<p>\u6240\u6709\u8282\u70b9&#xff08;master \u548c node1&#xff09;\u90fd\u8981\u88c5\u3002\u8fd9\u91cc\u7528 kuboard.cn \u63d0\u4f9b\u7684\u4e00\u952e\u811a\u672c&#xff0c;\u628a\u955c\u50cf\u6e90\u6362\u5230\u56fd\u5185&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u955c\u50cf\u52a0\u901f<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">REGISTRY_MIRROR<\/span><span class=\"token operator\">&#061;<\/span>https:\/\/registry.cn-hangzhou.aliyuncs.com<\/p>\n<p><span class=\"token comment\"># \u5b89\u88c5 docker \u4e0e kubelet&#xff0c;\u6307\u5b9a\u7248\u672c 1.19.5<\/span><br \/>\n<span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-sSL<\/span> https:\/\/kuboard.cn\/install-script\/v1.19.x\/install_kubelet.sh <span class=\"token operator\">|<\/span> <span class=\"token function\">sh<\/span> <span class=\"token parameter variable\">-s<\/span> <span class=\"token number\">1.19<\/span>.5<\/p>\n<p>\u8fd9\u6761\u547d\u4ee4\u505a\u4e86\u4e09\u4ef6\u4e8b&#xff1a;\u88c5 Docker\u3001\u88c5 kubelet\/kubeadm\/kubectl\u3001\u914d\u597d\u56fd\u5185\u955c\u50cf\u6e90\u3002<\/p>\n<p>\u9a8c\u8bc1&#xff1a;<\/p>\n<p><span class=\"token function\">docker<\/span> version<br \/>\nkubelet <span class=\"token parameter variable\">&#8211;version<\/span>     <span class=\"token comment\"># Kubernetes v1.19.5<\/span><\/p>\n<p>\u8fd9\u4e00\u6b65\u9700\u8981\u8054\u7f51&#xff0c;\u811a\u672c\u4f1a\u62c9\u4e0d\u5c11\u5305&#xff0c;\u7b49\u5f85\u5341\u5206\u949f\u5de6\u53f3\u662f\u6b63\u5e38\u7684\u3002\u5982\u679c\u5361\u4f4f&#xff0c;\u5148\u786e\u8ba4 REGISTRY_MIRROR \u662f\u5426\u751f\u6548\u3001DNS \u662f\u5426\u53ef\u7528\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u521d\u59cb\u5316 Master \u8282\u70b9<\/h3>\n<p>\u53ea\u5728 master \u8282\u70b9\u6267\u884c\u3002<\/p>\n<h4>5.1 \u8bbe\u7f6e\u53d8\u91cf<\/h4>\n<p><span class=\"token comment\"># master \u8282\u70b9\u5b9e\u9645 IP&#xff08;\u5185\u7f51 IP&#xff09;<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">MASTER_IP<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">192.168<\/span>.100.145<\/p>\n<p><span class=\"token comment\"># apiserver \u7684 DNS \u540d\u79f0&#xff0c;\u53ef\u81ea\u5b9a\u4e49<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">APISERVER_NAME<\/span><span class=\"token operator\">&#061;<\/span>abner.com<\/p>\n<p><span class=\"token comment\"># Pod \u7f51\u6bb5&#xff0c;\u5b89\u88c5\u5b8c\u6210\u540e\u7531 k8s \u521b\u5efa&#xff0c;\u7269\u7406\u7f51\u7edc\u4e2d\u4e8b\u5148\u4e0d\u5b58\u5728<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">POD_SUBNET<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">10.100<\/span>.0.1\/16<\/p>\n<p>\u91cd\u8981&#xff1a;export \u53ea\u5728\u5f53\u524d shell \u4f1a\u8bdd\u6709\u6548\u3002\u65b0\u5f00\u7a97\u53e3\u5c31\u5fc5\u987b\u91cd\u65b0\u6267\u884c\u8fd9\u4e09\u4e2a export&#xff0c;\u5426\u5219\u540e\u9762\u521d\u59cb\u5316\u811a\u672c\u4f1a\u62ff\u4e0d\u5230\u53c2\u6570&#xff08;\u8fd9\u662f\u521d\u5b66\u8005\u6700\u5e38\u8e29\u7684\u5751\u4e4b\u4e00&#xff09;\u3002<\/p>\n<h4>5.2 \u5199\u5165 hosts<\/h4>\n<p><span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">${MASTER_IP}<\/span>    <span class=\"token variable\">${APISERVER_NAME}<\/span>&#034;<\/span> <span class=\"token operator\">&gt;&gt;<\/span> \/etc\/hosts<\/p>\n<p>worker \u8282\u70b9\u4e4b\u540e\u4e5f\u8981\u5199\u540c\u4e00\u6761&#xff0c;\u4fdd\u8bc1\u96c6\u7fa4\u5185\u80fd\u901a\u8fc7 abner.com \u89e3\u6790\u5230 master\u3002<\/p>\n<h4>5.3 \u6267\u884c\u521d\u59cb\u5316<\/h4>\n<p><span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-sSL<\/span> https:\/\/kuboard.cn\/install-script\/v1.19.x\/init_master.sh <span class=\"token operator\">|<\/span> <span class=\"token function\">sh<\/span> <span class=\"token parameter variable\">-s<\/span> <span class=\"token number\">1.19<\/span>.5<\/p>\n<p>\u521d\u59cb\u5316\u5b8c\u6210\u540e\u4f1a\u6253\u5370\u51fa kubeadm \u7684\u5b8c\u6574\u8f93\u51fa&#xff0c;\u5e76\u4e14\u81ea\u52a8\u914d\u7f6e\u597d kubectl \u7684 kubeconfig\u3002<\/p>\n<h4>5.4 \u68c0\u67e5\u521d\u59cb\u5316\u7ed3\u679c<\/h4>\n<p><span class=\"token comment\"># \u89c2\u5bdf\u7cfb\u7edf\u7ec4\u4ef6&#xff0c;\u9700\u8981\u7b49\u5230\u5168\u90e8 Running<\/span><br \/>\n<span class=\"token function\">watch<\/span> kubectl get pod <span class=\"token parameter variable\">-n<\/span> kube-system <span class=\"token parameter variable\">-o<\/span> wide<\/p>\n<p>kube-system \u91cc\u4f1a\u6709 kube-apiserver\u3001kube-controller-manager\u3001kube-scheduler\u3001etcd\u3001kube-proxy\u3001coredns\u3001flannel \u7b49\u7ec4\u4ef6\u3002\u7b49\u5168\u90e8\u8fdb\u5165 Running \u518d\u7ee7\u7eed&#xff0c;\u5c24\u5176\u662f coredns \u548c\u7f51\u7edc\u63d2\u4ef6&#xff0c;\u6ca1\u8d77\u6765\u540e\u9762\u52a0\u8282\u70b9\u4f1a\u5931\u8d25\u3002<\/p>\n<p>\u67e5\u770b\u8282\u70b9\u72b6\u6001&#xff1a;<\/p>\n<p>kubectl get nodes <span class=\"token parameter variable\">-o<\/span> wide<\/p>\n<p>NAME     STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME<br \/>\nmaster   Ready    master   14m   v1.19.5   192.168.100.145   &lt;none&gt;        CentOS Linux 7 (Core)   3.10.0-693.el7.x86_64   docker:\/\/19.3.11<\/p>\n<p>STATUS&#061;Ready\u3001ROLES&#061;master\u3001CONTAINER-RUNTIME&#061;docker:\/\/&#8230;&#xff0c;\u8bf4\u660e\u63a7\u5236\u9762\u6b63\u5e38\u3002<\/p>\n<hr \/>\n<h3>\u516d\u3001\u52a0\u5165 Worker \u8282\u70b9<\/h3>\n<h4>6.1 \u5728 master \u4e0a\u751f\u6210 join \u547d\u4ee4<\/h4>\n<p>kubeadm token create &#8211;print-join-command<\/p>\n<p>\u8f93\u51fa\u5f62\u5982&#xff1a;<\/p>\n<p>W0813 21:35:29.086601   90612 configset.go:348] WARNING: kubeadm cannot validate<br \/>\ncomponent configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]<\/p>\n<p>kubeadm join abner.com:6443 &#8211;token 38699p.691qqnx340kwyhby \\\\<br \/>\n  &#8211;discovery-token-ca-cert-hash sha256:8b595b2d12528ae246fac812343f36bc30eff95bab25832b0e109a949c67dee8<\/p>\n<p>\u90a3\u6761 WARNING \u662f kubeadm \u7684\u5df2\u77e5\u63d0\u793a&#xff0c;\u4e0d\u5f71\u54cd\u4f7f\u7528\u3002token \u6709\u6548\u671f\u4e3a 2 \u5c0f\u65f6&#xff0c;\u8fc7\u671f\u91cd\u65b0\u6267\u884c\u8fd9\u6761\u547d\u4ee4\u5373\u53ef\u3002<\/p>\n<h4>6.2 \u5728 worker \u8282\u70b9\u6267\u884c\u52a0\u5165<\/h4>\n<p><span class=\"token comment\"># \u66ff\u6362\u4e3a master \u8282\u70b9\u7684\u5185\u7f51 IP<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">MASTER_IP<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">192.168<\/span>.100.145<\/p>\n<p><span class=\"token comment\"># \u5fc5\u987b\u4e0e\u521d\u59cb\u5316 master \u65f6\u7684 APISERVER_NAME \u4e00\u81f4<\/span><br \/>\n<span class=\"token builtin class-name\">export<\/span> <span class=\"token assign-left variable\">APISERVER_NAME<\/span><span class=\"token operator\">&#061;<\/span>abner.com<\/p>\n<p><span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;<span class=\"token variable\">${MASTER_IP}<\/span>    <span class=\"token variable\">${APISERVER_NAME}<\/span>&#034;<\/span> <span class=\"token operator\">&gt;&gt;<\/span> \/etc\/hosts<\/p>\n<p>kubeadm <span class=\"token function\">join<\/span> abner.com:6443 <span class=\"token parameter variable\">&#8211;token<\/span> 38699p.691qqnx340kwyhby <span class=\"token punctuation\">\\\\<\/span><br \/>\n  &#8211;discovery-token-ca-cert-hash sha256:8b595b2d12528ae246fac812343f36bc30eff95bab25832b0e109a949c67dee8<\/p>\n<h4>6.3 \u68c0\u67e5\u52a0\u5165\u7ed3\u679c<\/h4>\n<p>\u5728 master \u4e0a\u7b49\u5f85\u7ea6 5 \u5206\u949f&#xff1a;<\/p>\n<p>kubectl get <span class=\"token function\">node<\/span><\/p>\n<p>NAME     STATUS   ROLES    AGE     VERSION<br \/>\nmaster   Ready    master   31m     v1.19.5<br \/>\nnode1    Ready    &lt;none&gt;   2m57s   v1.19.5<\/p>\n<p>\u4e24\u4e2a\u8282\u70b9\u90fd\u662f Ready&#xff0c;\u96c6\u7fa4\u53ef\u7528\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u51c6\u5907 YAML&#xff1a;Deployment &#043; Service<\/h3>\n<p>\u56e0\u4e3a YAML \u8d44\u6e90\u6587\u4ef6\u53ef\u4ee5\u5728 k8s \u4e0a\u521b\u5efa\u5e94\u7528 Pod&#xff0c;\u6240\u4ee5\u8981\u63d0\u524d\u628a YAML \u51c6\u5907\u597d&#xff0c;\u5e76\u8ba9\u5b83\u968f\u9879\u76ee\u4e00\u8d77\u8fdb\u5165 Git \u4ed3\u5e93\u3002<\/p>\n<p>\u5728 GitLab \u9879\u76ee\u4e2d\u65b0\u5efa\u6587\u4ef6 pipeline.yml&#xff08;\u63a8\u8350\u653e\u5728\u6839\u76ee\u5f55&#xff09;\u3002<\/p>\n<p>\u5730\u5740\u7ea6\u5b9a&#xff08;\u5f88\u91cd\u8981&#xff09;&#xff1a;\u672c\u6587\u7edf\u4e00\u6309 Harbor &#061; 192.168.100.154:80\u3001K8s master &#061; 192.168.100.145 \u6765\u5199\u3002\u539f\u7b14\u8bb0\u91cc secret \u548c YAML \u4e2d\u66fe\u51fa\u73b0\u8fc7 192.168.100.145:80&#xff08;Harbor \u4e0e master \u540c\u673a\u65f6\u7684\u5199\u6cd5&#xff09;&#xff0c;\u800c\u4f60\u5982\u679c\u786e\u5b9e\u628a Harbor \u88c5\u5728 master \u4e0a&#xff0c;\u5c31\u628a\u4e0b\u9762\u6240\u6709 154 \u6362\u6210 145 \u5373\u53ef\u2014\u2014\u4f46\u5fc5\u987b\u56db\u5904\u540c\u65f6\u6539&#xff1a;harbor-secret \u7684 &#8211;docker-server\u3001YAML \u7684 image\u3001\u5404\u8282\u70b9 daemon.json \u7684 insecure-registries\u3001Jenkinsfile \u91cc\u7684 ${hbaddr}\u3002<\/p>\n<p>\u5148\u770b\u4e00\u4efd\u5b8c\u6574\u7684\u8d44\u6e90\u6e05\u5355&#xff1a;<\/p>\n<p><span class=\"token key atrule\">apiVersion<\/span><span class=\"token punctuation\">:<\/span> apps\/v1<br \/>\n<span class=\"token key atrule\">kind<\/span><span class=\"token punctuation\">:<\/span> Deployment<br \/>\n<span class=\"token key atrule\">metadata<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n  <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n<span class=\"token key atrule\">spec<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">replicas<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">2<\/span><br \/>\n  <span class=\"token key atrule\">selector<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">matchLabels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n  <span class=\"token key atrule\">template<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">metadata<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n    <span class=\"token key atrule\">spec<\/span><span class=\"token punctuation\">:<\/span><br \/>\n      <span class=\"token key atrule\">imagePullSecrets<\/span><span class=\"token punctuation\">:<\/span>                 <span class=\"token comment\"># \u5173\u952e&#xff1a;\u79c1\u6709\u4ed3\u5e93\u62c9\u53d6\u51ed\u8bc1<\/span><br \/>\n        <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> harbor<span class=\"token punctuation\">&#8211;<\/span>secret<br \/>\n      <span class=\"token key atrule\">containers<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n          <span class=\"token key atrule\">image<\/span><span class=\"token punctuation\">:<\/span> 192.168.100.154<span class=\"token punctuation\">:<\/span>80\/repo\/pipeline<span class=\"token punctuation\">:<\/span>v4.0<br \/>\n          <span class=\"token key atrule\">imagePullPolicy<\/span><span class=\"token punctuation\">:<\/span> Always       <span class=\"token comment\"># \u590d\u7528\u540c\u540d tag&#xff0c;\u5fc5\u987b Always<\/span><br \/>\n          <span class=\"token key atrule\">ports<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">containerPort<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">8080<\/span><br \/>\n<span class=\"token punctuation\">&#8212;<\/span><br \/>\n<span class=\"token key atrule\">apiVersion<\/span><span class=\"token punctuation\">:<\/span> v1<br \/>\n<span class=\"token key atrule\">kind<\/span><span class=\"token punctuation\">:<\/span> Service<br \/>\n<span class=\"token key atrule\">metadata<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n  <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n<span class=\"token key atrule\">spec<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token key atrule\">selector<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token key atrule\">app<\/span><span class=\"token punctuation\">:<\/span> pipeline<br \/>\n  <span class=\"token key atrule\">ports<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">8081<\/span><br \/>\n      <span class=\"token key atrule\">targetPort<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">8080<\/span><br \/>\n  <span class=\"token key atrule\">type<\/span><span class=\"token punctuation\">:<\/span> NodePort<\/p>\n<h4>7.1 \u4e09\u4e2a\u5173\u952e\u5b57\u6bb5&#xff0c;\u51b3\u5b9a\u4e86\u80fd\u4e0d\u80fd\u8dd1\u8d77\u6765<\/h4>\n<p>\u2460 imagePullSecrets \u4e0e secret \u7684\u5bf9\u5e94\u5173\u7cfb<\/p>\n<p><span class=\"token key atrule\">imagePullSecrets<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> harbor<span class=\"token punctuation\">&#8211;<\/span>secret<\/p>\n<p>\u8fd9\u662f&#034;\u7528\u54ea\u4e2a\u51ed\u8bc1\u53bb\u79c1\u6709\u4ed3\u5e93\u62c9\u955c\u50cf&#034;\u3002kubelet \u62c9\u955c\u50cf\u662f\u4e0d\u8ba4 docker login \u4fdd\u5b58\u5728 \/root\/.docker\/config.json \u91cc\u7684\u51ed\u8bc1\u7684&#xff08;\u5b83\u4e0d\u8bfb\u90a3\u4e2a\u6587\u4ef6&#xff09;&#xff0c;\u6240\u4ee5\u5fc5\u987b\u5728\u96c6\u7fa4\u91cc\u521b\u5efa\u4e00\u4e2a docker-registry \u7c7b\u578b\u7684 secret&#xff0c;\u5e76\u5728 Pod \u6a21\u677f\u91cc\u5f15\u7528\u3002\u6ca1\u8fd9\u4e00\u6b65&#xff0c;Pod \u4e00\u5b9a ImagePullBackOff\u3002<\/p>\n<p>\u2461 imagePullPolicy: Always<\/p>\n<p><span class=\"token key atrule\">imagePullPolicy<\/span><span class=\"token punctuation\">:<\/span> Always<\/p>\n<p>\u6211\u4eec\u590d\u7528\u4e86\u540c\u540d tag v4.0&#xff08;\u6bcf\u6b21\u6784\u5efa\u8986\u76d6\u540c\u4e00\u4e2a tag&#xff09;\u3002Always \u4fdd\u8bc1\u6bcf\u6b21\u542f\u52a8\u90fd\u91cd\u65b0\u62c9\u53d6&#xff0c;\u5426\u5219\u8282\u70b9\u4e0a\u4f1a\u7ee7\u7eed\u7528\u65e7\u955c\u50cf\u7f13\u5b58&#xff0c;\u51fa\u73b0&#034;\u6784\u5efa\u6210\u529f\u4e86&#xff0c;\u7ebf\u4e0a\u8fd8\u662f\u8001\u4ee3\u7801&#034;\u7684\u7075\u5f02\u73b0\u8c61\u3002<\/p>\n<p>\u2462 replicas: 2 &#043; selector.matchLabels<\/p>\n<p>replicas: 2 \u8868\u793a\u4e24\u4e2a\u526f\u672c&#xff0c;\u8c03\u5ea6\u5668\u4f1a\u628a\u5b83\u4eec\u5206\u6563\u5230\u53ef\u7528\u8282\u70b9&#xff08;\u8fd9\u91cc\u53ea\u6709\u4e00\u4e2a node1&#xff0c;\u6240\u4ee5\u4e24\u4e2a Pod \u90fd\u5728 node1&#xff0c;IP \u4e0d\u540c&#xff09;\u3002selector.matchLabels.app: pipeline \u5fc5\u987b\u4e0e template.metadata.labels \u5b8c\u5168\u5bf9\u5e94&#xff0c;\u5199\u9519\u4f1a\u62a5 selector does not match template labels\u3002<\/p>\n<h4>7.2 Service \u7684\u7aef\u53e3\u94fe\u6761&#xff08;\u6700\u5bb9\u6613\u641e\u6df7\u7684\u5730\u65b9&#xff09;<\/h4>\n<p><span class=\"token key atrule\">ports<\/span><span class=\"token punctuation\">:<\/span><br \/>\n  <span class=\"token punctuation\">&#8211;<\/span> <span class=\"token key atrule\">port<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">8081<\/span>        <span class=\"token comment\"># Service \u5728\u96c6\u7fa4\u5185\u7684\u7aef\u53e3<\/span><br \/>\n    <span class=\"token key atrule\">targetPort<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">8080<\/span>  <span class=\"token comment\"># \u5bb9\u5668\u5b9e\u9645\u76d1\u542c\u7684\u7aef\u53e3<\/span><br \/>\n<span class=\"token key atrule\">type<\/span><span class=\"token punctuation\">:<\/span> NodePort        <span class=\"token comment\"># \u989d\u5916\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u5f00\u4e00\u4e2a\u9ad8\u4f4d\u7aef\u53e3<\/span><\/p>\n<p>\u5b9e\u9645\u751f\u6548\u540e kubectl get svc \u4f1a\u663e\u793a&#xff1a;<\/p>\n<p>NAME       TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE<br \/>\npipeline   NodePort   10.96.131.139  &lt;none&gt;        8081:30724\/TCP   45m<\/p>\n<p>\u4e09\u5c42\u7aef\u53e3\u8981\u5206\u6e05&#xff1a;<\/p>\n<table>\n<tr>\u5c42\u503c\u8c01\u6765\u8bbf\u95ee<\/tr>\n<tbody>\n<tr>\n<td>containerPort<\/td>\n<td>8080<\/td>\n<td>Pod \u5185\u5e94\u7528\u76d1\u542c<\/td>\n<\/tr>\n<tr>\n<td>port<\/td>\n<td>8081<\/td>\n<td>\u96c6\u7fa4\u5185\u90e8\u5176\u4ed6\u670d\u52a1\u901a\u8fc7 pipeline:8081 \u8bbf\u95ee<\/td>\n<\/tr>\n<tr>\n<td>nodePort<\/td>\n<td>30724<\/td>\n<td>\u96c6\u7fa4\u5916\u90e8\u901a\u8fc7 \u8282\u70b9IP:30724 \u8bbf\u95ee&#xff08;\u8303\u56f4 30000-32767&#xff0c;\u672a\u6307\u5b9a\u5219\u968f\u673a\u5206\u914d&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u4ee5\u6700\u7ec8\u8bbf\u95ee\u5730\u5740\u662f http:\/\/192.168.100.146:30724\/test\u2014\u2014\u4e0d\u662f 8081\u3002\u8fd9\u4e2a\u5751\u51e0\u4e4e\u4eba\u4eba\u90fd\u8e29&#xff1a;port: 8081 \u53ea\u662f&#034;\u96c6\u7fa4\u5185\u7684\u95e8\u724c\u53f7&#034;&#xff0c;\u5bf9\u5916\u7684\u90a3\u6247\u95e8\u662f nodePort\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u521b\u5efa harbor-secret&#xff08;\u6700\u5173\u952e\u7684\u4e00\u6b65&#xff09;<\/h3>\n<p>\u5728 master \u8282\u70b9\u4f18\u5148\u521b\u5efa secret \u8d44\u6e90&#xff0c;\u7528\u6765\u4fdd\u5b58\u8bbf\u95ee Harbor \u7684\u51ed\u8bc1&#xff0c;\u5426\u5219\u955c\u50cf\u62c9\u53d6\u4f1a\u5931\u8d25&#xff1a;<\/p>\n<p>kubectl create secret docker-registry harbor-secret <span class=\"token punctuation\">\\\\<\/span><br \/>\n  &#8211;docker-server<span class=\"token operator\">&#061;<\/span><span class=\"token number\">192.168<\/span>.100.154:80 <span class=\"token punctuation\">\\\\<\/span><br \/>\n  &#8211;docker-username<span class=\"token operator\">&#061;<\/span>admin <span class=\"token punctuation\">\\\\<\/span><br \/>\n  &#8211;docker-password<span class=\"token operator\">&#061;<\/span>harbor123<\/p>\n<p>\u53c2\u6570\u8bf4\u660e&#xff1a;<\/p>\n<table>\n<tr>\u53c2\u6570\u542b\u4e49\u6ce8\u610f<\/tr>\n<tbody>\n<tr>\n<td>docker-registry<\/td>\n<td>secret \u7c7b\u578b<\/td>\n<td>\u4e13\u95e8\u7ed9\u79c1\u6709\u955c\u50cf\u4ed3\u5e93\u7528<\/td>\n<\/tr>\n<tr>\n<td>harbor-secret<\/td>\n<td>secret \u540d\u79f0<\/td>\n<td>\u5fc5\u987b\u4e0e YAML \u91cc imagePullSecrets.name \u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>&#8211;docker-server<\/td>\n<td>\u4ed3\u5e93\u5730\u5740<\/td>\n<td>\u5fc5\u987b\u5e26\u7aef\u53e3&#xff0c;\u4e14\u4e0e YAML \u91cc image \u524d\u7f00\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>&#8211;docker-username \/ &#8211;docker-password<\/td>\n<td>\u8d26\u53f7\u5bc6\u7801<\/td>\n<td>Harbor \u7684\u7ba1\u7406\u5458\u8d26\u53f7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u521b\u5efa\u540e\u786e\u8ba4&#xff1a;<\/p>\n<p>kubectl get secret harbor-secret<br \/>\nkubectl describe secret harbor-secret<\/p>\n<p>\u5982\u679c secret \u521b\u5efa\u5728\u975e default \u547d\u540d\u7a7a\u95f4&#xff0c;YAML \u4e5f\u8981\u6307\u5b9a\u540c\u4e00\u4e2a namespace&#xff0c;\u5426\u5219 Pod \u627e\u4e0d\u5230 secret\u3002\u8fd9\u662f&#034;\u660e\u660e\u5efa\u4e86 secret \u5374\u8fd8\u662f ImagePullBackOff&#034;\u7684\u7b2c\u4e8c\u5927\u539f\u56e0\u3002<\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u8ba9\u6240\u6709\u8282\u70b9\u4fe1\u4efb Harbor<\/h3>\n<p>\u56e0\u4e3a Harbor \u7528\u7684\u662f HTTP&#xff08;\u975e HTTPS&#xff09;&#xff0c;\u6bcf\u4e2a k8s \u8282\u70b9&#xff08;master \u548c node1&#xff09;\u7684 Docker \u90fd\u5fc5\u987b\u4fe1\u4efb\u5b83\u3002\u6ce8\u610f\u662f\u6240\u6709\u8282\u70b9&#xff0c;\u4e0d\u53ea\u662f master\u2014\u2014\u955c\u50cf\u5b9e\u9645\u662f\u5728 node1 \u4e0a\u62c9\u7684\u3002<\/p>\n<p><span class=\"token function\">vim<\/span> \/etc\/docker\/daemon.json<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token string-property property\">&#034;insecure-registries&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;192.168.100.154:80&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;registry-mirrors&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;https:\/\/registry.cn-hangzhou.aliyuncs.com&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;exec-opts&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;native.cgroupdriver&#061;systemd&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;log-driver&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;json-file&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;log-opts&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string-property property\">&#034;max-size&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;100m&#034;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;storage-driver&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;overlay2&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token string-property property\">&#034;storage-opts&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token string\">&#034;overlay2.override_kernel_check&#061;true&#034;<\/span><br \/>\n  <span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u51e0\u4e2a\u5b57\u6bb5\u7684\u610f\u4e49&#xff1a;<\/p>\n<ul>\n<li>insecure-registries&#xff1a;\u4fe1\u4efb\u7684 HTTP \u4ed3\u5e93\u5217\u8868&#xff08;\u672c\u7ae0\u65b0\u589e&#xff09;\u3002<\/li>\n<li>exec-opts: native.cgroupdriver&#061;systemd&#xff1a;cgroup \u9a71\u52a8\u5fc5\u987b\u4e0e kubelet \u4e00\u81f4&#xff0c;\u5426\u5219\u8282\u70b9\u4f1a NotReady\u3002<\/li>\n<li>log-driver \/ log-opts&#xff1a;\u9650\u5236\u5355\u4e2a\u5bb9\u5668\u65e5\u5fd7\u5927\u5c0f&#xff0c;\u9632\u6b62\u65e5\u5fd7\u628a\u78c1\u76d8\u5199\u6ee1\u3002<\/li>\n<li>storage-driver: overlay2&#xff1a;\u63a8\u8350\u7684\u5b58\u50a8\u9a71\u52a8\u3002<\/li>\n<\/ul>\n<p>\u91cd\u542f Docker \u5e76\u9a8c\u8bc1\u767b\u5f55&#xff1a;<\/p>\n<p>systemctl restart <span class=\"token function\">docker<\/span><\/p>\n<p><span class=\"token function\">docker<\/span> login <span class=\"token number\">192.168<\/span>.100.154:80 <span class=\"token parameter variable\">-u<\/span> admin <span class=\"token parameter variable\">-p<\/span> harbor123<br \/>\n<span class=\"token comment\"># Login Succeeded<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;\u91cd\u542f Docker \u540e\u5982\u679c kubelet \u62a5\u9519\u3001\u8282\u70b9 NotReady&#xff0c;\u6267\u884c systemctl restart kubelet \u5373\u53ef\u6062\u590d\u3002\u6539 daemon.json \u8fd9\u7c7b\u64cd\u4f5c\u5efa\u8bae\u5728\u4e1a\u52a1\u4f4e\u5cf0\u505a\u3002<\/p>\n<hr \/>\n<h3>\u5341\u3001Jenkins \u628a YAML \u63a8\u5230 master<\/h3>\n<p>\u601d\u8def&#xff1a;Jenkins \u4e0d\u76f4\u63a5\u5728 master \u4e0a\u5199\u6587\u4ef6&#xff0c;\u800c\u662f\u628a\u5de5\u4f5c\u533a\u91cc\u7684 pipeline.yml \u63a8\u5230 master \u7684\u6307\u5b9a\u76ee\u5f55&#xff0c;\u518d\u7528 kubectl apply \u5e94\u7528\u5b83\u3002<\/p>\n<h4>10.1 \u5728 master \u4e0a\u51c6\u5907\u76ee\u6807\u76ee\u5f55<\/h4>\n<p><span class=\"token function\">mkdir<\/span> \/usr\/local\/k8s<br \/>\n<span class=\"token function\">chmod<\/span> <span class=\"token number\">777<\/span> \/usr\/local\/k8s\/<\/p>\n<p>777 \u662f\u4e3a\u4e86\u8ba9 Jenkins \u63a8\u9001\u7528\u6237\u6709\u5199\u6743\u9650&#xff08;\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u6539\u6210\u6307\u5b9a\u5c5e\u4e3b &#043; 755&#xff09;\u3002<\/p>\n<h4>10.2 \u914d\u7f6e Publish Over SSH<\/h4>\n<p>Jenkins\u300c\u7cfb\u7edf\u7ba1\u7406 \u2192 \u7cfb\u7edf\u914d\u7f6e \u2192 Publish over SSH\u300d&#xff1a;<\/p>\n<ul>\n<li>Passphrase \/ Path to key&#xff1a;Jenkins \u4e0e\u76ee\u6807\u673a\u4e4b\u95f4\u7684\u5bc6\u94a5&#xff08;\u89c1\u4e0b\u4e00\u8282\u514d\u5bc6\u914d\u7f6e&#xff09;<\/li>\n<li>SSH Servers \u65b0\u589e\u4e00\u53f0&#xff1a;\n<ul>\n<li>Name&#xff1a;k8s-master&#xff08;\u6216\u6cbf\u7528 test&#xff0c;\u53ea\u8981\u4e0e\u6d41\u6c34\u7ebf\u91cc configName \u4e00\u81f4&#xff09;<\/li>\n<li>Hostname&#xff1a;192.168.100.145<\/li>\n<li>Username&#xff1a;root<\/li>\n<li>Remote Directory&#xff1a;\/usr\/local\/k8s<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u586b\u5b8c\u70b9 \u300cTest Configuration\u300d&#xff0c;\u663e\u793a Success \u540e\u518d\u300c\u5e94\u7528\u5e76\u4fdd\u5b58\u300d\u3002<\/p>\n<p>Test Configuration \u5931\u8d25\u57fa\u672c\u90fd\u662f\u4e09\u7c7b\u539f\u56e0&#xff1a;\u7f51\u7edc\u4e0d\u901a\u3001\u8d26\u53f7\u5bc6\u7801\/\u5bc6\u94a5\u9519\u3001Remote Directory \u4e0d\u5b58\u5728\u3002\u5148\u624b\u5de5 ssh root&#064;192.168.100.145 \u9a8c\u8bc1\u901a\u4e0d\u901a\u3002<\/p>\n<h4>10.3 \u4fee\u6539 Jenkinsfile \u7684\u63a8\u9001\u6b65\u9aa4<\/h4>\n<p>\u5230 GitLab \u4e0a\u4fee\u6539 Jenkinsfile \u91cc Publish Over SSH \u90a3\u4e2a stage&#xff0c;\u628a sourceFiles \u6307\u5411 yml&#xff0c;remoteDirectory \u6307\u5411\u76ee\u6807\u76ee\u5f55&#xff1a;<\/p>\n<p><span class=\"token function\">stage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u63a8\u9001 YAML \u5230 k8s master&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    steps <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">sshPublisher<\/span><span class=\"token punctuation\">(<\/span>publishers<span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token function\">sshPublisherDesc<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            configName<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;k8s-master&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            transfers<span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token function\">sshTransfer<\/span><span class=\"token punctuation\">(<\/span><br \/>\n                cleanRemote<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                excludes<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                execCommand<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                execTimeout<span class=\"token punctuation\">:<\/span> <span class=\"token number\">120000<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                flatten<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                makeEmptyDirs<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                noDefaultExcludes<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                patternSeparator<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;[, ]&#043;&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                remoteDirectory<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;\/usr\/local\/k8s&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                remoteDirectorySDF<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                removePrefix<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                sourceFiles<span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#039;pipeline.yml&#039;<\/span>      <span class=\"token comment\">\/\/ \u76f8\u5bf9 Jenkins \u5de5\u4f5c\u533a<\/span><br \/>\n            <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            usePromotionTimestamp<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            useWorkspaceInPromotion<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            verbose<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>10.4 \u4fdd\u5b58\u540e\u5148\u6784\u5efa\u4e00\u6b21&#xff0c;\u6d4b\u8bd5\u63a8\u9001<\/h4>\n<p>\u4fdd\u5b58\u914d\u7f6e&#xff0c;\u7136\u540e\u70b9\u300c\u7acb\u5373\u6784\u5efa\u300d\u524d\u8bb0\u5f97\u52a0\u4e00\u4e2a\u65b0 tag\u2014\u2014\u5426\u5219\u5de5\u4f5c\u533a\u4e0d\u4f1a\u5237\u65b0&#xff0c;Jenkins \u8bc6\u522b\u4e0d\u5230\u65b0\u6dfb\u52a0\u7684 yml \u6587\u4ef6\u3002<\/p>\n<p>\u6784\u5efa\u5b8c\u6210\u540e\u67e5\u770b\u6784\u5efa\u65e5\u5fd7&#xff0c;\u518d\u5230 master \u4e0a\u786e\u8ba4&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># ls \/usr\/local\/k8s\/<\/span><br \/>\npipeline.yml<\/p>\n<p>\u6587\u4ef6\u5df2\u6210\u529f\u4f20\u9012\u3002&#xff08;\u65e5\u5fd7\u91cc\u80fd\u770b\u5230 SSH: Transferred 1 file(s) \u4e4b\u7c7b\u7684\u5b57\u6837\u3002&#xff09;<\/p>\n<hr \/>\n<h3>\u5341\u4e00\u3001Jenkins \u514d\u5bc6 SSH \u767b\u5f55 master<\/h3>\n<p>\u540e\u9762\u8981\u5728\u6d41\u6c34\u7ebf\u91cc\u6267\u884c ssh root&#064;192.168.100.145 kubectl apply -f &#8230;&#xff0c;\u8fd9\u4e00\u6b65\u662f\u4ea4\u4e92\u5f0f\u7684&#xff08;\u8981\u8f93\u5bc6\u7801&#xff09;&#xff0c;\u6d41\u6c34\u7ebf\u91cc\u4f1a\u5361\u6b7b\u3002\u6240\u4ee5\u5fc5\u987b\u914d\u7f6e\u514d\u5bc6\u3002<\/p>\n<h4>11.1 \u5728 Jenkins \u5bb9\u5668\u5185\u751f\u6210\u5bc6\u94a5<\/h4>\n<p><span class=\"token function\">docker<\/span> <span class=\"token builtin class-name\">exec<\/span> <span class=\"token parameter variable\">-it<\/span> jenkins <span class=\"token function\">bash<\/span><\/p>\n<p>jenkins&#064;0eb81fc79a4a:\/$ <span class=\"token builtin class-name\">cd<\/span> ~<br \/>\njenkins&#064;0eb81fc79a4a:~$ ssh-keygen <span class=\"token parameter variable\">-t<\/span> rsa<br \/>\n<span class=\"token comment\"># \u4e00\u8def\u56de\u8f66&#xff08;\u4e0d\u8981\u8bbe passphrase&#xff0c;\u5426\u5219\u6d41\u6c34\u7ebf\u91cc\u4ecd\u9700\u4ea4\u4e92&#xff09;<\/span><\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>Generating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/var\/jenkins_home\/.ssh\/id_rsa):<br \/>\nCreated directory &#039;\/var\/jenkins_home\/.ssh&#039;.<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/var\/jenkins_home\/.ssh\/id_rsa<br \/>\nYour public key has been saved in \/var\/jenkins_home\/.ssh\/id_rsa.pub<\/p>\n<p>jenkins&#064;0eb81fc79a4a:~$ <span class=\"token builtin class-name\">cd<\/span> .ssh\/<br \/>\njenkins&#064;0eb81fc79a4a:~\/.ssh$ <span class=\"token function\">ls<\/span><br \/>\nid_rsa  id_rsa.pub<\/p>\n<p>passphrase \u4e00\u5b9a\u8981\u7559\u7a7a\u3002\u8bbe\u4e86\u5bc6\u7801&#xff0c;\u6d41\u6c34\u7ebf\u6267\u884c\u65f6\u540c\u6837\u4f1a\u5361\u4f4f&#xff08;\u9664\u975e\u7528 ssh-agent&#xff09;\u3002<\/p>\n<h4>11.2 \u590d\u5236\u516c\u94a5\u5230 master<\/h4>\n<p>jenkins&#064;0eb81fc79a4a:~\/.ssh$ <span class=\"token function\">cat<\/span> id_rsa.pub<br \/>\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEQpb25fdoeJS3f\/c5cXXxuqIQ\/x3OHOR8hKOB<span class=\"token punctuation\">..<\/span>.<\/p>\n<p>\u7136\u540e\u5728 master \u4e0a&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># mkdir .ssh<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># cd .ssh\/<\/span><br \/>\n<span class=\"token punctuation\">[<\/span>root&#064;master .ssh<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># vim authorized_keys<\/span><br \/>\n<span class=\"token comment\"># \u7c98\u8d34\u4e0a\u4e00\u6b65\u7684\u6574\u884c\u516c\u94a5&#xff0c;\u4fdd\u5b58<\/span><\/p>\n<p>\u6ce8\u610f&#xff1a;authorized_keys \u4e00\u884c\u53ea\u80fd\u653e\u4e00\u4e2a\u516c\u94a5&#xff0c;\u7c98\u8d34\u65f6\u4e0d\u8981\u6362\u884c\u3001\u4e0d\u8981\u5e26\u591a\u4f59\u7a7a\u683c&#xff0c;\u5426\u5219\u8ba4\u8bc1\u5931\u8d25\u3002<\/p>\n<h4>11.3 \u91cd\u542f sshd \u5e76\u6d4b\u8bd5<\/h4>\n<p><span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># systemctl restart sshd<\/span><\/p>\n<p>\u56de\u5230 Jenkins \u5bb9\u5668\u5185\u6d4b\u8bd5&#xff1a;<\/p>\n<p>jenkins&#064;0eb81fc79a4a:~\/.ssh$ <span class=\"token function\">ssh<\/span> root&#064;192.168.100.145 <span class=\"token function\">ls<\/span> \/<br \/>\nbin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root<br \/>\nrun  sbin  srv  sys  tmp  usr  var<\/p>\n<p>\u6ca1\u6709\u63d0\u793a\u8f93\u5bc6\u7801&#xff0c;\u76f4\u63a5\u5217\u51fa\u76ee\u5f55&#xff0c;\u8bf4\u660e\u514d\u5bc6\u6210\u529f\u3002<\/p>\n<p>\u5982\u679c\u4ecd\u7136\u8981\u6c42\u5bc6\u7801&#xff0c;\u6309\u987a\u5e8f\u6392\u67e5&#xff1a;\u2460 ~\/.ssh \u6743\u9650\u5e94\u4e3a 700\u3001authorized_keys \u5e94\u4e3a 600&#xff1b;\u2461 master \u4e0a PermitRootLogin \u662f\u5426\u4e3a yes&#xff1b;\u2462 \u516c\u94a5\u6709\u6ca1\u6709\u88ab\u7f16\u8f91\u5668\u6298\u884c\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e8c\u3001\u6d41\u6c34\u7ebf\u589e\u52a0 kubectl \u90e8\u7f72\u9636\u6bb5<\/h3>\n<h4>12.1 \u7528\u300c\u6d41\u6c34\u7ebf\u8bed\u6cd5\u300d\u751f\u6210 sh \u7247\u6bb5<\/h4>\n<p>\u5728\u4efb\u52a1\u300c\u914d\u7f6e \u2192 \u6d41\u6c34\u7ebf\u8bed\u6cd5\u300d\u91cc\u9009 sh&#xff0c;\u8f93\u5165&#xff1a;<\/p>\n<p><span class=\"token function\">ssh<\/span> root&#064;192.168.100.145 kubectl apply <span class=\"token parameter variable\">-f<\/span> \/usr\/local\/k8s\/pipeline.yml<\/p>\n<p>\u6ce8\u610f&#xff1a;kubectl \u5fc5\u987b\u5199\u7edd\u5bf9\u8def\u5f84\u6216\u7528 ssh \u767b\u5f55\u540e\u7684\u9ed8\u8ba4 PATH \u80fd\u627e\u5230\u7684\u8def\u5f84&#xff0c;pipeline.yml \u4e5f\u5fc5\u987b\u662f\u7edd\u5bf9\u8def\u5f84\u2014\u2014\u56e0\u4e3a\u901a\u8fc7 ssh \u6267\u884c\u7684\u662f\u4e00\u6761\u975e\u4ea4\u4e92\u547d\u4ee4&#xff0c;\u5b83\u7684\u5de5\u4f5c\u76ee\u5f55\u662f root \u7684\u5bb6\u76ee\u5f55&#xff0c;\u4e0d\u662f \/usr\/local\/k8s\u3002<\/p>\n<h4>12.2 \u5728 GitLab \u7684 Jenkinsfile \u91cc\u589e\u52a0 stage<\/h4>\n<p><span class=\"token function\">stage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u8fdc\u7a0b\u6267\u884c kubectl \u547d\u4ee4&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    steps <span class=\"token punctuation\">{<\/span><br \/>\n        sh <span class=\"token string\">&#039;ssh root&#064;192.168.100.145 kubectl apply -f \/usr\/local\/k8s\/pipeline.yml&#039;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5efa\u8bae\u653e\u5728\u300c\u63a8\u9001 YAML\u300d\u9636\u6bb5\u4e4b\u540e&#xff1a;<\/p>\n<p>stage(&#039;maven \u6784\u5efa&#039;) \u2192 stage(&#039;sonarqube \u68c0\u6d4b&#039;) \u2192 stage(&#039;Docker \u5236\u4f5c\u955c\u50cf&#039;)<br \/>\n\u2192 stage(&#039;\u63a8\u9001 Harbor&#039;) \u2192 stage(&#039;\u63a8\u9001 YAML \u5230 master&#039;) \u2192 stage(&#039;\u8fdc\u7a0b\u6267\u884c kubectl \u547d\u4ee4&#039;)<\/p>\n<p>\u987a\u5e8f\u5f88\u91cd\u8981&#xff1a;YAML \u5fc5\u987b\u5148\u5230 master&#xff0c;kubectl apply \u624d\u80fd\u8bfb\u5230\u6587\u4ef6\u3002\u53cd\u4e86\u5c31\u62a5 no such file or directory\u3002<\/p>\n<h4>12.3 \u4e00\u4e2a\u66f4\u5065\u58ee\u7684\u5199\u6cd5&#xff08;\u53ef\u9009&#xff09;<\/h4>\n<p>sh <span class=\"token string\">&#039;&#039;&#039;<br \/>\n  ssh root&#064;192.168.100.145 &#034;kubectl apply -f \/usr\/local\/k8s\/pipeline.yml&#034;<br \/>\n  ssh root&#064;192.168.100.145 &#034;kubectl rollout status deployment\/pipeline &#8211;timeout&#061;120s&#034;<br \/>\n&#039;&#039;&#039;<\/span><\/p>\n<p>rollout status \u4f1a\u963b\u585e\u7b49\u5f85\u6eda\u52a8\u66f4\u65b0\u5b8c\u6210&#xff0c;\u6d41\u6c34\u7ebf\u5931\u8d25\u80fd\u7acb\u523b\u53cd\u6620&#xff0c;\u800c\u4e0d\u662f&#034;apply \u6210\u529f\u4f46 Pod \u8d77\u4e0d\u6765&#034;\u5374\u663e\u793a\u7eff\u706f\u3002\u751f\u4ea7\u73af\u5883\u5f3a\u70c8\u5efa\u8bae\u52a0\u8fd9\u4e00\u6b65\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e09\u3001\u7248\u672c\u540c\u6b65&#xff1a;tag\u3001YAML\u3001\u4ee3\u7801\u4e09\u5904\u5bf9\u9f50<\/h3>\n<p>\u8fd9\u4e00\u6b65\u662f\u672c\u7ae0\u6700\u5bb9\u6613\u6f0f\u7684\u5730\u65b9\u3002\u56e0\u4e3a\u62c9\u53d6\u7684\u9879\u76ee\u6807\u7b7e\u662f v4.0&#xff0c;pipeline.yml \u91cc\u62c9\u53d6\u955c\u50cf\u7684\u6807\u7b7e\u4e5f\u8981\u540c\u6b65\u53d8\u66f4\u3002<\/p>\n<h4>13.1 \u4e09\u5904\u5fc5\u987b\u4e00\u8d77\u6539<\/h4>\n<table>\n<tr>#\u4f4d\u7f6e\u5185\u5bb9\u4e0d\u6539\u7684\u540e\u679c<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u6784\u5efa\u53c2\u6570 tag<\/td>\n<td>v4.0<\/td>\n<td>\u955c\u50cf\u540d\u5bf9\u4e0d\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>pipeline.yml \u7684 image<\/td>\n<td>&#8230;pipeline:v4.0<\/td>\n<td>\u62c9\u7684\u8fd8\u662f\u65e7\u955c\u50cf<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Harbor \u91cc\u7684 tag<\/td>\n<td>\u9700\u91cd\u65b0 push<\/td>\n<td>\u62c9\u53d6\u5931\u8d25 manifest unknown<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>13.2 \u987a\u5e26\u6539\u4e00\u4e0b\u9996\u9875&#xff0c;\u4fbf\u4e8e\u9a8c\u8bc1<\/h4>\n<p>\u8def\u5f84&#xff1a;src\/main\/java\/com\/chenyan\/demo\/controller\/TestController.java&#xff0c;\u628a\u8fd4\u56de\u5185\u5bb9\u6539\u4e00\u4e0b&#xff08;\u6bd4\u5982\u52a0\u4e0a\u7248\u672c\u53f7&#xff09;&#xff0c;\u8fd9\u6837\u9875\u9762\u4e0a\u4e00\u773c\u5c31\u80fd\u770b\u51fa\u65b0\u7248\u672c\u662f\u5426\u751f\u6548\u3002<\/p>\n<h4>13.3 \u5220\u9664\u5e76\u91cd\u5efa\u540c\u540d tag<\/h4>\n<p>\u5728 GitLab \u4e2d\u628a\u539f\u6765\u7684 v4.0 \u6807\u7b7e\u5220\u9664&#xff0c;\u91cd\u65b0\u521b\u5efa&#xff0c;\u547d\u540d\u4f9d\u7136\u5199 v4.0&#xff0c;\u7136\u540e\u70b9\u300c\u7acb\u5373\u6784\u5efa\u300d\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u5220\u4e86\u91cd\u5efa\u540c\u4e00\u4e2a\u540d\u5b57&#xff1f; kuboard\/\u6d41\u6c34\u7ebf\u91cc\u7528 ${JOB_NAME}:${tag} \u505a\u955c\u50cf\u540d&#xff0c;tag \u4e0d\u53d8\u5c31\u610f\u5473\u7740&#034;\u540c\u4e00\u8def\u5f84\u88ab\u8986\u76d6&#034;\u3002\u8fd9\u672c\u8eab\u662f\u53ef\u7528\u7684&#xff08;\u914d\u5408 imagePullPolicy: Always&#xff09;&#xff0c;\u4f46 GitLab \u7684 tag \u662f\u6307\u9488&#xff0c;\u76f4\u63a5\u8986\u76d6\u540c\u4e00\u4e2a tag \u4f1a\u8ba9&#034;\u5230\u5e95\u54ea\u4e2a commit \u5bf9\u5e94\u54ea\u4e2a\u955c\u50cf&#034;\u53d8\u5f97\u4e0d\u53ef\u8ffd\u6eaf\u3002\u5220\u6389\u91cd\u5efa&#xff0c;\u7b49\u4e8e\u5f3a\u5236\u5237\u65b0\u8fd9\u4e2a\u6307\u9488\u3002<\/p>\n<h4>13.4 \u26a0\ufe0f \u4e00\u4e2a\u5fc5\u987b\u7edf\u4e00\u7684\u547d\u540d\u95ee\u9898<\/h4>\n<p>\u539f\u7b14\u8bb0\u91cc\u5b58\u5728\u4e24\u5904\u547d\u540d\u4e0d\u4e00\u81f4&#xff0c;\u5b9e\u9645\u6267\u884c\u65f6\u4e00\u5b9a\u4f1a\u51fa\u95ee\u9898&#xff0c;\u52a1\u5fc5\u5148\u7edf\u4e00&#xff1a;<\/p>\n<table>\n<tr>\u4f4d\u7f6e\u539f\u7b14\u8bb0\u5199\u6cd5\u95ee\u9898<\/tr>\n<tbody>\n<tr>\n<td>Jenkins \u4efb\u52a1\u540d \/ \u955c\u50cf\u4ed3\u5e93\u8def\u5f84<\/td>\n<td>pipline&#xff08;\u62fc\u5199\u6709\u8bef&#xff09;<\/td>\n<td>\u6784\u5efa\u51fa\u7684\u662f repo\/pipline:v4.0<\/td>\n<\/tr>\n<tr>\n<td>pipeline.yml \u91cc\u7684 image<\/td>\n<td>repo\/pipeline:v4.0<\/td>\n<td>\u4e0e\u4e0a\u9762\u4e0d\u662f\u540c\u4e00\u4e2a\u4ed3\u5e93\u8def\u5f84<\/td>\n<\/tr>\n<tr>\n<td>Harbor \u5730\u5740<\/td>\n<td>YAML\/secret \u7528 145:80&#xff0c;daemon.json \u7528 154:80<\/td>\n<td>\u8282\u70b9\u4fe1\u4efb\u7684\u4ed3\u5e93\u4e0e\u5b9e\u9645\u62c9\u53d6\u5730\u5740\u4e0d\u540c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7edf\u4e00\u539f\u5219&#xff1a;\u4efb\u52a1\u540d &#061; \u955c\u50cf\u540d &#061; YAML \u91cc\u7684 image \u540e\u4e24\u6bb5 &#061; Service\/Deployment \u7684 metadata.name&#xff1b;Harbor \u5730\u5740\u5728 secret\u3001YAML\u3001daemon.json\u3001Jenkinsfile \u56db\u5904\u5fc5\u987b\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<p>\u5426\u5219\u5178\u578b\u62a5\u9519\u662f&#xff1a;<\/p>\n<p>Failed to pull image &#034;192.168.100.154:80\/repo\/pipeline:v4.0&#034;:<br \/>\nrpc error: code &#061; NotFound desc &#061; &#8230; manifest unknown<\/p>\n<hr \/>\n<h3>\u5341\u56db\u3001\u9a8c\u8bc1\u7ed3\u679c<\/h3>\n<h4>14.1 \u67e5\u770b Pod<\/h4>\n<p><span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># kubectl get pod -o wide<\/span><br \/>\nNAME                        READY   STATUS    RESTARTS   AGE     IP               NODE<br \/>\npipeline-7548f9c7f8-cb8hf   <span class=\"token number\">1<\/span>\/1     Running   <span class=\"token number\">0<\/span>          6m45s   <span class=\"token number\">10.100<\/span>.166.140   node1<br \/>\npipeline-7548f9c7f8-fpvfn   <span class=\"token number\">1<\/span>\/1     Running   <span class=\"token number\">0<\/span>          6m42s   <span class=\"token number\">10.100<\/span>.166.141   node1<\/p>\n<ul>\n<li>\u4e24\u4e2a Pod \u90fd\u662f 1\/1 Running&#xff0c;\u7b26\u5408 replicas: 2\u3002<\/li>\n<li>IP \u843d\u5728 10.100.166.x \u7f51\u6bb5&#xff0c;\u8bf4\u660e POD_SUBNET&#061;10.100.0.1\/16 \u751f\u6548\u3002<\/li>\n<li>NODE&#061;node1&#xff0c;\u56e0\u4e3a\u96c6\u7fa4\u53ea\u6709\u4e00\u4e2a worker\u3002<\/li>\n<\/ul>\n<h4>14.2 \u67e5\u770b Service<\/h4>\n<p><span class=\"token punctuation\">[<\/span>root&#064;master ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># kubectl get svc<\/span><br \/>\nNAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT<span class=\"token punctuation\">(<\/span>S<span class=\"token punctuation\">)<\/span>          AGE<br \/>\nkubernetes   ClusterIP   <span class=\"token number\">10.96<\/span>.0.1       <span class=\"token operator\">&lt;<\/span>none<span class=\"token operator\">&gt;<\/span>        <span class=\"token number\">443<\/span>\/TCP          11h<br \/>\npipeline     NodePort    <span class=\"token number\">10.96<\/span>.131.139   <span class=\"token operator\">&lt;<\/span>none<span class=\"token operator\">&gt;<\/span>        <span class=\"token number\">8081<\/span>:30724\/TCP   45m<\/p>\n<p>8081:30724 \u5c31\u662f&#034;\u96c6\u7fa4\u5185 8081 \/ \u5bf9\u5916 30724&#034;\u3002<\/p>\n<h4>14.3 \u786e\u8ba4\u955c\u50cf\u771f\u7684\u62c9\u4e0b\u6765\u4e86<\/h4>\n<p>\u5230 node1 \u4e0a&#xff08;Pod \u6240\u5728\u8282\u70b9&#xff09;\u770b&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;node1 ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># docker images<\/span><br \/>\nREPOSITORY                               TAG    IMAGE ID       CREATED         SIZE<br \/>\n<span class=\"token number\">192.168<\/span>.100.154:80\/repo\/pipeline         v4.0   f9fb39b6f313   <span class=\"token number\">7<\/span> minutes ago   543MB<\/p>\n<p><span class=\"token punctuation\">[<\/span>root&#064;node1 ~<span class=\"token punctuation\">]<\/span><span class=\"token comment\"># docker ps -a | grep pipeline<\/span><br \/>\nc7772f9ab89b   <span class=\"token number\">192.168<\/span>.100.154:80\/repo\/pipeline   <span class=\"token string\">&#034;\/bin\/sh -c &#039;java -j\u2026&#034;<\/span>   <span class=\"token number\">9<\/span> minutes ago   Up <span class=\"token number\">8<\/span> minutes<br \/>\nk8s_pipeline_pipeline-7548f9c7f8-fpvfn_default_c9d85723-<span class=\"token punctuation\">..<\/span>._0<\/p>\n<p>d7bd836f1602   registry.aliyuncs.com\/k8sxio\/pause:3.2   <span class=\"token string\">&#034;\/pause&#034;<\/span>   <span class=\"token number\">9<\/span> minutes ago   Up <span class=\"token number\">9<\/span> minutes<br \/>\nk8s_POD_pipeline-7548f9c7f8-fpvfn_default_<span class=\"token punctuation\">..<\/span>._0<\/p>\n<p>\u8fd9\u8bf4\u660e k8s \u5e95\u5c42\u4f9d\u7136\u662f Docker&#xff1a;\u6bcf\u4e2a Pod \u6709\u4e00\u4e2a pause \u5bb9\u5668&#xff08;\u6301\u6709\u7f51\u7edc\u547d\u540d\u7a7a\u95f4&#xff09;&#043; \u4e00\u4e2a\u4e1a\u52a1\u5bb9\u5668&#xff0c;\u547d\u540d\u89c4\u5219\u662f k8s_&lt;\u5bb9\u5668\u540d&gt;_&lt;Pod\u540d&gt;_&lt;\u547d\u540d\u7a7a\u95f4&gt;_&lt;uid&gt;_&lt;\u5e8f\u53f7&gt;\u3002<\/p>\n<h4>14.4 \u8bbf\u95ee\u5e94\u7528<\/h4>\n<p>\u6253\u5f00 node \u5730\u5740&#xff1a;<\/p>\n<p>http:\/\/192.168.100.146:30724\/test<\/p>\n<p>\u9875\u9762\u8fd4\u56de\u65b0\u7248\u5185\u5bb9&#xff0c;\u8bf4\u660e\u4ece\u4ee3\u7801\u63d0\u4ea4\u5230 k8s \u4e0a\u7ebf\u7684\u5168\u94fe\u8def\u5df2\u6253\u901a\u3002<\/p>\n<h4>14.5 \u67e5\u770b\u9489\u9489\u901a\u77e5<\/h4>\n<p>\u6d41\u6c34\u7ebf\u8dd1\u5b8c\u540e&#xff0c;\u9489\u9489\u7fa4\u91cc\u4f1a\u6536\u5230\u6784\u5efa\u7ed3\u679c\u3002\u6b64\u65f6\u6d88\u606f\u91cc\u7684&#034;\u7248\u672c&#034;\u5c31\u662f\u8fd9\u6b21\u7684 v4.0&#xff0c;\u548c k8s \u91cc\u8dd1\u7684\u955c\u50cf\u6807\u7b7e\u5b8c\u5168\u5bf9\u5e94\u2014\u2014\u6784\u5efa\u7ed3\u679c\u4e0e\u7ebf\u4e0a\u72b6\u6001\u7b2c\u4e00\u6b21\u505a\u5230\u4e86\u53ef\u5bf9\u9f50\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e94\u3001\u8e29\u5751\u6e05\u5355<\/h3>\n<table>\n<tr>#\u73b0\u8c61\u6839\u56e0\u89e3\u51b3<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>deploy.sh \u6bcf\u6b21\u628a\u8001\u5bb9\u5668\u5e26\u8d70<\/td>\n<td>\u6bcf\u6b21\u6267\u884c\u90fd\u91cd\u542f Docker<\/td>\n<td>\u7528 grep -q \u5224\u65ad\u662f\u5426\u5df2\u914d\u7f6e&#xff0c;\u5e42\u7b49\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Pod ImagePullBackOff<\/td>\n<td>\u79c1\u6709\u4ed3\u5e93\u6ca1\u6709\u62c9\u53d6\u51ed\u8bc1<\/td>\n<td>\u521b\u5efa harbor-secret &#043; YAML \u91cc imagePullSecrets<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u6709 secret \u4ecd\u62c9\u4e0d\u5230\u955c\u50cf<\/td>\n<td>secret \u5728\u522b\u7684 namespace \/ \u540d\u5b57\u4e0d\u4e00\u81f4<\/td>\n<td>\u540c namespace &#043; \u540d\u79f0\u4e25\u683c\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u8282\u70b9\u62c9\u955c\u50cf\u62a5 http: server gave HTTP response to HTTPS client<\/td>\n<td>\u8282\u70b9\u672a\u4fe1\u4efb HTTP \u4ed3\u5e93<\/td>\n<td>\u6bcf\u4e2a\u8282\u70b9 daemon.json \u52a0 insecure-registries<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u6784\u5efa\u6210\u529f\u4f46\u7ebf\u4e0a\u8fd8\u662f\u65e7\u4ee3\u7801<\/td>\n<td>\u590d\u7528\u540c\u540d tag &#043; \u7f13\u5b58<\/td>\n<td>imagePullPolicy: Always<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>\u8bbf\u95ee 8081 \u6253\u4e0d\u5f00<\/td>\n<td>\u6df7\u6dc6\u4e86 port \u4e0e nodePort<\/td>\n<td>\u7528 \u8282\u70b9IP:30724<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>selector does not match template labels<\/td>\n<td>\u4e24\u5904 labels \u4e0d\u4e00\u81f4<\/td>\n<td>matchLabels \u5fc5\u987b\u7b49\u4e8e Pod \u7684 labels<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>\u6d41\u6c34\u7ebf\u5361\u5728 ssh \u9636\u6bb5<\/td>\n<td>ssh \u9700\u8981\u4ea4\u4e92\u8f93\u5bc6\u7801<\/td>\n<td>\u914d\u514d\u5bc6&#xff1a;ssh-keygen &#043; authorized_keys<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>\u514d\u5bc6\u914d\u4e86\u4ecd\u8981\u5bc6\u7801<\/td>\n<td>\u76ee\u5f55\/\u6587\u4ef6\u6743\u9650\u6216\u516c\u94a5\u88ab\u6298\u884c<\/td>\n<td>~\/.ssh 700\u3001authorized_keys 600\u3001\u516c\u94a5\u4e00\u884c<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>kubectl apply \u62a5\u627e\u4e0d\u5230\u6587\u4ef6<\/td>\n<td>\u7528\u4e86\u76f8\u5bf9\u8def\u5f84<\/td>\n<td>\u4e00\u5f8b\u7edd\u5bf9\u8def\u5f84 \/usr\/local\/k8s\/pipeline.yml<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>\u52a0\u4e86 yml \u4f46 Jenkins \u8bc6\u522b\u4e0d\u5230<\/td>\n<td>\u5de5\u4f5c\u533a\u672a\u5237\u65b0<\/td>\n<td>\u5efa\u65b0 tag \/ \u89e6\u53d1\u65b0\u6784\u5efa<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>kubeadm join \u62a5 token \u8fc7\u671f<\/td>\n<td>token \u6709\u6548\u671f 2 \u5c0f\u65f6<\/td>\n<td>\u91cd\u65b0 kubeadm token create &#8211;print-join-command<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>\u8282\u70b9 NotReady<\/td>\n<td>cgroup \u9a71\u52a8\u4e0d\u4e00\u81f4 \/ \u6539\u5b8c daemon.json \u672a\u91cd\u542f kubelet<\/td>\n<td>native.cgroupdriver&#061;systemd &#043; systemctl restart kubelet<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u5341\u516d\u3001\u603b\u7ed3<\/h3>\n<p>\u8fd9\u4e00\u7ae0\u505a\u7684\u662f&#034;\u4ea4\u4ed8\u65b9\u5f0f\u7684\u5347\u7ea7&#034;&#xff1a;<\/p>\n<li>\u811a\u672c\u5e42\u7b49\u5316\u3002deploy.sh \u4ece&#034;\u6bcf\u6b21\u90fd\u6539 Docker \u914d\u7f6e\u5e76\u91cd\u542f&#034;\u53d8\u6210&#034;\u5224\u65ad\u4e00\u6b21\u3001\u53ea\u914d\u4e00\u6b21&#034;&#xff0c;\u65e2\u89e3\u51b3\u4e86\u4e0a\u671f\u5f69\u86cb&#xff0c;\u4e5f\u662f\u8fd0\u7ef4\u811a\u672c\u7684\u57fa\u672c\u7d20\u517b\u3002<\/li>\n<li>\u8fd0\u884c\u6001\u4ea4\u7ed9 K8s\u3002replicas: 2 &#043; Deployment &#043; Service&#xff0c;\u4ece\u6b64\u6709\u526f\u672c\u3001\u6709\u81ea\u6108\u3001\u6709\u7edf\u4e00\u5165\u53e3&#xff0c;\u4e0d\u518d\u4f9d\u8d56&#034;\u67d0\u53f0\u673a\u5668\u4e0a\u7684\u67d0\u4e2a\u5bb9\u5668&#034;\u3002<\/li>\n<li>\u51ed\u8bc1\u4e0e\u4fe1\u4efb\u8981\u5206\u5f00\u5904\u7406\u3002docker login \u89e3\u51b3&#034;\u4eba\u80fd\u62c9\u955c\u50cf&#034;&#xff0c;imagePullSecrets \u89e3\u51b3&#034;kubelet \u80fd\u62c9\u955c\u50cf&#034;&#xff1b;insecure-registries \u89e3\u51b3&#034;\u5141\u8bb8\u8d70 HTTP&#034;\u3002\u4e09\u8005\u7f3a\u4e00\u4e0d\u53ef&#xff0c;\u800c\u4e14\u5fc5\u987b\u5728\u6240\u6709\u8282\u70b9\u4e0a\u4e00\u81f4\u3002<\/li>\n<li>\u7aef\u53e3\u94fe\u8def\u8981\u5206\u6e05\u3002containerPort 8080 \u2192 port 8081 \u2192 nodePort 30724&#xff0c;\u5bf9\u5916\u53ea\u770b nodePort\u3002<\/li>\n<li>\u547d\u540d\u5fc5\u987b\u4e09\u5904\u5bf9\u9f50\u3002\u4efb\u52a1\u540d\u3001\u955c\u50cf\u540d\u3001YAML \u91cc\u7684 image\u3001Service \u540d&#xff0c;\u4efb\u4f55\u4e00\u5904\u5bf9\u4e0d\u4e0a\u90fd\u4f1a\u4ee5&#034;\u62c9\u4e0d\u5230\u955c\u50cf&#034;\u7684\u5f62\u5f0f\u62a5\u9519\u3002<\/li>\n<li>\u514d\u5bc6\u662f\u81ea\u52a8\u5316\u7684\u524d\u63d0\u3002ssh-keygen \u7559\u7a7a passphrase &#043; authorized_keys&#xff0c;\u5426\u5219\u6d41\u6c34\u7ebf\u4f1a\u5361\u5728\u4ea4\u4e92\u8f93\u5165\u4e0a\u3002<\/li>\n<p>\u56de\u5934\u770b\u8fd9\u4e09\u7ae0\u7684\u6f14\u8fdb\u8def\u5f84&#xff0c;\u5176\u5b9e\u662f\u4e00\u6761\u5f88\u6e05\u6670\u7684&#034;\u62bd\u8c61\u5c42\u7ea7\u4e0a\u5347&#034;\u8def\u7ebf&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u4ea4\u4ed8\u7269\u8c01\u5728\u7ba1\u8fd0\u884c\u6001\u89e3\u51b3\u7684\u95ee\u9898<\/tr>\n<tbody>\n<tr>\n<td>\u7b2c 2 \u90e8<\/td>\n<td>docker run \u547d\u4ee4<\/td>\n<td>\u4eba<\/td>\n<td>\u80fd\u8dd1\u8d77\u6765<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c 3 \u90e8<\/td>\n<td>Jenkinsfile &#043; deploy.sh<\/td>\n<td>\u811a\u672c<\/td>\n<td>\u4e0d\u7528\u624b\u52a8\u8dd1<\/td>\n<\/tr>\n<tr>\n<td>\u7b2c 4 \u90e8&#xff08;\u672c\u7ae0&#xff09;<\/td>\n<td>pipeline.yml<\/td>\n<td>Kubernetes<\/td>\n<td>\u8dd1\u5f97\u7a33\u3001\u53ef\u6269\u7f29<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e0b\u4e00\u6b65\u5f88\u81ea\u7136\u7684\u5ef6\u4f38&#xff1a;<\/p>\n<ul>\n<li>\u52a0 liveness\/readiness \u63a2\u9488&#xff0c;\u8ba9 K8s \u771f\u6b63\u5224\u65ad&#034;\u5e94\u7528\u662f\u5426\u5065\u5eb7&#034;&#xff0c;\u800c\u4e0d\u53ea\u662f&#034;\u5bb9\u5668\u662f\u5426\u5728\u8dd1&#034;\u3002<\/li>\n<li>\u7528 Ingress \u53d6\u4ee3 NodePort&#xff0c;\u628a 30724 \u8fd9\u79cd\u9ad8\u4f4d\u7aef\u53e3\u6536\u655b\u6210\u57df\u540d\u8bbf\u95ee\u3002<\/li>\n<li>\u7528 HPA \u6309 CPU \u81ea\u52a8\u6269\u7f29\u5bb9&#xff0c;\u914d\u5408 resources.requests \u624d\u80fd\u751f\u6548\u3002<\/li>\n<li>\u628a YAML \u62c6\u6210 Helm Chart&#xff0c;\u4e0d\u540c\u73af\u5883&#xff08;dev\/test\/prod&#xff09;\u7528 values.yaml \u533a\u5206&#xff0c;\u800c\u4e0d\u662f\u6539\u955c\u50cf tag\u3002<\/li>\n<li>\u6d41\u6c34\u7ebf\u91cc\u52a0 kubectl rollout status \u4e0e rollout undo&#xff0c;\u8ba9&#034;\u90e8\u7f72\u5931\u8d25\u81ea\u52a8\u56de\u6eda&#034;\u6210\u4e3a\u9ed8\u8ba4\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u8fd9\u7bc7\u7b14\u8bb0\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u70b9\u8d5e &#043; \u6536\u85cf&#xff0c;\u8bc4\u8bba\u533a\u4ea4\u6d41\u3002<\/p>\n<p>\u73af\u5883&#xff1a;CentOS 7 \/ Kubernetes v1.19.5 \/ Docker 19.3.11 \/ Harbor v2.8.2 \/ Jenkins 2.346.3-lts-jdk8<\/p>\n<p>      <span id=\"quality-guide-article-end\" aria-hidden=\"true\" style=\"display:block;height:1px;margin-bottom:-1px\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1404,392,120],"topic":[],"class_list":["post-124431","post","type-post","status-publish","format-standard","hentry","category-server","tag-devops","tag-jenkins","tag-kubernetes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/124431.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/124431.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T17:08:31+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124431.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/124431.html\",\"name\":\"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-18T17:08:31+00:00\",\"dateModified\":\"2026-11-18T17:08:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/124431.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/124431.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124431.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/124431.html","og_locale":"zh_CN","og_type":"article","og_title":"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/124431.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-18T17:08:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"12 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/124431.html","url":"https:\/\/www.wsisp.com\/helps\/124431.html","name":"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-18T17:08:31+00:00","dateModified":"2026-11-18T17:08:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/124431.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/124431.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/124431.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"DevOps \u8fdb\u9636 Kubernetes \u4e0e DevOps \u6574\u5408\u5b9e\u6218\uff1aK8s \u96c6\u7fa4\u642d\u5efa + Jenkins \u81ea\u52a8\u90e8\u7f72 Pipeline \u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=124431"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124431\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=124431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=124431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=124431"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=124431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}