{"id":1718,"date":"2023-03-26T07:32:34","date_gmt":"2023-03-25T23:32:34","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1718"},"modified":"2023-04-23T21:37:30","modified_gmt":"2023-04-23T13:37:30","slug":"k8s-deploy-pods-to-specific-nodes-masters","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/26\/k8s-deploy-pods-to-specific-nodes-masters\/","title":{"rendered":"K8s\u5c06Pod\u6307\u5b9a\u90e8\u7f72\u5230\u7279\u5b9a\u8282\u70b9(master)\u4e0a\u7684\u4e00\u79cd\u65b9\u6cd5"},"content":{"rendered":"<p>\u9700\u6c42\uff1a\u642d\u5efa\u4e00\u4e2a\u96c6\u7fa4\uff0c\u8fd9\u4e2a\u96c6\u7fa4\u8981\u8d70 CI\/CD \u6d41\u7a0b\uff0c\u8fd8\u8981\u7ba1\u7406 CI\/CD \u6d41\u7a0b\u7684\u4ea7\u51fa\u7269\uff0c\u5c06\u5176\u4fdd\u5b58\u5728 Harbor \u4e2d\uff0c\u8ba9\u540e\u8ba9\u4ea7\u51fa\u7269\u5728\u53e6\u5916\u4e24\u4e2a\u8282\u70b9\u4e0a\u8fd0\u884c\u8d77\u6765\u3002\u5efa\u8bae\u5c06 Jenkins \u90e8\u7f72\u5230 Master \u8282\u70b9\uff0c\u53ef\u4ee5\u907f\u514d\u5404\u79cd\u8bc1\u4e66\u76f8\u5173\u7684\u95ee\u9898\u3002<\/p>\n<p>\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0cPod \u90e8\u7f72\u4e00\u822c\u90fd\u662f K8s \u5206\u914d\uff0c\u600e\u4e48\u5c06 Jenkins \u90e8\u7f72\u5230\u7279\u5b9a master \u8282\u70b9\u5462\uff1f<\/p>\n<p><!-- more --><\/p>\n<h2>\u8282\u70b9\u6253\u6807\u7b7e<\/h2>\n<p>\u4e3a master \u8282\u70b9\u6253\u6807\u7b7e<\/p>\n<pre><code>[root@k8s-master ~]# kubectl label nodes master labelName=master<\/code><\/pre>\n<h2>nodeSelector<\/h2>\n<p>\u7f16\u5199yaml\uff0c\u90e8\u7f72\u6587\u6863\u5982\u4e0b<\/p>\n<pre><code class=\"language-yml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: jenkins-deployment\n  labels:\n    app: jenkins\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: jenkins\n  template:\n    metadata:\n      labels:\n        app: jenkins\n    spec:\n      containers:\n      - name: jenkins\n        image: jenkins:latest\n        imagePullPolicy: IfNotPresent\n        ports:\n        - containerPort: 8080\n          name: web\n          protocol: TCP\n        - containerPort: 50000\n          name: agent\n          protocol: TCP\n        volumeMounts:\n        - name: jenkins-home\n          mountPath: \/var\/jenkins_home\n      volumes:\n      - name: jenkins-home\n        hostPath:\n          path: \/root\/jenkins-home\n      nodeSelector:\n        labelName: master\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: jenkins-service\n  labels:\n    app: jenkins\nspec:\n  ports:\n  - port: 8080\n    targetPort: 8080\n    name: web\n    nodePort: 32019\n  - port: 50000\n    targetPort: 50000\n    name: agent\n  selector:\n    app-name: jenkins\n  type: NodePort<\/code><\/pre>\n<p>\u6b63\u662f\u7531\u4e8e<code>Demployment<\/code>\u5728<code>spec<\/code>\u4e2d\u5236\u5b9a\u4e86<code>nodeSelector<\/code>\u7684 label \u4e3a <code>labelName:master<\/code>\uff0c Jenkins \u4f1a\u81ea\u52a8\u9009\u5728 master \u8282\u70b9\u8fdb\u884c\u90e8\u7f72\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a\u642d\u5efa\u4e00\u4e2a\u96c6\u7fa4\uff0c\u8fd9\u4e2a\u96c6\u7fa4\u8981\u8d70 CI\/CD \u6d41\u7a0b\uff0c\u8fd8\u8981\u7ba1\u7406 CI\/CD \u6d41\u7a0b\u7684\u4ea7\u51fa\u7269\uff0c\u5c06\u5176\u4fdd\u5b58\u5728 Harbo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[356],"class_list":["post-1718","post","type-post","status-publish","format-standard","hentry","category-k8s","tag-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1718"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1718\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}