<p>I have a single values.yaml file with the following two containers:</p>
<pre><code>...

nginx:
  image:
    repository: _ADDRESS_
    tag: stable
    pullPolicy: IfNotPresent

flask:
  image:
    repository: _ADDRESS_
    tag: stable
    pullPolicy: IfNotPresent

...
</code></pre>
<p>Is it best practice to duplicate the following code manually within the deployment file for each container and just change the variables or is there a more standard way of dealing with this? Feels as if it limits the abstraction so was just curious as to whether I am doing this wrong.</p>
<pre><code>- name: {{ .Chart.Name }}
              securityContext:
                {{- toYaml .Values.securityContext | nindent 12 }}
              image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              ports:
                - name: http
                  containerPort: 80
                  protocol: TCP
              livenessProbe:
                httpGet:
                  path: /
                  port: http
              readinessProbe:
                httpGet:
                  path: /
                  port: http
              resources:
                {{- toYaml .Values.resources | nindent 12 }}
</code></pre>
<p>Thank you for your time. If there are any details I can add to simplify my question, please don't hesitate to mention them and I will edit the post.</p>

<blockquote>
<p>Is it best practice to duplicate the following code manually within the deployment file for each container</p>
</blockquote>
<p>Yes.</p>
<p>In principle it's possible to write a generic Helm template that produces a Deployment YAML specification.  But then you'll run into a problem where the Flask application listens on port 5000 but the Nginx server uses port 80, and the Flask application has a dedicated <code>/health</code> endpoint but the Nginx server should just probe <code>/</code>, and so on, and you'd need to make these differences visible in the <code>values.yaml</code>.  This has two problems: you're exposing fixed details of the application as configuration, and in effect you're republishing the entire Kubernetes YAML structure as Helm values.</p>
<p>For some things that really do get repeated over and over, you could use a helper template; for example</p>
<pre class="lang-yaml prettyprint-override"><code>{{- define &quot;container.common&quot; -}}
securityContext: {{- toYaml .Values.securityContext | nindent 2 }}
image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources: {{- toYaml .Values.resources | nindent 2 }}
{{- end -}}

- name: {{ .Chart.Name }}
{{ include &quot;container.common&quot; . | indent 2 }}
  ports: { ... }
  livenessProbe: { ... }
  readinessProbe: { ... }
</code></pre>
<p>But for details like <code>ports:</code> and the probes, again, these are fixed properties of the image (the Flask application will <em>always</em> listen on port 5000 and the end user will never need to configure it) and it's appropriate to write it in the <code>templates/flask-deployment.yaml</code> file, even if it looks very similar to settings in other files.</p>
