一、jenkins安装插件
搜索插件:Kubernetes Credentials Plugin、Kubernetes plugin、Kubernetes CLI Plugin 后进行安装 Install without restart;
二、生成连接k8s的证书文件
先生成jenkins的专用config文件或者用最高权限的其他config文件
cat .kube/config apiVersion: v1 clusters: - cluster: certificate-authority: /Users/biyin-lhr/.minikube/ca.crt extensions: - extension: last-update: Wed, 07 Sep 2022 18:10:39 CST provider: minikube.sigs.k8s.io version: v1.25.2 name: cluster_info server: https://127.0.0.1:57188 name: minikube contexts: - context: cluster: minikube extensions: - extension: last-update: Wed, 07 Sep 2022 18:10:39 CST provider: minikube.sigs.k8s.io version: v1.25.2 name: context_info namespace: default user: minikube name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube user: client-certificate: /Users/biyin-lhr/.minikube/profiles/minikube/client.crt client-key: /Users/biyin-lhr/.minikube/profiles/minikube/client.key #注意:生成cert.pfx时一定要创建密码,在jenkins上传证书时需要使用。 openssl pkcs12 -export -out cert.pfx -inkey .minikube/profiles/minikube/client.key -in .minikube/profiles/minikube/client.crt -certfile .minikube/ca.crt
在jenkins的web界面创建凭证
Manage Jenkins --> Manage Credentials
下图为创建完成后的样子:
三、jenkins界面添加k8s集群
Manage Jenkins --> manage Nodes and Clouds --> Configure Clouds
Name: 给所加的k8s集群设置名字
Kubernetes URL: 集群的api-server出口地址,可以通过kubectl cluster info 查看
Kubernetes server certificate key:config文件中的client-key内容,记得解密
Credentials: 选择上一步添加的证书。
Test Connection:测试连接,Connected to Kubernetes
标签:name,Kubernetes,client,minikube,jenkins,k8s,连接 From: https://www.cnblogs.com/lllhr/p/16667592.html