Jenkins use ca_https to access kubernetes_cluster api

  1. 通过之前生成的admin的证书访问api server:

    1
    ➜  pipeline curl --insecure --cacert /data/kubernetes/ssl/ca.crt --key /data/kubernetes/ssl/admin-key.pem --cert /data/kubernetes/ssl/admin.pem https://192.168.0.14:6443 
  2. 在kubernetes master上调用本地接口8080访问api server:

    1
    2
    3
    4
    5
    6
    ➜  pipeline curl http://127.0.0.1:8080
    {
    "paths": [
    "/api",
    "/api/v1",
    ....
  3. 通过”~/.kube/config”配置文件(base64 -d转码后生成的证书)(如下)访问api server:

If you are not hosting Jenkins on the same Kubernetes cluster (or not hosting it on Kubernetes at all), then you need to perform a few extra steps to configure the access to your Kubernetes cluster.

1
curl --insecure --cacert ./ca.crt --key ./client.key -cert ./client.crt https://192.168.0.14:6443

详细步骤如下:

  • cat ~/.kube/config

  • 将”certificate-authority-data”的值保存在一个文件ca中
    然后:cat ca|base64 -d > ca.crt,生成ca证书文件

  • we need to grab the base64 encoded client-certificate-data,同样:将”client-certificate-data”的值保存在1.client.crt中,cat 1.client.crt |base64 -d > client.crt

  • 将”client-key-data”的值保存在1.client.key中,cat 1.client.key |base64 -d > client.key

  • 执行:”openssl pkcs12 -export -out cert.pfx -inkey client.key -in client.crt -certfile ca.crt -passout pass:passwd”其中cert.pfx上传给Jenkins,其密码为passwd

  • jenkins新建Credentials,Kind选择”Certificate”,通过”Upload PKCS#12 certificate”将生成的cert.pfx上传上来,Password为刚才pass后面指定的值”passwd”

  • Kubernetes URL:由”http://127.0.0.1:8080"更改为:"https://192.168.0.14:6443"
    “127.0.0.1:8080”为本地验证的url,类型为:http;”192.168.0.14:6443”则为远程连接接口,类型为:https
    至此需要认证的https ca证书配置完成。


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!