我正在运行jenkins作业来构建我们的Maven应用程序并将其部署到kubernetes集群中。我已按顺序创建了pod容器模板来部署模块。
当我要构建我的詹金斯工作时,构建失败并出现以下错误,
Still waiting to schedule task
‘Jenkins’ doesn’t have label ‘Angular_71-bt2f0’
同时,当我检查kubernetes master时,我能够看到pod正在尝试调度,并且几秒钟后它又回到了终止状态。
root@poc:/var/run# kubectl get pods
NAME READY STATUS RESTARTS AGE
angular-71-bt2f0-ns772-4rmrq 0/3 ContainerCreating 0 1s
root@poc:/var/run# kubectl get pods
NAME READY STATUS RESTARTS AGE
angular-71-bt2f0-ns772-4rmrq 2/3 Terminating 0 28s
angular-71-bt2f0-ns772-mcv9z 2/3 Error 0 8s
管道脚本
def label = "worker-${UUID.randomUUID().toString()}"
podTemplate(containers: [
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
]) {
node(POD_LABEL) {
stage('Get a Maven project') {
git 'https://github.com/jenkinsci/kubernetes-plugin.git'
container('maven') {
stage('Build a Maven project') {
sh 'mvn -B clean install'
}
}
}
}
}
请找到以下主机配置
root@poc:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
root@poc:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
poc-worker2 Ready worker 6m3s v1.17.0
poc.com Ready master 2d v1.17.0
root@poc:~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
root@poc:~# kubectl cluster-info
Kubernetes master is running at https://10.0.0.4:6443
KubeDNS is running at https://10.0.0.4:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubectl错误日志
kubectl logs angular-71-bt2f0-ns772-4rmrq
error: a container name must be specified for pod angular-77-l32fr-sfxqk-qhdgf, choose one of: [maven golang jnlp]
Below is the kubectl logs while running jenkins job
root@poc:~# kubectl logs angular103f578nkcrnfx69fk c maven
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found
root@poc:~# kubectl logs angular103f578nkcrnfx69fk c golang
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found
root@poc:~# kubectl logs angular103f578nkcrnfx69fk c jnlp
Error from server (NotFound): pods "angular103f578nkcrnfx69fk" not found
请问有人可以帮助我解决此问题,我不确定我在哪里做错了。
答案 0 :(得分:2)
因为kubectl -n jenkins-namespace get services
显示为:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cicd-jenkins ClusterIP 172.20.120.227 <none> 8080/TCP 128d
cicd-jenkins-agent ClusterIP 172.20.105.189 <none> 50000/TCP 128d
您必须转到Jenkins>管理Jenkins>配置系统(http://jenkins:8080/configure)。 然后,相应地配置 Jenkins URL 和 jenkins隧道(请参见下面的屏幕截图)
信用到https://youtu.be/MkzCVvlpiaM
如果您使用的是Jenkins代码配置(JCasC)插件,则可以通过jenkinsUrl
和jenkinsTunnel
键进行配置:
jenkins:
clouds:
- kubernetes:
name: cluster
serverUrl: https://kubernetes.default
# ....
jenkinsUrl: http://cicd-jenkins:8080/
jenkinsTunnel: cicd-jenkins-agent:50000
# ....
答案 1 :(得分:0)
也许您缺少一些东西?
下面的containerTemplates是真正的管道任务,您的jenkins从属代理(JNLP)容器在哪里?
private fun moveToFront(mainAppPackage: String) {
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
val recentTasks = activityManager.getRunningTasks(Int.MAX_VALUE)//activityManager.appTasks.map { it.taskInfo }
for (i in recentTasks.indices) {
log("PUSH Application executed : "
+ recentTasks[i].baseActivity.toShortString()
+ "\t\t ID: " + recentTasks[i].id + "")
if (recentTasks[i].baseActivity.toShortString().indexOf(mainAppPackage) > -1) {
log("PUSH TO FRONT : "
+ recentTasks[i].baseActivity.toShortString()
+ "\t\t ID: " + recentTasks[i].id + "")
activityManager.moveTaskToFront(recentTasks[i].id, ActivityManager.MOVE_TASK_WITH_HOME)
}
}
}