{"id":174602,"date":"2020-03-27T10:47:01","date_gmt":"2020-03-27T02:47:01","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=174602"},"modified":"2020-03-17T08:48:32","modified_gmt":"2020-03-17T00:48:32","slug":"k8s-jenkins","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/k8s-jenkins.html","title":{"rendered":"k8s\u5982\u4f55\u90e8\u7f72\u5206\u5e03\u5f0fjenkins"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nKubernetes\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\uff0c\u7528\u4e8e\u7ba1\u7406\u4e91\u5e73\u53f0\u4e2d\u591a\u4e2a\u4e3b\u673a\u4e0a\u7684\u5bb9\u5668\u5316\u7684\u5e94\u7528\uff0cKubernetes\u7684\u76ee\u6807\u662f\u8ba9\u90e8\u7f72\u5bb9\u5668\u5316\u7684\u5e94\u7528\u7b80\u5355\u5e76\u4e14\u9ad8\u6548\uff08powerful\uff09,Kubernetes\u63d0\u4f9b\u4e86\u5e94\u7528\u90e8\u7f72\uff0c\u89c4\u5212\uff0c\u66f4\u65b0\uff0c\u7ef4\u62a4\u7684\u4e00\u79cd\u673a\u5236\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u524d\u63d0\u6761\u4ef6\u662f\uff0c\u6709storageclass\uff0c\u5229\u7528pvc \u521b\u5efa\u6301\u4e45\u5316\u5b58\u50a8 \u521b\u5efakube-ops namespace <\/p>\n

\u8fd9\u91cc\u521b\u5efaopspvc \u53e6\u5916\u628aaccessmode \u6362\u6210readwritemany\uff0c\u56e0\u4e3a\u4f1a\u6709\u591a\u4e2apod \u8fdb\u884c\u8bfb\u5199<\/p>\n

\u7136\u540e\u90e8\u7f72jenkins master deployment\u5982\u4e0b<\/strong><\/span><\/div>\n
\r\n---\r\napiVersion: extensions\/v1beta1\r\nkind: Deployment\r\nmetadata:\r\n  name: jenkins\r\n  namespace: kube-ops\r\nspec:\r\n  template:\r\n    metadata:\r\n      labels:\r\n        app: jenkins\r\n    spec:\r\n      terminationGracePeriodSeconds: 10\r\n      serviceAccountName: jenkins\r\n      containers:\r\n      - name: jenkins\r\n        image: jenkins\/jenkins:lts\r\n        imagePullPolicy: IfNotPresent\r\n        ports:\r\n        - containerPort: 8080\r\n          name: web\r\n          protocol: TCP\r\n        - containerPort: 50000\r\n          name: agent\r\n          protocol: TCP\r\n        resources:\r\n          limits:\r\n            cpu: 2000m\r\n            memory: 4Gi\r\n          requests:\r\n            cpu: 1000m\r\n            memory: 2Gi\r\n        livenessProbe:\r\n          httpGet:\r\n            path: \/login\r\n            port: 8080\r\n          initialDelaySeconds: 60\r\n          timeoutSeconds: 5\r\n          failureThreshold: 12\r\n        readinessProbe:\r\n          httpGet:\r\n            path: \/login\r\n            port: 8080\r\n          initialDelaySeconds: 60\r\n          timeoutSeconds: 5\r\n          failureThreshold: 12\r\n        volumeMounts:\r\n        - name: jenkinshome\r\n          subPath: jenkins\r\n          mountPath: \/var\/jenkins_home\r\n        env:\r\n        - name: LIMITS_MEMORY\r\n          valueFrom:\r\n            resourceFieldRef:\r\n              resource: limits.memory\r\n              divisor: 1Mi\r\n        - name: JAVA_OPTS\r\n          value: -Xmx$(LIMITS_MEMORY)m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia\/Shanghai\r\n      securityContext:\r\n        fsGroup: 1000\r\n      volumes:\r\n      - name: jenkinshome\r\n        persistentVolumeClaim:\r\n          claimName: opspvc\r\n\r\n---\r\napiVersion: v1\r\nkind: Service\r\nmetadata:\r\n  name: jenkins\r\n  namespace: kube-ops\r\n  labels:\r\n    app: jenkins\r\nspec:\r\n  selector:\r\n    app: jenkins\r\n  ports:\r\n  - name: web\r\n    port: 8080\r\n    targetPort: web\r\n  - name: agent\r\n    port: 50000\r\n    targetPort: agent\r\n<\/pre>\n
\u5206\u914d\u6743\u9650\uff0c\u914d\u7f6erbac\u5982\u4e0b<\/strong><\/span><\/div>\n
\r\napiVersion: v1\r\nkind: ServiceAccount\r\nmetadata:\r\n  name: jenkins\r\n  namespace: kube-ops\r\n\r\n---\r\n\r\nkind: Role\r\napiVersion: rbac.authorization.k8s.io\/v1beta1\r\nmetadata:\r\n  name: jenkins\r\n  namespace: kube-ops\r\nrules:\r\n  - apiGroups: [\"\"]\r\n    resources: [\"pods\"]\r\n    verbs: [\"create\",\"delete\",\"get\",\"list\",\"patch\",\"update\",\"watch\"]\r\n  - apiGroups: [\"\"]\r\n    resources: [\"pods\/exec\"]\r\n    verbs: [\"create\",\"delete\",\"get\",\"list\",\"patch\",\"update\",\"watch\"]\r\n  - apiGroups: [\"\"]\r\n    resources: [\"pods\/log\"]\r\n    verbs: [\"get\",\"list\",\"watch\"]\r\n  - apiGroups: [\"\"]\r\n    resources: [\"secrets\"]\r\n    verbs: [\"get\"]\r\n\r\n---\r\napiVersion: rbac.authorization.k8s.io\/v1beta1\r\nkind: RoleBinding\r\nmetadata:\r\n  name: jenkins\r\n  namespace: kube-ops\r\nroleRef:\r\n  apiGroup: rbac.authorization.k8s.io\r\n  kind: Role\r\n  name: jenkins\r\nsubjects:\r\n  - kind: ServiceAccount\r\n    name: jenkins\r\n    namespace: kube-ops\r\n<\/pre>\n
\u5b89\u88c5k8s \u63d2\u4ef6\uff0c\u4e0ek8s \u76ee\u6807\u96c6\u7fa4\u8fdb\u884c\u8fdc\u7a0b\u8fde\u63a5<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u56e0\u4e3a\u662f\u817e\u8baf\u4e91\uff0c\u5e76\u6ca1\u6709\u63d0\u4f9btls \u5ba2\u6237\u7aef\u8ba4\u8bc1\uff0c\u6240\u4ee5\u76f4\u63a5\u5229\u7528\u8d26\u53f7\u5bc6\u7801\uff0c\u8fdb\u884c\u8ba4\u8bc1\uff0c\u8bb0\u5f97\uff0c\u7981\u7528https \u8bc1\u4e66\u68c0\u67e5,jenkins\u548ck8s \u5c31\u96c6\u6210\u597d\u4e86<\/p>\n

\u5212\u91cd\u70b9\uff01\uff01\uff01\uff1ajenkins\u5730\u5740\uff0c\u8fd9\u91cc\u6211\u8fd9\u91cc\u5199\u7684\u662f\u5185\u7f51\u5730\u5740\u4ee5\u53ca\u66b4\u9732\u4e8650000\u7aef\u53e3\uff08\u7528\u6765\u4e0eslave \u5efa\u7acb\u901a\u4fe1\u4f7f\u7528\uff09\uff0c\u56e0\u4e3amaster \u548cslave \u5206\u522b\u5728\u4e0d\u901a\u7684k8s \u96c6\u7fa4\u91cc\uff0c\u90a3\u4e48\u9700\u8981\u8fdc\u7a0b\u8fdb\u884c\u8054\u901a\uff0c\u800cjenkins-ui \u6211\u662f\u4ee5ingress \u7684\u65b9\u5f0f\u5bf9\u5916\u66b4\u9732<\/p>\n

slave \u7684\u914d\u7f6e<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\u6807\u7b7e\u5217\u8868\uff0c\u8fd9\u91cc\u586b\u5199\u7684\u6807\u7b7e\uff0c\u9700\u8981\u5728slave \u6240\u5728k8s \u96c6\u7fa4\u7684\u8282\u70b9\u4e0a\u8fdb\u884c\u6807\u6ce8\uff0c\u800c\u8fd9\u4e2a\u540d\u5b57\uff0c\u662flabel\u8fd9\u4e2a\u5b57\u6bb5\u91cc\u7684key \u5e76\u672a\u662fvalue\uff0c\u8fd9\u91cc\u8981\u6ce8\u610f<\/p>\n

job \u91cc\u914d\u7f6e<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u8fd9\u4e2a\u610f\u601d\u5c31\u662f slave \u4f1a\u5c3d\u53ef\u80fd\u7684\u5728\u8fd9\u4e2a\u8282\u70b9build<\/p>\n","protected":false},"excerpt":{"rendered":"

\u524d\u63d0\u6761\u4ef6\u662f\uff0c\u6709storageclass\uff0c\u5229\u7528pvc \u521b\u5efa\u6301\u4e45\u5316\u5b58\u50a8 \u521b\u5efakube-ops namespace […]<\/p>\n","protected":false},"author":668,"featured_media":63809,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-174602","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/174602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=174602"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/174602\/revisions"}],"predecessor-version":[{"id":174621,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/174602\/revisions\/174621"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/63809"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=174602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=174602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=174602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}