简体   繁体   中英

Global variable not affecting values.yaml file in helm chart of Kubernetes (passing secretName and Domain Name from CLI)

I need one help over here. I am stuck while implementing helm chart. Scenario: I need to pass value via CLI to values.yaml file. Below is the sample code.

values.yaml

# Default values for miqp-ui-dep.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
##################Names of files and Applications################
Depname: miqp-server-dep
Appname: miqp-server
Svcname: miqp-server-svc
Ingname: miqp-ing
#################################################################
replicaCount: 2
strategy:
  type: RollingUpdate
  rollingUpdate:
     maxSurge: 1
     maxUnavailable: 1
minReadySeconds: 5
nodeSelector:
       role: nginxplus
image:
  repository: xxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/miqp-devops
  tag: miqpserver_2sep
  pullPolicy: IfNotPresent
service:
  name: miqp-ui-svc
  externalPort: 80
  internalPort: 8081
volumeMounts:
  name: ebs-pvc
ingress:
  enabled: true
  hosts:
    - kubernetes-miq.xxxxxx.com
  tls:
    - secretName: default-token-k33w6
      hosts:
        - kubernetes-xxxxxx.com
persistence:
  enabled: true
  volume:
    accessModes: ReadWriteOnce
    pvcName: ebs-pvc
    storageClass: standard
    storageSize: 20G

ingress.yaml

{{- if .Values.ingress.enabled -}}
{{- $serviceName := .Values.service.name -}}
{{- $servicePort := .Values.service.externalPort -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ .Values.Ingname }}
  namespace: {{ .Release.Namespace }}
spec:
  rules:
    {{- range $host := .Values.ingress.hosts }}
    - host: {{ $host }}
      http:
        paths:
          - path:
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
          - path: /api/
            backend:
              serviceName: {{ $serviceName }}
              servicePort: {{ $servicePort }}
     {{- end -}}
  {{- if .Values.ingress.tls}}
  tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
  {{- end -}}
{{- end -}}

Now I can set the values of the parameter of values.yml using --set option, but what if we have to replace the parameter if it's in below manner?

ingress:
  enabled: true
  hosts:
    - kubernetes-miq.xxxxxx.com
  tls:
    - secretName: default-token-k33w6
      hosts:
        - kubernetes-miq.xxxxxx.com

I have to replace the value of - secretName value ie default-token-k33w6 and hosts ie kubernetes-miq.xxxxxx.com

Thanks in Advance.

You can always do something like helm upgrade --reuse-values --set ingress.enabled=false , for a more complex one you can do helm upgrade --reuse-values -f <filename> where your file under contains something like your example :

ingress:
  enabled: true
  hosts:
  - kubernetes-miq.xxxxxx.com

as for running more complex structures via --set take a look at https://github.com/kubernetes/helm/blob/master/docs/using_helm.md#the-format-and-limitations-of---set which refers to ways like :

--set key={a,b,c}

or

--set name.key1=a,name.key2=b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM