เทมเพลต Helm เข้ากันไม่ได้กับโครงสร้าง values.yaml

Aug 16 2020

ฉันมีทางเข้า yaml ดังต่อไปนี้:

spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .host }}                 // row 31
      http:
        paths:
        {{- range .paths }}
          - path: {{ . | quote }}
            backend:
              serviceName: {{ $fullName }} servicePort: {{ $svcPort }}
        {{- end }}
  {{- end }}
{{- end }}

และค่าต่อไปนี้เพื่อป้อนเทมเพลตนี้:

  hosts:
    host: "app.example.com"
    paths:
      - "/api"
      - "/oauth"

  tls:
    - secretName: "example-tls"
      hosts:
        - "*.app.example.com"
        - "dev.example.com"

เมื่อฉันเรียกใช้ "helm install" มันล้มเหลวใน:

ข้อผิดพลาด: UPGRADE FAILED: template: templates / ingress.yaml: 31:15: เรียกใช้ "template / ingress.yaml" ที่ <.host>: ไม่สามารถประเมินโฮสต์ฟิลด์ในอินเทอร์เฟซประเภท {}

ดังนั้นสำหรับฉันดูเหมือนว่าโฮสต์จะต้องเป็นรายการไม่ใช่พจนานุกรม (เนื่องจากคำสั่งrange ) ดังนั้นฉันจึงแปลงมัน:

  hosts:
    - host: "app.example.com"
      paths:
        - "/api"
        - "/oauth"

แต่ในกรณีนี้ฉันจะได้รับ:

คำเตือน: ปลายทางสำหรับโฮสต์คือตาราง การละเว้นค่าที่ไม่ใช่ตาราง [map [host: app.example.com paths: [/ api / oauth]]]

และข้อผิดพลาดเดียวกันกับด้านบนนอกจากนี้

จะทำให้มันใช้งานได้อย่างไร?

อัปเดต 1

ค่า:

ingress:
  enabled: true

  rules:
    - host: c1.app.example.com
      paths:
        - /api
        - /oauth
    - host: c2.app.example.com
      paths:
        - /api
        - /oauth
  tls:
    - secretName: "example-tls"
      hosts:
        - "*.app.example.com"
        - "dev.example.com"

แม่แบบ:

{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.rules }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- range .paths }}
          - path: {{ . | quote }}
            backend:
              serviceName: {{ $fullName }} servicePort: {{ $svcPort }}
        {{- end }}
  {{- end }}
{{- end }}

อัปเดต 2

ฉันเข้าใจว่าปัญหาไม่ได้อยู่ในโค้ด แต่อยู่ในบรรทัดคำสั่ง ฉันเลี้ยงด้วยสตริงแทนอาร์เรย์

เทมเพลตหางเสือ ... - ตั้งค่า ingress.hosts.host = c1.app.example.com ...

ฉันจะพยายามหาวิธีระบุค่าหลายค่าและอัปเดตที่นี่

อัปเดต 3

ฉันลบข้อมูลจากค่า:

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

คำตอบ

1 seshadri_c Aug 16 2020 at 15:36

แม่แบบกำลังมองหา.Values.ingress.hostsในขณะที่ค่าที่แสดงของคุณไม่มีingressคำนำหน้า และในขณะที่rangeผู้ประกอบการจะถูกใช้เราควรจะมีรายชื่อของพจนานุกรม

นอกจากนี้ก่อนที่จะทำ a helm installควรเรียกใช้helm templateเพียงเพื่อให้แน่ใจว่าคำจำกัดความ YAML แสดงผลอย่างถูกต้อง

พิจารณาเนื้อหาด้านล่างในvalues.yaml:

--- 
ingress: 
  hosts: 
    - 
      host: app1.example.com
      paths: 
        - /api
        - /oauth
    - 
      host: app2.example.com
      paths: 
        - /api1
        - /authz
  tls:
    - hosts:
      - "*.app.example.com"
      - "dev.example.com"
      secretName: "example-tls"

helm templateคำสั่งที่รันผลลัพธ์ใน (ฉันได้กำหนดserviceNameเป็น haproxy และservicePortเป็น 8080 สำหรับภาพประกอบ):

spec:
  tls:
    - hosts:
        - "*.app.example.com"
        - "dev.example.com"
      secretName: example-tls
  rules:
    - host: app1.example.com                 // row 31
      http:
        paths:
          - path: "/api"
            backend:
              serviceName: haproxy
              servicePort: 8080
          - path: "/oauth"
            backend:
              serviceName: haproxy
              servicePort: 8080
    - host: app2.example.com                 // row 31
      # similar output for app2.example.com

1 MichaelA. Aug 27 2020 at 00:13

ตอบคำถามของตัวเอง

ปัญหาคือโครงสร้างเทมเพลตขาเข้าและอาร์กิวเมนต์บรรทัดคำสั่งที่ฉันระบุไว้สำหรับการแทนที่พารามิเตอร์ไม่ตรงกัน

นี่คือความพอดีที่เหมาะสมของอาร์กิวเมนต์บรรทัดคำสั่ง :

helm upgrade <some other options here>
--values ./values.yaml
--set ingress.enabled=True
--set ingress.tls[0].hosts[0]=app.example.com
--set ingress.tls[0].secretName=example-tls
--set ingress.rules[0].host=app.example.com

ที่เติมค่าyaml :

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

สำหรับเทมเพลตขาเข้า:

spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - secretName: {{ .secretName }}
      hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.rules }}
    - host: {{ .host | quote }}
      http:
        paths:
        - path: /api
          backend:
            serviceName: {{ $fullName }} servicePort: {{ $svcPort }}
  {{- end }}
{{- end }}