<p>I am trying to deploy a containerized webapp on Openshift by a helm chart. When I deploy the app I get the following error in the pod logs -</p>
<pre><code>Events:
  Type     Reason          Age                   From               Message

  Normal   Pulled          14m                   kubelet            Successfully pulled image &quot;&lt;private-gitlab-registry-docker-image&gt;:latest&quot; in 3.787555091s
  Warning  Failed          14m                   kubelet            Error: container create failed: time=&quot;2022-11-11T13:51:47Z&quot; level=error msg=&quot;runc create failed: unable to start container process: exec: \&quot;python3 src/myapp.py\&quot;: stat python3 src/myapp.py: no such file or directory&quot;

</code></pre>
<p>Here is the dockerfile -</p>
<pre><code>FROM &lt;private-gitlab-registry-centos-image&gt;

ADD files/etc/yum.repos.d/* /etc/yum.repos.d/

RUN yum update -y

WORKDIR /app

RUN yum install -y python-keystoneclient python3-flask python3-keystoneauth1 python3-redis python3-werkzeug python3-pip python3-keystoneclient
RUN pip install flask-caching

COPY . /app

ENTRYPOINT [ &quot;python3&quot; ]

CMD [ &quot;src/myapp.py&quot; ]
</code></pre>
<p>When I manually try to run this docker image, it works just fine. But when I deploy it on Kubernetes, kubelet throws the above error.</p>
<p>Here is my deployment.yaml -</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment                 # Type of Kubernetes resource
metadata:
  name: myapp             # Unique name of the Kubernetes resource
spec:
  replicas: 1                    # Number of pods to run at any given time
  selector:
    matchLabels:
      app: myapp          # This deployment applies to any Pods matching the specified label
  template:                      # This deployment will create a set of pods using the configurations in this template
    metadata:
      labels:                    # The labels that will be applied to all of the pods in this deployment
        app: myapp 
    spec:
      containers:
      - name: myapp
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.imagePullPolicy }}
          {{- include &quot;myapp.command&quot; . | nindent 8 }}
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
          - containerPort: 8080  # Should match the port number that the Go application listens on    
        env:                     # Environment variables passed to the container
          - name: REDIS_HOST
            value: redis-master
          - name: REDIS_PORT
            value: &quot;6379&quot;  
</code></pre>
<p>And values.yaml -</p>
<pre><code>image:
  repository: gitlab-registry.cern.ch/batch-team/hepspec-query/hepspec-query
  tag: latest
  imagePullSecret: {}
  imagePullPolicy: Always
  command: [ &quot;python3&quot; , &quot;src/hepspecapp.py&quot; ]
  args: {}
</code></pre>

Masquerade
<p>The simplest thing to do here is to remove the part of the Helm chart here that provides <code>command:</code>, and overrides the image's <code>ENTRYPOINT</code>.  The image already knows what command it's supposed to run (if oddly split across two Docker directives) and you don't need to specify it when you run the image.  Similarly, it'd be odd to reconfigure this at deploy time to run some other command without substantially rearchitecting the container setup.</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: myapp
    image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
    imagePullPolicy: {{ .Values.image.imagePullPolicy }}
    # but you don't need to specify command: or make it configurable
</code></pre>
<p>If it's important to you to make this configurable, you're probably running into a syntax problem with the default Go serialization of lists out of templates.  If you run <code>helm template</code> over your chart, it'll probably print something like</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: myapp
    image: gitlab-registry.cern.ch/batch-team/hepspec-query/hepspec-query:latest
    imagePullPolicy: Always
    command: [python3 src/hepspecapp.py]
</code></pre>
<p>That is, <code>.Values.command</code> is a list, and it's parsed and stored internally as a list, and you're getting a default serialization that's not what's in the <code>values.yaml</code> file.  It turns out that <em>is</em> valid YAML, by coincidence, but now it's a list containing a single string that contains an embedded space.</p>
<p>Helm contains a lightly-documented <code>toYaml</code> function that can convert an arbitrary structure back to valid YAML.  This is indented starting at the first column so you need to make sure to appropriately <code>indent</code> the result.</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: myapp
{{- if .Values.command }}
    command:
{{ .Values.command | toYaml | indent 6 }}
{{- end }}
{{- if .Values.args }}
    args:
{{ .Values.args | toYaml | indent 6 }}
{{- end }}
</code></pre>
