<p>i'm a newbie to k8s. I have a homework and this is my situation:<br>
There is an app with microservice-oriented, build with amount ten containers. It had a <code>docker-compose</code> file for easily set up. Now my mission is deploy it into Kubernetes. My idea: convert <code>docker-compose</code> file to k8s manifest with <code>kompose</code>, and create helm chart for each services.<br>
My question is: I have to modify each chart one-by-one, isn't it? Is there any way to generate <code>values.yaml</code> base on existing k8s manifest? example, from this: <br></p>
<pre><code># deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: bookstore-account-service
  name: bookstore-account-service
...
</code></pre>
<p>to this, automatically:</p>
<pre><code># deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: {{ .Values.cmd }}
    kompose.version: {{ .Values.ver }}
  creationTimestamp: null
  labels:
    io.kompose.service: {{ .Values.name }}
  name: {{ .Values.name }}
...
</code></pre>
<pre><code># values.yaml
cmd: kompose convert
ver: 1.22.0 (955b78124)
name: bookstore-account-service
</code></pre>
<p>p/s: sorry for my bad English, it's not my first language :D</p>

manhtr76
<p>The Helm <code>values.yaml</code> file is the main point where you can configure the chart at deployment time.  On the one hand, you can't configure anything that's not referenced in <code>.Values</code>; on the other hand, you usually don't want every individual line of the YAML file to be configurable.</p>
<p>If I was going to approach this, I'd start by <a href="https://docs.helm.sh/docs/helm/helm_create/" rel="nofollow noreferrer"><code>helm create</code></a> a new chart.  I'd then switch to the <code>templates</code> directory, move aside most of the boilerplate there (but leave the generated <code>_helpers.tpl</code> file), and run <a href="https://kompose.io/user-guide/#kompose-convert" rel="nofollow noreferrer"><code>kompose convert</code></a>.  This will generate a set of YAML files, though with no Helm templating.</p>
<p>From here I'd edit the files to make them match typical Helm usage.  Look at the original files from <code>helm create</code> (or <a href="https://github.com/helm/helm/blob/main/pkg/chartutil/create.go" rel="nofollow noreferrer">in the Helm source</a>) for examples.  I would expect the edited <code>deployment.yaml</code> to look like:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  {{-/* delete the Kompose annotations: and empty creationTimestamp: */}}
  labels:
    {{-/* get a standard set of labels from _helpers.tpl }}
    {{- include &quot;bookstore.labels&quot; . | nindent 4 }}
  {{-/* get a standard name from _helpers.tpl }}
  name: {{ include &quot;bookstore.fullname&quot; . }}
</code></pre>
<p>What should go in the <code>values.yaml</code> file, then?  These are things you'd need to configure <em>at deploy time</em>.  If you need to override the container <code>command:</code> or <code>args:</code>, these would usually be fixed, but if you needed to supply some sort of credentials or host name, those could vary per-deployment.  (If you <code>helm install</code>ed the chart twice, what would be <em>different</em> between the installs?)  The <code>helm create</code> template makes resource limits configurable, since these can vary heavily based on the actual workload:</p>
<pre class="lang-yaml prettyprint-override"><code># deployment.yaml (from helm/create.go linked above)
resources:
  {{- toYaml .Values.resources | nindent 12 }}
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># values.yaml (also from helm/create.go)
resources: {}
</code></pre>
<p>You could deploy this with a specific set of values here:</p>
<pre class="lang-yaml prettyprint-override"><code># values.dev.yaml
resources:
  requests:
    memory: 256Mi
  limits:
    memory: 1Gi
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># values.prod.yaml
resources:
  requests:
    memory: 2Gi
  limits:
    memory: 4Gi
</code></pre>
<pre class="lang-sh prettyprint-override"><code>helm install bookstore . -f values.dev.yaml
</code></pre>
<p>If you had preserved, for example, the &quot;what version of Kompose generated this file&quot; annotation, there'd be no reason to change that between environments, and so you could just leave that as a fixed string.</p>
