一.jenkins、gitlab、nexus集群资源部署
1.资源部署yaml清单均托管至github
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2.克隆下载部署清单
git clone https://github.com/CosmicBDry/k8s-manifest.git
3.查看部署清单,apply以下清单完成部署
1)gitlab部署清单
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)jenkins部署清单
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)nexus部署清单
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
二.jenkins凭据、kubernetes代理节点配置、项目构建
1.创建需要的凭据
1)系统设置中找到凭据管理
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)找到jenkins容器sa用户jenkins-admin对应的secret
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)列出secret对应的token值,为base64编码,用于jenkins的凭据认证
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
4)将以上jenkins容器的sa账户token值粘贴至下面secret中,认证选择secret文本方式
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
5)所有需要的凭据如下,nexus的docker仓库、gitlab版本库、jenkins的集群sa等认证凭据
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2.jenkins的代理节点添加
1)找到节点管理
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)配置云代理节点
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)首先配置k8s集群相关配置信息
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
4)配置k8s集群、jenkins服务等访问入口
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
5)配置jnlp容器代理节点
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
6)配置maven容器代理节点
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
将maven容器内部仓库挂载到pvc卷,下次构建就不会重复下载相同的依赖jar包等文件,直接在本地仓库找,
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
7)配置docker-in-docker容器代理节点,负责构建docker镜像
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
挂载node节点的docker本地套接字文件至docker-in-docker容器中,使得容器直接共享node节点的docker进程,完成docker镜像的构建与推送
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3.jenkins的springboot项目构建
1)配置参数化构建
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)pipeline脚本如下,托管至GitHub:
url:https://github.com/CosmicBDry/k8s-manifest/blob/master/devops/Jenkinsfile/springboot.pipeline
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)完成创建
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
三.准备好gitlab项目
1.查看gitlab项目
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2.springboot项目(通过idear快速构建springboot)
1)项目结构
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)pom.xml文件定位包依赖
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)查看源码
查看启动类源码
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
查看控制类源码
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3.CICD项目
1)项目结构
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)springboot容器部署清单
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)dockefile文件
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
4)部署脚本
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
5)k8s集群认证文件
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
四.代码发布更新流程
1.查看当前版本为v1.1.10
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2.修改pom.xml本次更新版本为v1.1.20
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3.java源码更新
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
4.基于Jenkins的参数化构建,点击开始构建
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
5.控制台输出
1)克隆gitlab的springboot项目代码
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
2)进行maven构建编译
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
3)拉取devops项目
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
4)docker镜像的构建
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
5)是否将打好的docker镜像推送至docker镜像仓库,这里的镜像仓库用的是nexus
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
6)将构建好的镜像推送至nexus镜像仓库
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
7)是否确认部署springboot项目至k8s集群
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
8)开始部署
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
6.查看nexus的docker镜像仓库,已成功推送镜像
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
7.在k8s集群查看项目,springboot容器已成功启动
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()
8.浏览器访问测试,已更新至v1.1.20版本,完成发布更新
![k8s集群中部署jenkins、gitlab、nexus实现CICD]()