<p>I want to prepare the ingress with hosts and their values</p>
<p>Example values file :</p>
<pre><code>hosts:
  test1.test.top: {
    &quot;serviceName&quot;: &quot;httpd-echo&quot;,
    &quot;servicePort&quot;: &quot;5678&quot;
  }
  test2.test.top: {
    &quot;serviceName&quot;: &quot;httpd-echo2&quot;,
    &quot;servicePort&quot;: &quot;5678&quot;
  }
</code></pre>
<p>Tried to apply it on template :</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ include &quot;ingress.fullname&quot; . }}
  {{- with .Values.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  rules:
    {{ range $key, $value := .Values.hosts }}
    - host: {{ $key }}
      http:
        paths:
          - backend:
            {{- with .Values.hosts.$value }}
              {{- toYaml . | nindent 4 }}
            {{- end }}
    {{ end }}
</code></pre>
<p>But have an error :</p>
<blockquote>
<p>Error: parse error at (general-ingress/templates/ingress.yaml:28): bad
character U+0024 '$'</p>
</blockquote>
<p>Kindly aks you to provide example how I can implement it, please</p>

Manish Iarhovich
<p>Is it required to have values defined as json? If yes, you need to declare them as</p>
<pre><code>hosts:
  test1.test.top: |
    {
      &quot;serviceName&quot;: &quot;httpd-echo&quot;,
      &quot;servicePort&quot;: &quot;5678&quot;
    }
  test2.test.top: |
    {
      &quot;serviceName&quot;: &quot;httpd-echo2&quot;,
      &quot;servicePort&quot;: &quot;5678&quot;
    }
  
</code></pre>
<p>If your values.yaml can be like</p>
<pre><code>hosts:
  test1.test.top: 
    serviceName: httpd-echo
    servicePort: 5678
  test2.test.top: 
    serviceName: httpd-echo2
    servicePort: 5678
</code></pre>
<p>One of the options of defining your ingress would be</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ include &quot;ingress.fullname&quot; . }}
  {{- with .Values.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  rules:
  {{- range $key, $value := .Values.hosts }}
  - host: {{ $key }}
    http:
      paths:
        - backend:
          {{- $value | toYaml | nindent 12 }}
  {{- end }}
</code></pre>
