Jenkins X per environment values.yaml

duf*_*ffn 4 jenkins kubernetes-helm jenkins-x

I am using Jenkins X and attempting to set different variables via values.yaml files based upon the environment that I am promoting to. For example, when promoting a release from staging to production, I would like the values.yaml file in my environment-xxxx-production repository to override values in my project repository.

According to https://github.com/jenkins-x/jx/issues/1667#issuecomment-420901836 this comment, this should work simply by placing variables in the environment-xxxx-production repository.

Sample deployment.yaml file inside of my project.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "fullname" . }}
  labels:
    draft: {{ default "draft-app" .Values.draft }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        draft: {{ default "draft-app" .Values.draft }}
        app: {{ template "fullname" . }}
{{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.service.internalPort }}
{{/*
Here's the section in question.
*/}}
{{- if .Values.env }}
        env:
{{- if .Values.prBranch }}
          - name: MY_ENV
            value: "some_value"
{{- else }}
{{ toYaml .Values.env | indent 10 }}
{{- end }}
{{- end }}
        livenessProbe:
          httpGet:
            path: {{ .Values.probePath }}
            port: {{ .Values.service.internalPort }}
          initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
          successThreshold: {{ .Values.livenessProbe.successThreshold }}
          timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
        readinessProbe:
          httpGet:
            path: {{ .Values.probePath }}
            port: {{ .Values.service.internalPort }}
          periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
          successThreshold: {{ .Values.readinessProbe.successThreshold }}
          timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
        resources:
{{ toYaml .Values.resources | indent 12 }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
Run Code Online (Sandbox Code Playgroud)

Sample project values.yaml contains this:

env:
  - name: MY_ENV
    value: "some_staging_value"
Run Code Online (Sandbox Code Playgroud)

Sample environment-xxxx-production values.yaml contains this:

env:
- name: MY_ENV
  value: some_production_value
Run Code Online (Sandbox Code Playgroud)

我当然可以使预览和暂存环境变量正常工作。但是,当我将应用程序升级到生产环境时,中的env 列表environment-xxxx-production不会覆盖项目本身内部文件中的env 列表values.yaml

Jam*_*han 5

生产values.yaml文件中的密钥必须是您在requirements.yaml-多数民众赞成如何组成图表的图表名称。

因此,如果您的应用被调用cheese,请requirements.yaml尝试在values.yaml

cheese:
  env:
  - name: MY_ENV
    value: some_production_value
Run Code Online (Sandbox Code Playgroud)