一:流程结构
说明:
1. 用户向Gitlab提交代码,代码中包含 Dockerfile文件。
2.Jenkins监听Gitlab代码库的推送和变更事件
3.Jenkins调用maven插件对源码进行编译打包
4.Jenkins调用docker工具根据Dockerfile文件生成镜像,并推送镜像到Harbor仓库
5.Jenkins通过SSH远程调用Kubernetes集群的master节点,更新Pod的模板YAML文件,调用kubectl命令进行发布操作
6.Kubernetes集群的Node 节点从Harbor仓库,拉取镜像,启动Pod和应用容器。
二:实施步骤
1.Docker+Gitlab+Jenkins+Maven代码持续集成与自动部署
请参照之前的博文 http://blog.itpub.net/28624388/viewspace-2151638/
2.使用Harbor作为私有镜像仓库
请参照之前的博文 http://blog.itpub.net/28624388/viewspace-2153568/
3.kubernetes集成(以应用desktop为例)
a.Jenkins中安装SSH插件
b.Jenkins中创建Credentials ssh

c.系统关联-->系统配置-->ssh remote hosts配置

d.在项目配置的最后,增加ssh remote命令调用的脚本

desktop-ds.yaml 文件如下
-
apiVersion: extensions/v1beta1
-
kind: DaemonSet
-
metadata:
-
name: desktop
-
labels:
-
app: desktop
-
spec:
-
selector:
-
matchLabels:
-
app: desktop
-
template:
-
metadata:
-
labels:
-
app: desktop
-
spec:
-
containers:
-
- name: desktop
-
image: 120.79.156.135/desktop/tomcat:desktop
-
volumeMounts:
-
- name: jdkdir
-
mountPath: /usr/local/jdk
-
- name: uploaddir
-
mountPath: /mnt/upload
-
ports:
-
- containerPort: 8080
-
imagePullSecrets:
-
- name: registry-secret
-
volumes:
-
- name: jdkdir
-
hostPath:
-
path: /mnt/devops/jdk1.8
-
- name: uploaddir
-
hostPath:
-
path: /mnt/upload
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28624388/viewspace-2153655/
,如需转载,请注明出处,否则将追究法律责任。