<p>this might sound like a very silly question for K8's experts. But I have been struggling with this for a while, thus the question below.</p>
<p>I'm trying to deploy locally a simple Kubernetes application through Minikube and docker to test the sidecar container pattern.</p>
<p>Let's start with the sidecar container elements:</p>
<p><strong>Dockerfile</strong></p>
<pre><code>FROM python:3.6-alpine

RUN pip install boto3==1.14.20
RUN pip install --upgrade awscli s3cmd
   
ENV APP_HOME_DIR=/home/sidecar
RUN mkdir $APP_HOME_DIR

ADD run.sh $APP_HOME_DIR
ADD s3_sync.py $APP_HOME_DIR
RUN chmod +x $APP_HOME_DIR/s3_sync.py
RUN chmod +x $APP_HOME_DIR/run.sh

ENV BUCKET_NAME=
ENV PROJECT_NAME=
ENV FEATURE_BRANCH=
ENV LOCAL_DIR=

WORKDIR $APP_HOME_DIR


ENTRYPOINT [&quot;./run.sh&quot;]
</code></pre>
<p><strong>run.sh</strong></p>
<pre><code>#!/bin/sh

while true
do
    echo &quot;Triggering an S3-SYNC&quot;
    python /home/sidecar/s3_sync.py -b $BUCKET_NAME -p $PROJECT_NAME -f $FEATURE_BRANCH -l $LOCAL_DIR
    sleep 10
done
</code></pre>
<p>And a simplified version of the python file <strong>s3_sync.py</strong>:</p>
<pre><code>import logging
import argparse

logging.basicConfig(
    level=logging.INFO,
    format=&quot;%(asctime)s [%(levelname)s] %(message)s&quot;,
    handlers=[logging.FileHandler(&quot;debug.log&quot;), logging.StreamHandler()],
)

logger = logging.getLogger(__name__)

MASTER = &quot;master&quot;

def main():

    bucket_name = args.bucket_name
    project_name = args.project_name
    branch = args.feature_branch
    local_dir = args.local_dir
    sync_type = &quot;production&quot; if branch == MASTER else &quot;review&quot;

    logger.info(f&quot;S3-SYNC starting for {sync_type} environment&quot;)



if __name__ == &quot;__main__&quot;:
    parser = argparse.ArgumentParser()
    parser.add_argument(&quot;-b&quot;, &quot;--bucket_name&quot;, help=&quot;s3 bucket name&quot;, required=True)
    parser.add_argument(&quot;-p&quot;, &quot;--project_name&quot;, help=&quot;project name to sync&quot;, default=&quot;&quot;)
    parser.add_argument(&quot;-f&quot;, &quot;--feature_branch&quot;, help=&quot;git feature branch name&quot;, default=&quot;master&quot;)
    parser.add_argument(&quot;-l&quot;, &quot;--local_dir&quot;, help=&quot;local dir where to sync the s3 objects&quot;, required=True)

    args = parser.parse_args()
    main()
</code></pre>
<p>If I build the above and run it through:</p>
<pre><code>docker build -t sidecar_python .
docker run -e BUCKET_NAME=MYBUCKET -e PROJECT_NAME=MYPROJECT -e FEATURE_BRANCH=MYBRANCH -e LOCAL_DIR=/home sidecar_python
</code></pre>
<p>things run smoothly.</p>
<p>I then combine the sidecar in the Kubernetes deployment yaml file with another local Docker image:</p>
<p><strong>k8_deployment.yml</strong></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: mc1
spec:
  volumes:
    - name: dags
      emptyDir: {}
  containers:
    - name: readdag
      image: dag_reader
      imagePullPolicy: Never
      volumeMounts:
        - name: dags
          mountPath: /usr
    - name: sidecar
      image: sidecar_python:latest
      imagePullPolicy: Never
      env:
        - name: BUCKET_NAME
          value: &quot;MYBUCKET&quot;
        - name: PROJECT_NAME
          value: &quot;MYPROJECT&quot;
        - name: FEATURE_BRANCH
          value: &quot;MYBRANCH&quot;
        - name: LOCAL_DIR
          value: &quot;/usr&quot;
      volumeMounts:
        - name: dags
          mountPath: /usr
</code></pre>
<p>The dag_reader image is another local image, to keep things short I won't post its Dockerfile as it's very simple and outside the scope of my question.</p>
<p>Then I run the usual: <code>minikube start</code>, <code>eval $(minikube docker-env)</code>, <code>docker build..</code> of the 2 images and in the end <code>kubectl apply -f k8_deployment.yml</code>.</p>
<p>If I execute:</p>
<pre><code>kubectl get po
NAME   READY   STATUS    RESTARTS   AGE
mc1    2/2     Running   0          2m7s
</code></pre>
<p>things seem to look good.</p>
<p>But then if I check the logs of sidecar container:</p>
<pre><code>kubectl logs -f mc1 sidecar

Triggering an S3-SYNC
./run.sh: line 6: python: not found
</code></pre>
<p>So python is not found, I can't find the reason why the container running in the pod can't find python, but the container running standalone in docker can.</p>
<p>The same error is thrown for the other container running in the pod: also that one has a python alpine image.</p>
<p>Can anyone explain why? Am I doing something wrong here?</p>
<p>Thanks,
Alessio</p>

AlessioG
<p>The <code>/usr</code> directory contains a variety of system and application software.  In particular, the Python binary is typically in <code>/usr/bin/python3</code> on a Linux system (or container).</p>
<p>Your Kubernetes YAML mounts an <code>emptyDir</code> volume over <code>/usr</code>.  That hides everything that was in that directory tree, including the Python binary and all of the Python system libraries.  That leads to this error.</p>
<p>Mounting the volume somewhere else would avoid this problem.  Containerized applications tend to not be overly picky about &quot;standard&quot; FHS paths, so I might set instead</p>
<pre class="lang-yaml prettyprint-override"><code>  env:
    - name: LOCAL_DIR
      value: &quot;/dags&quot;
  volumeMounts:
    - name: dags
      mountPath: /dags
</code></pre>
