Jenkins kubernetes 插件不起作用 [英] Jenkins kubernetes plugin not working
问题描述
我正在尝试使用 jenkins-kubernetes 插件设置 Jenkins Dynamic slaves 创建.
我的 jenkins 在 K8s 集群之外运行.
链接:
并且连接成功.
然后我用 pod 模板创建了一个作业:
问题开始了:<强>1.当我最初运行此作业时,它会运行并且我的 pod 内的 jenkins 从属容器无法连接并抛出:
我启用了 JNLP 端口 (50000) 不确定它是否是正确的端口,即使在 Jenkins 中使用随机选项进行测试也没有任何效果.
2.现在我放弃了这个 jenkins 工作并重新运行它说:
由用户 Vaibhav Jain 发起[管道] podTemplate[管道] {[管道]节点还在等待安排任务詹金斯没有标签 defaultlabel
并且在 kubernetes 中没有任何 pod 正在启动.这很奇怪.
我不确定我做错了什么.需要帮助!
我建议您不要使用证书,而是通过创建 serviceAccount 来使用 kubernetes 中的凭据:
---api版本:v1种类:服务账户元数据:姓名:詹金斯---种类:角色api版本:rbac.authorization.k8s.io/v1beta1元数据:姓名:詹金斯规则:- apiGroups: [""]资源:[豆荚"]动词:[创建"、删除"、获取"、列表"、补丁"、更新"、监视"]- apiGroups: [""]资源:[pods/exec"]动词:[创建"、删除"、获取"、列表"、补丁"、更新"、监视"]- apiGroups: [""]资源:[豆荚/日志"]动词:["get","list","watch"]- apiGroups: [""]资源:[秘密"]动词:[得到"]---api版本:rbac.authorization.k8s.io/v1beta1种类:角色绑定元数据:姓名:詹金斯角色参考:apiGroup: rbac.authorization.k8s.io种类:角色姓名:詹金斯科目:- 种类:ServiceAccount姓名:詹金斯
并使用该 serviceAccount 部署 jenkins:
apiVersion: extensions/v1beta1种类:部署元数据:标签:应用程序:詹金斯姓名:詹金斯规格:复制品:1选择器:匹配标签:应用程序:詹金斯模板:元数据:标签:应用程序:詹金斯规格:服务帐户名称:詹金斯....
我给你看我的 Kubernetes 插件截图(注意 JNLP 端口的 Jenkins 隧道,'jenkins' 是我的 kubernetes 服务的名称):
对于凭据:
然后填写文件(ID将自动生成,描述将显示在凭据列表框中),但请确保如我之前所说的那样在 kubernetes 中创建了 serviceAccount:
我的说明是针对 kubernetes 中的 Jenkins master.如果您想在集群外使用它(但在集群内使用从属设备),我认为您必须使用简单的登录名/密码凭据.
关于你上次的错误,似乎是主机解析错误:slave无法解析你的主机.
希望能帮到你.
I am trying to setup Jenkins Dynamic slaves creation using jenkins-kubernetes plugin.
My jenkins is running outside K8s Cluster.
Link: https://github.com/jenkinsci/kubernetes-plugin
My jenkins version is 2.60.2 and Kubernetes plugin version is 1.1.2
I followed the steps mention on the readme and successfully setup the connection.
My setting looks like:
And connection is successful.
Then I created a job with pod template :
Here starts the problem: 1. When I run this job initially it runs and jenkins slave container inside my pod not able to connect and throws:
I have enabled JNLP port(50000) not sure if it is the right port even tested with random option in Jenkins nothing worked.
2. Now I discarded this jenkins job and re run again it says:
Started by user Vaibhav Jain
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
Jenkins doesn’t have label defaultlabel
and no pod is getting started in kubernetes. This is weird.
I am not sure what I am doing wrong. Need help!
Instead of using certificates, I suggest you to use credentials in kubernetes, by creating a serviceAccount:
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: jenkins
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: jenkins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: jenkins
subjects:
- kind: ServiceAccount
name: jenkins
and deploying jenkins using that serviceAccount:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: jenkins
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
serviceAccountName: jenkins
....
I show you my screenshots for Kubernetes plugin (note Jenkins tunnel for the JNLP port, 'jenkins' is the name of my kubernetes service):
For credentials:
Then fill the fileds (ID will be autogenerated, description will be shown in credentials listbox), but be sure to have created serviceAccount in kubernetes as I said before:
My instructions are for the Jenkins master inside kubernetes. If you want it outside the cluster (but slaves inside) I think you have to use simple login/password credentials.
For what concerns your last error, it seems to be a host resolution error: the slave cannot resolve your host.
I hope it helps you.
这篇关于Jenkins kubernetes 插件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!