Choerodon猪齿鱼V0.23版本中的部署 > 利用部署 > 流水线性能在猪齿鱼中停用,须要切换为开发 > 利用流水线性能,相比于老版的流水线,新版本的利用流水线加强了猪齿鱼的治理性能,提供了更多的扩大。通过 Gitlab 和 猪齿鱼的 DevOps 实现提交代码后自动更新服务的流程。

前置条件

  • 猪齿鱼 DevOps

开发标准

开发人员在个性分支(feature-*)进行性能开发,实现性能开发之后将个性分支合并到环境分支develop进行部署。

自动化部署配置

在猪齿鱼中配置 K8s Config Map

性能门路:利用部署 > 资源 > 资源视图 > 抉择环境 > 配置映射

在配置映射中须要定义CM的名称,这里以hzero-dev为例,在配置映射中保护公共的环境变量,例如注册核心地址等.

调整 Chart 中的配置文件

创立实现配置映射之后,须要在k8s部署时读取cm配置,这一步须要调整我的项目下的helm配置。

留神配置的缩进,间接拷贝(Ctrl + V)IDEA会主动调整缩进,请应用Paste as Plain Text保障缩进不会被主动调整。

  • charts/hzero-platform/templates/_helpers.tpl
{{/* vim: set filetype=mustache: */}}{{- /*service.labels.standard prints the standard service Helm labels.The standard labels are frequently used in metadata.*/ -}}{{- define "service.image" -}}{{- printf "%s:%s" .Values.image.repository (default (.Chart.Version) .Values.image.tag) -}}{{- end -}}{{- define "service.microservice.labels" -}}choerodon.io/version: {{ default (.Chart.Version) .Values.image.tag }}choerodon.io/service: {{ .Chart.Name | quote }}choerodon.io/metrics-port: {{ .Values.deployment.managementPort | quote }}{{- end -}}{{- define "service.labels.standard" -}}choerodon.io/release: {{ .Release.Name | quote }}{{- end -}}{{- define "service.match.labels" -}}choerodon.io/release: {{ .Release.Name | quote }}{{- end -}}{{- define "service.logging.deployment.label" -}}choerodon.io/logs-parser: {{ .Values.logs.parser | quote }}{{- end -}}{{- define "service.monitoring.pod.annotations" -}}choerodon.io/metrics-group: {{ .Values.metrics.group | quote }}choerodon.io/metrics-path: {{ .Values.metrics.path | quote }}{{- end -}}{{/*Return the appropriate apiVersion for deployment.*/}}{{- define "app.deployment.apiVersion" -}}{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}{{- print "apps/v1beta2" -}}{{- else -}}{{- print "apps/v1" -}}{{- end -}}{{- end -}}{{/*Return the appropriate apiVersion for statefulset.*/}}{{- define "app.statefulset.apiVersion" -}}{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}{{- print "apps/v1beta2" -}}{{- else -}}{{- print "apps/v1" -}}{{- end -}}{{- end -}}{{/*Return the appropriate apiVersion for ingress.*/}}{{- define "app.ingress.apiVersion" -}}{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}{{- print "extensions/v1beta1" -}}{{- else -}}{{- print "networking.k8s.io/v1beta1" -}}{{- end -}}{{- end -}}
  • charts/hzero-platform/templates/deployment.yaml

26~28行定义读取CMCM的名称来自于values.yaml

apiVersion: {{ include "app.deployment.apiVersion" . }}kind: Deploymentmetadata:  name: {{ .Release.Name }}  labels:{{ include "service.labels.standard" . | indent 4 }}{{ include "service.logging.deployment.label" . | indent 4 }}spec:  replicas: {{ .Values.replicaCount }}  selector:    matchLabels:{{ include "service.labels.standard" . | indent 6 }}  template:    metadata:      labels:{{ include "service.labels.standard" . | indent 8 }}{{ include "service.microservice.labels" . | indent 8 }}        SERVICE_CODE: {{ .Chart.Name | quote }}      annotations:{{ include "service.monitoring.pod.annotations" . | indent 8 }}    spec:      containers:        - name: {{ .Release.Name }}          image: "{{ .Values.image.repository }}:{{ .Chart.Version }}"          imagePullPolicy: {{ .Values.image.pullPolicy }}          envFrom:          - configMapRef:              name: {{ .Values.configMap.name }}          env:{{- range $name, $value := .Values.env.open }}{{- if not (empty $value) }}          - name: {{ $name | quote }}            value: {{ $value | quote }}{{- end }}{{- end }}          ports:            - name: http              containerPort: {{ .Values.service.port }}              protocol: TCP          # readinessProbe:          #   httpGet:          #     path: /health          #     port: {{ .Values.deployment.managementPort }}          #     scheme: HTTP          readinessProbe:            exec:              command:              - curl              - localhost:{{ .Values.deployment.managementPort }}/actuator/health            failureThreshold: 3            initialDelaySeconds: 60            periodSeconds: 10            successThreshold: 1            timeoutSeconds: 10          resources:{{ toYaml .Values.resources | indent 12 }}          volumeMounts:          - mountPath: /Charts            name: data{{- if not (empty .Values.persistence.subPath) }}            subPath: {{ .Values.persistence.subPath }}{{- end }}      volumes:      - name: data        {{- if .Values.persistence.enabled }}        persistentVolumeClaim:          claimName: {{ .Values.persistence.existingClaim | default ( .Release.Name ) }}        {{- else }}        emptyDir: {}        {{- end }}
  • charts/hzero-platform/values.yaml

6~7行定义了CM的名称,这里须要和猪齿鱼配置映射的名称匹配。

# Default values for hzero-platform.# This is a YAML-formatted file.# Declare variables to be passed into your templates.replicaCount: 1configMap:  name: hzero-devimage:  repository: registry.choerodon.com.cn/hzero-hzero/hzero-platform  pullPolicy: Alwaysenv:  open:    # 数据库地址    SPRING_DATASOURCE_URL: jdbc:mysql://db.hzero.org:3306/hzero_platform?useUnicode=true&characterEncoding=utf-8&useSSL=false    # Redis DB    SPRING_REDIS_DATABASE: 1metrics:  path: /actuator/prometheus  group: spring-bootlogs:  parser: spring-bootpersistence:  enabled: falseservice:  enabled: false  type: ClusterIP  port: 8100  name: hzero-platformdeployment:  managementPort: 8101resources:  # We usually recommend not to specify default resources and to leave this as a conscious  # choice for the user. This also increases chances charts run on environments with little  # resources,such as Minikube. If you do want to specify resources,uncomment the following  # lines,adjust them as necessary,and remove the curly braces after 'resources:'.  limits:    # cpu: 100m    memory: 1.7Gi  requests:    # cpu: 100m    memory: 1.2Gi

创立部署配置

性能门路:部署 > 利用部署 > 资源 > 创立部署配置

在部署配置抉择对应服务,如果我的项目中有values.yaml文件,这里会主动带出。将环境相干的信息替换实现后保留。

创立利用流水线

性能门路:开发 > 利用流水线

在利用流水线中创立流水线,根本的流程至多须要蕴含构建、公布和部署三个流程,代码查看是可选的局部。

代码查看配置

抉择须要查看的代码分支,查看类型分为两类,SonarMaven用来查看Maven我的项目,SonarScanner用来查看通用我的项目,自定义配置用来配置公有的Sonar服务信息。

构建配置

构建这一步次要执行Maven编译打包和Docker镜像构建,共享目录设置定义是否应用缓存,比方历史拉取的Maven资源等等。

Maven构建这一步,没有非凡须要,个别只须要执行

mvn package -Dmaven.test.skip=true -U -B

Docker构建这一步须要配置一些文件门路,Dockerfile文件门路须要填写文件的相对路径,镜像构建上下文是执行镜像打包命令的目录,个别是构建产物所在的目录,例如Maven默认构建的包所在的目录为target目录,这里填写的是构建产出物的相对路径。

失效“利用流水线”

在上一步创立完利用流水线之后,如下所示:

留神:如果你的指标分支不是master还须要做一些手工解决,须要手工将master分支的.gitlab-ci.yml文件复制或者合并到指标分支

测试自动化部署

实现所有配置之后,在我的项目中提交代码或者间接在利用流水线中抉择全新执行,而后在猪齿鱼的利用流水线中和 Gitlab 的CI/CD > Pipelines中能够看到编译和镜像打包步骤的执行。

在部署节点执行实现之后,在部署 > 利用部署 > 资源中查看相干的服务能够看到实例的替换。

触发器部署

在理论我的项目开发过程中,可能存在局部根底组件我的项目,这些我的项目不会间接部署到服务器,而是须要打包成能够来的JarMaven仓库中,而后再部署依赖了此模块的我的项目,为了解决这类的需要,须要借助Gitlab的触发器来实现。

创立触发器

如果我的项目依赖了其余的模块,须要在模块代码更新之后主动部署,能够在Gitlab中创立触发器。

触发触发器

新建好触发器之后,复制下方提醒中的脚本到被依赖模块我的项目的利用流水线的自定义阶段。

自定义CI配置:

如果须要将以后工程部署到Maven仓库供其余我的项目拉取,在CIMaven构建步骤中抉择自定义仓库配置

而后执行打包命令

mvn clean deploy -Dmaven.test.skip=true -Dmaven.springboot.skip=true -Dmaven.javadoc.skip=true -U -B -s settings.xml

残缺的利用流水线配置如下所示:

对于猪齿鱼

Choerodon 猪齿鱼作为开源多云利用麻利全链路技术平台,是基于开源技术Kubernetes,Istio,knative,Gitlab,Spring Cloud来实现本地和云端环境的集成,实现企业多云/混合云应用环境的一致性。平台通过提供精益麻利、继续交付、容器环境、微服务、DevOps等能力来帮忙组织团队来实现软件的生命周期治理,从而更快、更频繁地交付更稳固的软件。

更多内容

大家能够通过以下社区路径理解Choerodon猪齿鱼文档、最新动静、产品个性:

【Choerodon官网】

https://choerodon.io/zh/

【汉得开放平台】

https://open.hand-china.com/

【汉得凋谢论坛】

https://openforum.hand-china.com/

也可退出Choerodon猪齿鱼官网社区用户交换群,交换猪齿鱼应用心得、Docker、微服务、K8S、麻利治理等相干实践实际心得,群同步更新版本更新等信息,大家能够加群探讨交换。

①-Choerodon猪齿鱼官网交换(已满);

②-Choerodon猪齿鱼官网交换(可加);【微信号发至客服邮箱choerodon@vip.hand-china.com,经营小伙伴拉您入官网交换群】

欢送退出Choerodon猪齿鱼社区,独特为企业数字化服务打造一个凋谢的生态平台。