在deploy阶段,是将Docker镜像发布运行至Kubernetes集群,其中涉及编写Kubernetes部署发布yaml文件,具体示例如下:
--- apiVersion: apps/v1 kind: Deployment metadata: name: __APP_NAME__ spec: replicas: __REPLICAS__ selector: matchLabels: app: __APP_NAME__ strategy: type: RollingUpdate template: metadata: labels: app: __APP_NAME__ spec: imagePullSecrets: - name: wudimanong-ecr containers: - name: __APP_NAME__ image: __IMAGE__ resources: requests: memory: "1000M" limits: memory: "1000M" volumeMounts: - name: time-zone mountPath: /etc/localtime - name: java-logs mountPath: /opt/logs ports: - containerPort: __PORT__ env: - name: SPRING_PROFILES_ACTIVE value: __PROFILE__ - name: JAVA_OPTS value: -Xms1G -Xmx1G -Dapp.home=http://www.likecs.com/opt/ volumes: - name: time-zone hostPath: path: /etc/localtime - name: java-logs hostPath: path: /data/app/deployment/logs如果一切准备妥当,此时你向GitLab仓库提交代码将自动触发构建Pipeline,而Pipeline将自动运行你在“.gitlab-ci.yml”文件中定义的具体CI/CD流水线逻辑,从而实现应用的自动化发布效果。
基于GitLab-CI机制的自动化发布系统由于其构建方式比较简单,不需要太多的开发工作,因此目前不少创业公司中都采用了此类方案来实现微服务的自动化构建和交付。