一、安装Jenkins
挂载宿主机docker目录,使Jenkins可使用宿主机docker命令
docker run -d -u root -v /var/jenkins:/var/jenkins_home -v '/usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -p 18080:8080 -p 15000:5000 --name myjenkins --restart=always --privileged Jenkins/Jenkins
首次使用,输入以下文件password.
docker exec -i 7c9e526e2845 cat /var/jenkins_home/secrets/initialAdminPassword
选择需要插件,安装
从高级选项卡,修改hudson.model.UpdateCenter.xml里的加速镜像
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
二、配置harbor密钥到K8S
方法1:
在Master登录harbor
docker login 192.168.137.12:80 -u admin -p 123456
查看密钥数据
cat ~/.docker/config.json
Base64加密
cat ~/.docker/config.json|base64 -w 0
编写yaml文件,data节点
apiVersion: v1 kind: Secret metadata: name: mysecret2 type: kubernetes.io/dockerconfigjson data: .dockerconfigjson: ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEzNy4xMjo4MCI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZNVEl6TkRVMiIKCQl9Cgl9Cn0=
方法2
kubectl create secret docker-registry harbor-secret -secret --docker-server=192.168.137.12:80 --docker-username=admin --docker-password=123456
Deployment配置文件
三、Publish over SSH设置
Pipeline脚本
pipeline { agent any stages { stage("checkout"){ steps{ checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'http://192.168.137.10:13001/whh/net5.git']]]) } } stage('build images') { steps { sh 'docker build -t 192.168.137.12:80/test/net6api:v1 .' } } stage('pull harbor') { steps { sh 'docker login 192.168.137.12:80 -u admin -p 123456' sh 'docker push 192.168.137.12:80/test/net6api:v1' } } stage('pull k8s') { steps { sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s master', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'kubectl apply -f /root/deployment.yaml', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'deployment.yaml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)]) } } } }
Jenkins构建成功
四、测试
1.查看K8S POD
kubectl get pod -owide
2.chrome测试
标签:false,--,192.168,137.12,生产线,构建,Jenkins,docker From: https://www.cnblogs.com/heho/p/16925647.html