jenkins对接K8S

创建连接K8S的凭据

查看需要使用到的命名空间
[root@k8s ~]# kubectl get ns |grep arts-system
arts-system       Active   16d
创建service accounts
[root@k8s ~]# kubectl create sa jenkins-k8s -n arts-system
serviceaccount/jenkins-k8s created
[root@k8s ~]# kubectl get sa -n arts-system |grep jenkins
jenkins-k8s   1         14s
对jenkins做cluster-admin绑定
[root@k8s ~]# kubectl create clusterrolebinding jenkins-k8s-role-binding --clusterrole cluster-admin --serviceaccount=arts-system:jenkins-k8s -n arts-system
clusterrolebinding.rbac.authorization.k8s.io/jenkins-k8s-role-binding created
[root@k8s ~]# kubectl get clusterrolebinding -n arts-system
NAME                       AGE
jenkins-k8s-role-binding   29s
system:coredns             3y264d
查看arts-system命名空间中的sa和secret
[root@k8s ~]# kubectl get sa,secret -n arts-system
NAME                         SECRETS   AGE
serviceaccount/default       1         16d
serviceaccount/jenkins-k8s   1         3m30s

NAME                             TYPE                                  DATA   AGE
secret/default-token-scbjb       kubernetes.io/service-account-token   3      16d
secret/jenkins-k8s-token-qjr6p   kubernetes.io/service-account-token   3      3m30s
提取token
[root@k8s ~]# kubectl describe secrets jenkins-k8s-token-qjr6p -n arts-system
Name:         jenkins-k8s-token-qjr6p
Namespace:    arts-system
Labels:       
Annotations:  kubernetes.io/service-account.name: jenkins-k8s
              kubernetes.io/service-account.uid: e7d1633d-3419-4a95-b8e8-e4f1956989e8

Type:  kubernetes.io/service-account-token

Data
====
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IlNybzBGYzNoYklYWlJlM2NsU0VWNTY2TGZlM2E3a1RUYm5ObmJxLXFZMjAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJhcnRzLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJqZW5raW5zLWs4cy10b2tlbi1xanI2cCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJqZW5raW5zLWs4cyIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImU3ZDE2MzNkLTM0MTktNGE5NS1iOGU4LWU0ZjE5NTY5ODllOCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDphcnRzLXN5c3RlbTpqZW5raW5zLWs4cyJ9.wIPNdnYKqNGdUv0bYwDgGFW4_EhR3vKcFdHsmrQFbtiWomLBQERZe9xs1adO4qJm5V40sCozWJWiv6yE9ZN8stEI_FTJcaLDeLJDqYe-2BAuGXG6sDOUsjk2vc7K4NJb2xi508xyof5xuS2mTBwMXiyO_zhefrXVq9NrQd9hrUFQOhcod_SoWu965unOA4uDqxi9Sgll4RW-yG9lN5PK18xaGEHvJHldS_vT8JhvQ1lvjxDWxZkYvXJLN9i0Yp0bHal6GNCl4tDaMmTCyvuhuhBWldB57fwNrO71hrl1rN8BKy0ngeJ4SUr3TqA0cSpDXyAdS01OnwaokiVt3APM-A
ca.crt:     1099 bytes

jenkins上创建连接K8S的凭证

jenkins对接K8S_第1张图片

jenkins连接K8S

jenkins对接K8S_第2张图片

配置连接k8s需要的kubeconfig文件

获取k8s的kubecofnig文件
[root@k8s kubernetes]# cat kubeconfig
Version: v1
kind: Config
users:
- name: controllermanager
  user:
    client-certificate: /var/lib/kubernetes/cs_client.crt
    client-key: /var/lib/kubernetes/cs_client.key
clusters:
- name: local
  cluster:
    certificate-authority: /var/lib/kubernetes/ca.crt
    server: https://192.168.73.100:6443
contexts:
- context:
    cluster: local
    user: controllermanager
  name: my-context
current-context: my-context
将kubecofig文件中的认证填写到该文件中
### 获取认证文件内容并进行base64编码
[root@k8s kubernetes]# cat /var/lib/kubernetes/cs_client.crt | base64 | tr -d '\n'
LS0tLS1CRUdJTiBDRVJUSUZJQ0F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BrSkxMVwp0YVNzRms5UnNNdFBjcXFjSmdPL3JGelVuMDRhRHdJREFRQUJvMUF3VGpBZEJnTlZIUTRFRmdRVU9kZFI1dlhYCk5kaWZWRmFNWjRUZ0FQY0U3L1F3SHdZRFZSMGpCQmd3Rm9BVU9kZFI1dlhYTmRpZlZGYU1aNFRnQVBjRTcvUXcKREFZRFZSMFRCQVV3QXdFQi96QU5CZ2txaGtpRzl3MEJBUXNGQUFPQ0FRRUFXTnA2Nm05QjJOZWUyaHdLbmo1awp6WDY2d0YrbkFrQlVFbEhQeDlsZDBKcVhDaDRUZ2RNcGR0ckRaNG1CUS9oUXVpaThtQjQ2TFlDM2VtVGYvRGJMCkxnSUN2eVhlLythWjY1MkVBeFNtUndpU3FOaHFGc09hcUx1UlVialpRKzNvRmt0WVlVN0pFcWs2bnlub3hUR0oKeDFBQU45cFdXdkRPT09tNHpscGdxY3Y4cnpEL1MweEZoaWFWVnR6N29KeGVsdllpTzFlclJybDB3a2Y0SnlJVwpPTlNIZ0VXaVFTRTFUNHp2WHV3MHI2MndXRUs2ZktFYXZHYWtHU3B5YWxjcFVPTE01YmE3dnZzOWRTRWVGZEhhClZUL0xXWTA1RmJBN1hzOXd4SnNMS2djeEVzM2Y3dkVaaGhQRTJjZHpPeG9ra3B6NjdqZHN6QVZCbzZWQlA5SHoKR1E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://192.168.73.100:6443
contexts:
- context:
    cluster: local
    user: controllermanager
  name: my-context
current-context: my-context

安装 配置文件管理 插件

jenkins对接K8S_第3张图片

添加kubecofnig文件

jenkins对接K8S_第4张图片
jenkins对接K8S_第5张图片

jenkins对接K8S_第6张图片

jenkins对接K8S_第7张图片

生成一个流水

jenkins对接K8S_第8张图片

生成的流水脚本如下
configFileProvider([configFile(fileId: '1af5255e-d0db-4009-8218-12448ede43e3', targetLocation: 'arts-system.kubeconfig')]) {
    // some block
}
完善流水脚本,进行一个测试
pipeline {
    agent any

    stages {
        stage('测试部署') {
            steps {
                script{
                    configFileProvider([configFile(fileId: '1af5255e-d0db-4009-8218-12448ede43e3', targetLocation: 'arts-system.kubeconfig')]) {
                        sh '''
                        kubectl get node --kubeconfig=arts-system.kubeconfig
                        '''
                    }
                }
            }
        }
    }
}
创建一个流水然后进行测试的结果如下

jenkins对接K8S_第9张图片

你可能感兴趣的:(CICD,jenkins,kubernetes,servlet)