同事的jenkins 链接自己的 k8s 总是出问题 给出了资料和服务器 进行处理。

同时给出的参考资料:https://blog.csdn.net/diantun00/article/details/81180694

这边用自己的服务器简单进行了测试。

jenkins的地址

http://10.24.101.161:8080/configure

k8s 集群的

https://10.24.103.1:6443

1. 验证jenkins 已经添加了 kubernetes 的插件

如果没有的话自行安装

然后 进行系统配置

拖到最后面 添加一个云

我的k8s 是使用 kubeadm 直接 安装的 比较简单, 根据 作者的说法进行处理

进入 kubernetes的配置目录

cd /etc/kubernetes

查看 admin.conf

cat admin.conf

我这边的内容为:

反正是测试服务器---说不定明天我就删了-- 证书 密钥 无所谓。。。

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNE1EVXhPVEEyTURBeE5Gb1hEVEk0TURVeE5qQTJNREF4TkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTmJ4ClhvdkFiL0pvNkluOGo3MWgwNHFRQnMwdGNLMU91cnY3OVhPbEZReEdpUUpUVnE0L1VCVXhNenhvaVFnaDBqanYKbWk3T2RjMlZUTmR1bVpPbi8rY1B1MldkVTF6R05rb04yeFYvaFN0Y3k0UmFiNEF4MCt4M3NLS0NFY1hpeVZlYgpNbm52NnM1T2UyOXVJL2hBK1cxVnRuekcxclpqaTd5Umo2blpQZnN1WG5kN2xQZ0ZWRlRsTWxpMTFVa3R5RVg4CmtMVys2Skx5eW5PWUZndVg4cGp1andINWxlWWs0R2xKV0NGNU10czBldlJaTFVMWVhUQi96NDZEL3pFdUgxc0kKZHlsTFpOVTdqUE5CK0tWMUUwVm1lVmRvbE1WejI4SWZZbUVoR1FJTTN1SmNNRTRlWTFSQlVUWDFUbHQ0TmNMSgp6MlNDb2ZvNURNUjNsUTdDbkEwQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFHQmxBY2pvOGp4M0RLZyt1K0hQTzZ3Z3dYMDMKbkg5cnMyMEViNHBYaVVrUkpxUGlDa096WW5xYVl1S2pNRjhGb2VVRmViaDErQ3B1aFY1U0hQWVlsK1EvRCt4dApMYzVlNFVoMFZ6RnI1MWJMWDd0UXFNaHpxWlo0czRIVW1IRlVyclJPZGw3QmduRlFZZkVGRlRKZTlBRGY4ZTBQCldBQ1FXZXJvUGpPMFY2K3NoU3VpZlFMb1k1NStWREd6anFOWnlqUkdUOUFnUFBJdDdrOHVITnRpQUROOWFIVW0KN3RrR3hlNEhMNnFzSnc5dGhNQ3U1R3dvbDF6THcrMzZUdjR0YjJmWlZ0UTZXakh4RUFKMVJZcFdoU0tsVnpqUQo1WlZ5RWgraDZzL01YR1BtRW5SaDNVMmg2YjdjTVNROElQZDFlTDE5SnA1dXZzN3VqcEkzalB2dUlRVT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
    server: https://10.24.103.1:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJTk1kTHhDUlZjS1l3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4T0RBMU1Ua3dOakF3TVRSYUZ3MHhPVEExTVRrd05qQXdNVGxhTURReApGekFWQmdOVkJBb1REbk41Yz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TdDbkEwQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFHQmxBY2pvOGp4M0RLZyt1K0hQTzZ3Z3dYMDMKbkg5cnMyMEViNHBYaVVrUkpxUGlDa096WW5xYVl1S2pNRjhGb2VVRmViaDErQ3B1aFY1U0hQWVlsK1EvRCt4dApMYzVlNFVoMFZ6RnI1MWJMWDd0UXFNaHpxWlo0czRIVW1IRlVyclJPZGw3QmduRlFZZkVGRlRKZTlBRGY4ZTBQCldBQ1FXZXJvUGpPMFY2K3NoU3VpZlFMb1k1NStWREd6anFOWnlqUkdUOUFnUFBJdDdrOHVITnRpQUROOWFIVW0KN3RrR3hlNEhMNnFzSnc5dGhNQ3U1R3dvbDF6THcrMzZUdjR0YjJmWlZ0UTZXakh4RUFKMVJZcFdoU0tsVnpqUQo1WlZ5RWgraDZzL01YR1BtRW5SaDNVMmg2YjdjTVNROElQZDFlTDE5SnA1dXZzN3VqcEkzalB2dUlRVT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
|base64 -d >ca.crt

原作者写的更好, 这里直接copy了

 

用到上面提到的kubernetes的配置文件

文件中有三个值 certificate-authority-data 、client-certificate-data 、 client-key-data 

解码它们获得证书 ,注意将上面的值替换称自己的一大长传字符串

echo certificate-authority-data | base64 -d > ca.crt
echo client-certificate-data | base64 -d > client.crt
echo client-key-data | base64 -d > client.key

然后根据如上内容生成客户端认账的 证书

openssl pkcs12 -export -out cert.pfx -inkey client.key -in client.crt -certfile ca.crt

注意导出时收入输入密码。

这里完整的复制的原作者的内容 openssl 的使用虽然之前学过 但是太不精通了。。

然后k8s 里面进行处理

将 ca.crt base64 解码之后的证书内容放进来

如图示

 

 然后添加jenkins的证书

选择 证书

 

 然后 上传 文件 输入导出时的密码

然后 进行测试

能够成功。

管理jenkins的凭据

不知道怎么删除。。。

 

转载于:https://www.cnblogs.com/jinanxiaolaohu/p/9412324.html

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐