jenkins 連接k8s
一、jenkins安裝插件

?
? 搜索插件:Kubernetes Credentials Plugin、Kubernetes plugin、Kubernetes CLI Plugin 后進(jìn)行安裝 Install without restart;
二、生成連接k8s的證書文件
先生成jenkins的專用config文件或者用最高權(quán)限的其他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時(shí)一定要?jiǎng)?chuàng)建密碼,在jenkins上傳證書時(shí)需要使用。 openssl pkcs12 -export -out cert.pfx -inkey .minikube/profiles/minikube/client.key -in .minikube/profiles/minikube/client.crt -certfile .minikube/ca.crt
在jenkins的web界面創(chuàng)建憑證
Manage Jenkins --> Manage Credentials?

?
?

?
?下圖為創(chuàng)建完成后的樣子:

?
?三、jenkins界面添加k8s集群
Manage Jenkins --> manage Nodes and Clouds --> Configure Clouds

?
? Name: 給所加的k8s集群設(shè)置名字
Kubernetes URL: 集群的api-server出口地址,可以通過kubectl cluster info 查看
Kubernetes server certificate key:config文件中的client-key內(nèi)容,記得解密
Credentials: 選擇上一步添加的證書。
Test Connection:測(cè)試連接,
Connected to Kubernetes
鏈接:https://www.dianjilingqu.com/523785.html