使用 kubernetes 插件在 kubernetes 并行 jenkins 代理
Parallel jenkins agents at kubernetes with kubernetes plugin
我使用的是 Jenkins 版本 2.190.2 和 Kubernetes 插件 1.19.0
我有这个詹金斯作为 AWS 的 kubernetes 集群的主人。
这个 jenkins 配置了 kubernetes 插件,运行 没问题。
我配置了一些 运行ning 的 pod 模板和容器。
我能够 运行 指定代理和容器的声明性管道。
我的问题是我无法 运行 并行作业。
当同时执行多个作业时,第一个作业开始,创建 pod 并执行东西。即使使用不同的代理,第二个作业也会等待第一个作业结束。
示例:
管道 1
pipeline {
agent { label "bash" }
stages {
stage('init') {
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
}
}
管道 2
pipeline {
agent { label "bash2" }
stages {
stage('init') {
steps {
container('bash2') {
echo 'bash2'
sleep 300
}
}
}
}
}
这是 org.csanchez.jenkins.plugins.kubernetes 日志。我已经上传到 wetransfer -> we.tl/t-ZiSbftKZrK
我已经阅读了很多关于这个问题的文章,我已经配置了 jenkins 从这个开始 JAVA_OPTS 但是问题没有解决。
-Dhudson.slaves.NodeProvisioner.initialDelay=0
-Dhudson.slaves.NodeProvisioner.MARGIN=50
-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85
Kubernetes 插件配置为:
- Kubernetes cloud / Concurrency Limit = 50. 我已经配置了没有值,但问题仍然存在
- Kubernetes 云/Pod 保留 = 从不
- 无值的 Pod 模板/并发限制。我已经配置了10,但问题仍然存在
- Pod 模板/Pod 保留 = 默认值
我缺少什么配置或我在做什么错误?
你的pods是并行创建的
Oct 31, 2019 3:13:30 PM INFO org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
Created Pod: default/bash-4wjrk
...
Oct 31, 2019 3:13:30 PM INFO org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
Created Pod: default/bash2-3rxck
但是你的 bash2 pod 失败了
Caused by: java.net.UnknownHostException: jenkins-jnlp.default.svc.cluster.local
你应该使用 Parallel Stages. Which you can find described in the Jenkins documentation for pipeline syntax.
Stages in Declarative Pipeline may declare a number of nested stages within a parallel
block, which will be executed in parallel. Note that a stage must have one and only one of steps
, stages
, or parallel
. The nested stages cannot contain further parallel
stages themselves, but otherwise behave the same as any other stage
, including a list of sequential stages within stages
. Any stage containing parallel
cannot contain agent
or tools
, since those are not relevant without steps
.
In addition, you can force your parallel
stages to all be aborted when one of them fails, by adding failFast true
to the stage
containing the parallel
. Another option for adding failfast
is adding an option to the pipeline definition: parallelsAlwaysFailFast()
示例管道可能如下所示:
Jenkinsfile
pipeline {
agent none
stages {
stage('Run pod') {
parallel {
stage('bash') {
agent {
label "init"
}
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
stage('bash2') {
agent {
label "init"
}
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
}
}
}
}
由于另一个问题,我终于解决了我的问题。
我们开始在 create normal pods 时出错,因为我们在 aws 的 kubernetes 节点没有足够的空闲 ip。由于这个错误,我们扩展了节点,现在 jenkins 管道可以 运行 与不同的 pods 和容器并行。
我使用的是 Jenkins 版本 2.190.2 和 Kubernetes 插件 1.19.0 我有这个詹金斯作为 AWS 的 kubernetes 集群的主人。 这个 jenkins 配置了 kubernetes 插件,运行 没问题。 我配置了一些 运行ning 的 pod 模板和容器。 我能够 运行 指定代理和容器的声明性管道。
我的问题是我无法 运行 并行作业。 当同时执行多个作业时,第一个作业开始,创建 pod 并执行东西。即使使用不同的代理,第二个作业也会等待第一个作业结束。
示例:
管道 1
pipeline {
agent { label "bash" }
stages {
stage('init') {
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
}
}
管道 2
pipeline {
agent { label "bash2" }
stages {
stage('init') {
steps {
container('bash2') {
echo 'bash2'
sleep 300
}
}
}
}
}
这是 org.csanchez.jenkins.plugins.kubernetes 日志。我已经上传到 wetransfer -> we.tl/t-ZiSbftKZrK
我已经阅读了很多关于这个问题的文章,我已经配置了 jenkins 从这个开始 JAVA_OPTS 但是问题没有解决。
-Dhudson.slaves.NodeProvisioner.initialDelay=0
-Dhudson.slaves.NodeProvisioner.MARGIN=50
-Dhudson.slaves.NodeProvisioner.MARGIN0=0.85
Kubernetes 插件配置为:
- Kubernetes cloud / Concurrency Limit = 50. 我已经配置了没有值,但问题仍然存在
- Kubernetes 云/Pod 保留 = 从不
- 无值的 Pod 模板/并发限制。我已经配置了10,但问题仍然存在
- Pod 模板/Pod 保留 = 默认值
我缺少什么配置或我在做什么错误?
你的pods是并行创建的
Oct 31, 2019 3:13:30 PM INFO org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
Created Pod: default/bash-4wjrk
...
Oct 31, 2019 3:13:30 PM INFO org.csanchez.jenkins.plugins.kubernetes.KubernetesLauncher launch
Created Pod: default/bash2-3rxck
但是你的 bash2 pod 失败了
Caused by: java.net.UnknownHostException: jenkins-jnlp.default.svc.cluster.local
你应该使用 Parallel Stages. Which you can find described in the Jenkins documentation for pipeline syntax.
Stages in Declarative Pipeline may declare a number of nested stages within a
parallel
block, which will be executed in parallel. Note that a stage must have one and only one ofsteps
,stages
, orparallel
. The nested stages cannot contain furtherparallel
stages themselves, but otherwise behave the same as any otherstage
, including a list of sequential stages withinstages
. Any stage containingparallel
cannot containagent
ortools
, since those are not relevant withoutsteps
.In addition, you can force your
parallel
stages to all be aborted when one of them fails, by addingfailFast true
to thestage
containing theparallel
. Another option for addingfailfast
is adding an option to the pipeline definition:parallelsAlwaysFailFast()
示例管道可能如下所示:
Jenkinsfile
pipeline {
agent none
stages {
stage('Run pod') {
parallel {
stage('bash') {
agent {
label "init"
}
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
stage('bash2') {
agent {
label "init"
}
steps {
container('bash') {
echo 'bash'
sleep 300
}
}
}
}
}
}
}
由于另一个问题,我终于解决了我的问题。 我们开始在 create normal pods 时出错,因为我们在 aws 的 kubernetes 节点没有足够的空闲 ip。由于这个错误,我们扩展了节点,现在 jenkins 管道可以 运行 与不同的 pods 和容器并行。