Jenkins使用k8s插件在JNLP容器上运行。

huangapple go评论112阅读模式
英文:

Jenkins using k8s plugin runs on JNLP container

问题

I've decided to run a podTemplate with one container of main.

  1. 为什么我的 pod 模板配置中包含 JNLP?它是什么作用?我是否可以只有我的容器和我的镜像而没有 JNLP?
  2. 如何将 JNLP 镜像覆盖为我的镜像,而不是传入的镜像?
  3. 如何在我的 pod/container "main" 上运行我的作业,而不是在 JNLP 上运行?

Jenkins使用k8s插件在JNLP容器上运行。
Jenkins使用k8s插件在JNLP容器上运行。

我的 Jenkins 配置代码 -

  1. config:
  2. Jenkins:cluster: non-prod
  3. Jenkins:secrets:
  4. create: true
  5. secretsList:
  6. - name: jenkins-github-token-non-prod
  7. value: /us-west-2-non-prod/jenkins/secrets/github-token
  8. - name: jenkins-slack-token-non-prod
  9. value: /us-west-2-non-prod/jenkins/secrets/slack-token
  10. Jenkins:config:
  11. chart: jenkins
  12. namespace: default
  13. repo: https://charts.jenkins.io
  14. values:
  15. agent:
  16. enabled: true
  17. podTemplates:
  18. jenkins-slave-pod: |
  19. - name: jenkins-slave-pod
  20. label: jenkins-slave-pod
  21. containers:
  22. - name: main
  23. image: '805787217936.dkr.ecr.us-west-2.amazonaws.com/aba-jenkins-slave:ecs-global-node_master_57'
  24. command: "sleep"
  25. args: "30d"
  26. privileged: true
  27. master.JCasC.enabled: true
  28. master.JCasC.defaultConfig: true
  29. kubernetesConnectTimeout: 5
  30. kubernetesReadTimeout: 15
  31. maxRequestsPerHostStr: "32"
  32. namespace: default
  33. image: "805787217936.dkr.ecr.us-west-2.amazonaws.com/aba-jenkins-slave"
  34. tag: "ecs-global-node_master_57"
  35. workingDir: "/home/jenkins/agent"
  36. nodeUsageMode: "NORMAL"
  37. imagePullSecretName:
  38. componentName: "eks-global-slave"
  39. websocket: false
  40. privileged: false
  41. runAsUser:
  42. runAsGroup:
  43. resources:
  44. requests:
  45. cpu: "512m"
  46. memory: "512Mi"
  47. limits:
  48. cpu: "512m"
  49. memory: "512Mi"
  50. podRetention: "Never"
  51. volumes: [ ]
  52. workspaceVolume: { }
  53. envVars: [ ]
  54. command:
  55. args: "${computer.jnlpmac} ${computer.name}"
  56. sideContainerName: "jnlp"
  57. TTYEnabled: true
  58. containerCap: 10
  59. podName: "jnlp"
  60. idleMinutes: 0
  61. connectTimeout: 100
  62. serviceAccount:
  63. annotations: {}
  64. controller:
  65. numExecutors: 1
  66. additionalExistingSecrets: []
  67. JCasC:
  68. securityRealm: |
  69. local:
  70. allowsSignup: false
  71. users:
  72. - id: "aba"
  73. password: "aba"
  74. configScripts:
  75. credentials: |
  76. credentials:
  77. system:
  78. domainCredentials:
  79. - credentials:
  80. - string:
  81. scope: GLOBAL
  82. id: slack-token
  83. description: "Slack access token"
  84. secret: "${jenkins-slack-token-non-prod-value}"
  85. - usernamePassword:
  86. id: "github-credentials"
  87. password: "aba"
  88. scope: GLOBAL
  89. username: "aba"
  90. plugin-config: |
  91. jenkins:
  92. disabledAdministrativeMonitors:
  93. - "hudson.model.UpdateCenter$CoreUpdateMonitor"
  94. - "jenkins.diagnostics.ControllerExecutorsNoAgents"
  95. security:
  96. updateSiteWarningsConfiguration:
  97. ignoredWarnings:
  98. - "core-2_263"
  99. - "SECURITY-2617-extended-choice-parameter"
  100. - "SECURITY-2170"
  101. - "SECURITY-2796"
  102. - "SECURITY-2169"
  103. - "SECURITY-2332"
  104. - "SECURITY-2232"
  105. - "SECURITY-1351"
  106. - "SECURITY-1350"
  107. - "SECURITY-2888"
  108. unclassified:
  109. slackNotifier:
  110. teamDomain: "superops"
  111. baseUrl: "https://superops.slack.com/services/hooks/jenkins-ci/"
  112. tokenCredentialId: "slack-token"
  113. globalLibraries:
  114. libraries:
  115. - defaultVersion: "master"
  116. allowVersionOverride: true
  117. name: "aba-jenkins-library"
  118. implicit: true
  119. retriever:
  120. modernSCM:
  121. scm:
  122. git:
  123. credentialsId: "github-credentials"
  124. id: "shared-library-creds"
  125. remote: "https://github.com/aba-aba/aba-jenkins-library.git"
  126. traits:
  127. - "gitBranchDiscovery"
  128. - "cleanBeforeCheckoutTrait"
  129. - "ignoreOnPushNotificationTrait"
  130. additionalPlugins:
  131. - junit:1119.1121.vc43d0fc45561
  132. - prometheus:2.0.11
  133. - saml:4.352.vb_722786ea_79d
  134. - role-strategy:546.ve16648865996
  135. - blueocean-web:1.25.5
  136. - github-branch-source:1677.v731f745ea_0cf
  137. - git-changelog:3.23
  138. - scriptler:3.5
  139. - sshd:3.249.v2dc2ea_416e33
  140. - rich-text-publisher-plugin:1.4
  141. - matrix-project:785.v06b_7f47b_c631
  142. - build-failure-analyzer:2.3.0
  143. - testng-plugin:555.va0d5f66521e3
  144. - allure-jenkins-plugin:2.30.2
  145. - timestamper:1.18
  146. - ws-cleanup:0.42
  147. - build-timeout:1.21
  148. - slack:616.v03b_1e98d13dd
  149. - email-ext:2.91
  150. - docker-commons:1.19
  151. - docker-workflow:521.v1a_a_dd2073b_2e
  152. - rundeck:3.6.11
  153. - parameter-separator:1.3
  154. - extended-choice-parameter:346.vd87693c5a_86c
  155. - uno-choice:2.6.3
  156. adminPassword: ""
  157. ingress:
  158. enabled: true
  159. hostName: jenkins.non-prod.us-west-2.int.isappcloud.com
  160. ingressClassName: nginx-int
  161. installPlugins:
  162. - kubernetes:3883.v4d70a_a_a_df034
  163. - workflow-aggregator:590.v6a_d052e5a_a_b_5
  164. - git:5.0.0
  165. - configuration-as-code:1569.vb_72405
  166. <details>
  167. <summary>英文:</summary>
  168. I&#39;ve decided to run a podTemplate with one container of main.
  169. 1. Why does my pod template configuration include JNLP? What is needed for? can I have only my pod with my container with my image?
  170. 2. How do I overwrite the JNLP image with my image instead of inbound image?
  171. 3. How do I run my job on my pod/container of &#39;main&#39; and not JNLP?
  172. [![enter image description here][1]][1]
  173. [![enter image description here][2]][2]
  174. My Jenkins configuration as code -
  175. ```config:
  176. Jenkins:cluster: non-prod
  177. Jenkins:secrets:
  178. create: true
  179. secretsList:
  180. - name: jenkins-github-token-non-prod
  181. value: /us-west-2-non-prod/jenkins/secrets/github-token
  182. - name: jenkins-slack-token-non-prod
  183. value: /us-west-2-non-prod/jenkins/secrets/slack-token
  184. Jenkins:config:
  185. chart: jenkins
  186. namespace: default
  187. repo: https://charts.jenkins.io
  188. values:
  189. agent:
  190. enabled: true
  191. podTemplates:
  192. jenkins-slave-pod: |
  193. - name: jenkins-slave-pod
  194. label: jenkins-slave-pod
  195. containers:
  196. - name: main
  197. image: &#39;805787217936.dkr.ecr.us-west-2.amazonaws.com/aba-jenkins-slave:ecs-global-node_master_57&#39;
  198. command: &quot;sleep&quot;
  199. args: &quot;30d&quot;
  200. privileged: true
  201. master.JCasC.enabled: true
  202. master.JCasC.defaultConfig: true
  203. kubernetesConnectTimeout: 5
  204. kubernetesReadTimeout: 15
  205. maxRequestsPerHostStr: &quot;32&quot;
  206. namespace: default
  207. image: &quot;805787217936.dkr.ecr.us-west-2.amazonaws.com/aba-jenkins-slave&quot;
  208. tag: &quot;ecs-global-node_master_57&quot;
  209. workingDir: &quot;/home/jenkins/agent&quot;
  210. nodeUsageMode: &quot;NORMAL&quot;
  211. # name of the secret to be used for image pulling
  212. imagePullSecretName:
  213. componentName: &quot;eks-global-slave&quot;
  214. websocket: false
  215. privileged: false
  216. runAsUser:
  217. runAsGroup:
  218. resources:
  219. requests:
  220. cpu: &quot;512m&quot;
  221. memory: &quot;512Mi&quot;
  222. limits:
  223. cpu: &quot;512m&quot;
  224. memory: &quot;512Mi&quot;
  225. podRetention: &quot;Never&quot;
  226. volumes: [ ]
  227. workspaceVolume: { }
  228. envVars: [ ]
  229. # - name: PATH
  230. # value: /usr/local/bin
  231. command:
  232. args: &quot;${computer.jnlpmac} ${computer.name}&quot;
  233. # Side container name
  234. sideContainerName: &quot;jnlp&quot;
  235. # Doesn&#39;t allocate pseudo TTY by default
  236. TTYEnabled: true
  237. # Max number of spawned agent
  238. containerCap: 10
  239. # Pod name
  240. podName: &quot;jnlp&quot;
  241. # Allows the Pod to remain active for reuse until the configured number of
  242. # minutes has passed since the last step was executed on it.
  243. idleMinutes: 0
  244. # Timeout in seconds for an agent to be online
  245. connectTimeout: 100
  246. serviceAccount:
  247. annotations: {}
  248. controller:
  249. numExecutors: 1
  250. additionalExistingSecrets: []
  251. JCasC:
  252. securityRealm: |
  253. local:
  254. allowsSignup: false
  255. users:
  256. - id: &quot;aba&quot;
  257. password: &quot;aba&quot;
  258. # securityRealm: |
  259. # saml:
  260. # binding: &quot;urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect&quot;
  261. # displayNameAttributeName: &quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name&quot;
  262. # groupsAttributeName: &quot;http://schemas.xmlsoap.org/claims/Group&quot;
  263. # idpMetadataConfiguration:
  264. # period: 0
  265. # url: &quot;https://aba.onelogin.com/saml/metadata/34349e62-799f-4378-9d2a-03b870cbd965&quot;
  266. # maximumAuthenticationLifetime: 86400
  267. # usernameCaseConversion: &quot;none&quot;
  268. # authorizationStrategy: |-
  269. # roleBased:
  270. # forceExistingJobs: true
  271. configScripts:
  272. credentials: |
  273. credentials:
  274. system:
  275. domainCredentials:
  276. - credentials:
  277. - string:
  278. scope: GLOBAL
  279. id: slack-token
  280. description: &quot;Slack access token&quot;
  281. secret: &quot;${jenkins-slack-token-non-prod-value}&quot;
  282. - usernamePassword:
  283. id: &quot;github-credentials&quot;
  284. password: &quot;aba&quot;
  285. scope: GLOBAL
  286. username: &quot;aba&quot;
  287. plugin-config: |
  288. jenkins:
  289. disabledAdministrativeMonitors:
  290. - &quot;hudson.model.UpdateCenter$CoreUpdateMonitor&quot;
  291. - &quot;jenkins.diagnostics.ControllerExecutorsNoAgents&quot;
  292. security:
  293. updateSiteWarningsConfiguration:
  294. ignoredWarnings:
  295. - &quot;core-2_263&quot;
  296. - &quot;SECURITY-2617-extended-choice-parameter&quot;
  297. - &quot;SECURITY-2170&quot;
  298. - &quot;SECURITY-2796&quot;
  299. - &quot;SECURITY-2169&quot;
  300. - &quot;SECURITY-2332&quot;
  301. - &quot;SECURITY-2232&quot;
  302. - &quot;SECURITY-1351&quot;
  303. - &quot;SECURITY-1350&quot;
  304. - &quot;SECURITY-2888&quot;
  305. unclassified:
  306. slackNotifier:
  307. teamDomain: &quot;superops&quot;
  308. baseUrl: &quot;https://superops.slack.com/services/hooks/jenkins-ci/&quot;
  309. tokenCredentialId: &quot;slack-token&quot;
  310. globalLibraries:
  311. libraries:
  312. - defaultVersion: &quot;master&quot;
  313. allowVersionOverride: true
  314. name: &quot;aba-jenkins-library&quot;
  315. implicit: true
  316. retriever:
  317. modernSCM:
  318. scm:
  319. git:
  320. credentialsId: &quot;github-credentials&quot;
  321. id: &quot;shared-library-creds&quot;
  322. remote: &quot;https://github.com/aba-aba/aba-jenkins-library.git&quot;
  323. traits:
  324. - &quot;gitBranchDiscovery&quot;
  325. - &quot;cleanBeforeCheckoutTrait&quot;
  326. - &quot;ignoreOnPushNotificationTrait&quot;
  327. additionalPlugins:
  328. - junit:1119.1121.vc43d0fc45561
  329. - prometheus:2.0.11
  330. - saml:4.352.vb_722786ea_79d
  331. - role-strategy:546.ve16648865996
  332. - blueocean-web:1.25.5
  333. - github-branch-source:1677.v731f745ea_0cf
  334. - git-changelog:3.23
  335. - scriptler:3.5
  336. - sshd:3.249.v2dc2ea_416e33
  337. - rich-text-publisher-plugin:1.4
  338. - matrix-project:785.v06b_7f47b_c631
  339. - build-failure-analyzer:2.3.0
  340. - testng-plugin:555.va0d5f66521e3
  341. - allure-jenkins-plugin:2.30.2
  342. - timestamper:1.18
  343. - ws-cleanup:0.42
  344. - build-timeout:1.21
  345. - slack:616.v03b_1e98d13dd
  346. - email-ext:2.91
  347. - docker-commons:1.19
  348. - docker-workflow:521.v1a_a_dd2073b_2e
  349. - rundeck:3.6.11
  350. - parameter-separator:1.3
  351. - extended-choice-parameter:346.vd87693c5a_86c
  352. - uno-choice:2.6.3
  353. adminPassword: &quot;&quot;
  354. ingress:
  355. enabled: true
  356. hostName: jenkins.non-prod.us-west-2.int.isappcloud.com
  357. ingressClassName: nginx-int
  358. installPlugins:
  359. - kubernetes:3883.v4d70a_a_a_df034
  360. - workflow-aggregator:590.v6a_d052e5a_a_b_5
  361. - git:5.0.0
  362. - configuration-as-code:1569.vb_72405b_80249
  363. jenkinsUrlProtocol: https
  364. prometheus:
  365. enabled: true
  366. resources:
  367. limits:
  368. cpu: &quot;4&quot;
  369. memory: 8Gi
  370. requests:
  371. cpu: &quot;2&quot;
  372. memory: 4Gi
  373. sidecars:
  374. configAutoReload:
  375. resources:
  376. requests:
  377. cpu: 128m
  378. memory: 256Mi
  379. statefulSetAnnotations:
  380. pulumi.com/patchForce: &quot;true&quot;
  381. Name: eks-non-prod-us-west-2-jenkins
  382. department: aba
  383. division: enterprise
  384. environment: non-prod
  385. owner: devops
  386. project: eks-non-prod-us-west-2-jenkins
  387. team: infra
  388. tag: 2.362-jdk11
  389. version: 4.1.13
  390. Jenkins:stackTags:
  391. Name: eks-non-prod-us-west-2-jenkins
  392. department: aba
  393. division: enterprise
  394. environment: non-prod
  395. owner: devops
  396. project: eks-non-prod-us-west-2-jenkins
  397. team: infra
  398. aws:region: us-west-2

答案1

得分: 1

以下是翻译好的内容:

Kubernetes插件分配Jenkins代理在Kubernetes pod中。在这些pod中,总是有一个特殊的容器jnlp,它运行Jenkins代理。其他容器可以运行您选择的任意进程,并且可以在代理pod的任何容器中动态运行命令...
默认情况下,命令将在运行Jenkins代理的jnlp容器中执行。 (jnlp的名称是历史原因,为了兼容性而保留。)
...此外,在Kubernetes Pod模板部分,我们需要配置将用于启动代理pod的镜像。除非在不寻常情况下,我们不建议覆盖jnlp容器。

https://plugins.jenkins.io/kubernetes/

要自定义jnlp镜像,您可以在代理块中指定,然后在容器块中使用容器标签来运行该容器:

英文:

The kubernetes plugin has a summary of what the JNLP is used for. It's recommended to retain the JNLP container, and the name is JNLP mostly for historical reasons. It sounds like it's not JWS.

> The Kubernetes plugin allocates Jenkins agents in Kubernetes pods. Within these pods, there is always one special container jnlp that is running the Jenkins agent. Other containers can run arbitrary processes of your choosing, and it is possible to run commands dynamically in any container in the agent pod...
> Commands will be executed by default in the jnlp container, where the Jenkins agent is running. (The jnlp name is historical and is retained for compatibility.)
>...In addition to that, in the Kubernetes Pod Template section, we need to configure the image that will be used to spin up the agent pod. We do not recommend overriding the jnlp container except under unusual circumstances.

https://plugins.jenkins.io/kubernetes/

To customize the jnlp image you specify that in the agent block then using the container label in the container block to run on that container:

  1. pipeline {
  2. agent {
  3. kubernetes {
  4. yaml &#39;&#39;&#39;
  5. apiVersion: v1
  6. kind: Pod
  7. metadata:
  8. labels:
  9. some-label: some-label-value
  10. spec:
  11. containers:
  12. - name: jnlp
  13. image: &#39;jenkins/inbound-agent&#39; // your image you want to override
  14. args: [&#39;\$(JENKINS_SECRET)&#39;, &#39;\$(JENKINS_NAME)&#39;]
  15. - name: maven
  16. image: maven:alpine
  17. command:
  18. - cat
  19. tty: true
  20. - name: busybox
  21. image: busybox
  22. command:
  23. - cat
  24. tty: true
  25. &#39;&#39;&#39;
  26. retries 2
  27. }
  28. }
  29. stages {
  30. stage(&#39;Run maven&#39;) {
  31. steps {
  32. container(&#39;maven&#39;) { // specify which container to run this on
  33. sh &#39;mvn -version&#39;
  34. }
  35. container(&#39;busybox&#39;) {
  36. sh &#39;/bin/busybox&#39;
  37. }
  38. }
  39. }
  40. }
  41. }

huangapple
  • 本文由 发表于 2023年2月23日 22:02:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定