<p>When running a sidecar container along with the main container in my kubernets deployment I'm getting an error with the timeout when mounting the volume.</p>
<p><strong>MountVolume.SetUp failed for volume &quot;initdb&quot; : failed to sync configmap cache: timed out waiting for the condition</strong></p>
<p><strong>kubectl describe pod mypod</strong></p>
<pre><code>.
.
.
  client:
    Container ID:   docker://xx
    Image:          docker.io/golang:xx
    Image ID:       docker-xxx
    Port:           &lt;none&gt;
    Host Port:      &lt;none&gt;
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Tue, 14 Jun 2022 15:44:22 +0200
      Finished:     Tue, 14 Jun 2022 15:44:22 +0200
    Ready:          False
    Restart Count:  3
    Environment:
      env_a:                &lt;set to the key 'env_a' of config map 'unleash'&gt;      Optional: false
      token:  &lt;set to the key 'token' in secret 'mysecrets'&gt;  Optional: false
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from xxx (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  initdb:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      initdb
    Optional:  false
  kube-api-access-rrrsv:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           xxx
    ConfigMapOptional:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              &lt;none&gt;
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason       Age                    From               Message
  ----     ------       ----                   ----               -------
  Normal   Scheduled    6m44s                  default-scheduler  Successfully xxx to minikube
  Warning  FailedMount  6m42s                  kubelet            MountVolume.SetUp failed for volume &quot;initdb&quot; : failed to sync configmap cache: timed out waiting for the condition
  Normal   Pulled       3m23s (x5 over 6m)     kubelet            Container image &quot;xxx/postgres:xx&quot; already present on machine
  Normal   Created      3m21s (x5 over 5m56s)  kubelet            Created container init-db
  Normal   Started      3m14s (x5 over 5m45s)  kubelet            Started container init-db
  Warning  BackOff      3m12s (x9 over 5m1s)   kubelet            Back-off restarting failed container
  Normal   Pulled       94s                    kubelet            Container image &quot;xx/unleash-server:xxx&quot; already present on machine
</code></pre>
<p>This is the deployment file that I'm trying to deploy:</p>
<p>I did not attach all the yaml file as it's working fine except when including the sidecarcontainer.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: mydeployment
  name: mydeployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: mydeployment
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mydeployment
    spec:
      volumes:
        - name: volume-db
          configMap:
            name: volume-db
      initContainers:
        - name: datbase
          image: &quot;myrepo/postgres:xxx&quot;
          env:
            .
            .
            .
            # environment variables to configure the postgres database. Not attached here #
            .
            .
            .
          volumeMounts:
            - mountPath: /etc/postgresql
              name: volume-db
              readOnly: true
      containers:
        - name: maincontainer
          env:
            .
            .
            .
            # environment variables to configure the maincontainer. Not attached here #
            .
            .
            .
          image: &quot;myrepo/maincontainer:xxx&quot;
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          livenessProbe:
            httpGet:
              path: localhost/maincontainer/health
              port: http
            initialDelaySeconds: 20
            timeoutSeconds: 250
          readinessProbe:
            httpGet:
              path: localhost/maincontainer/health
              port: http
            initialDelaySeconds: 20
            timeoutSeconds: 250
            successThreshold: 5
            periodSeconds: 10
        - name: sidecarcontainer
          env:
            .
            .
            .
            #environment variables to configure the sidecar container. Not attached here#
            .
            .
            .
          image: &quot;myrepo/sidecarcontainer:xxx&quot;
          imagePullPolicy: IfNotPresent
</code></pre>
<p>Any idea why is throwing the timeout error when mounting the volume?</p>
<p>Is it something related to the timeout when including the sidecar container and needs to be incresed?</p>
<p>If it's something related on how I'm including the sidecar container a clear example will be appreciated.</p>

X T
<p>I've already fixed the issue.</p>
<p>Since the sidecar container is running a go image it's necessary to run some command so that the pod won´t finished its execution.</p>
<p>Adding these lines at the end of the sidecar container definition in the deployment yaml file fixed the issue:</p>
<pre><code>- name: sidecarcontainer
          env:
            .
            .
            .
            #environment variables to configure the sidecar container. Not attached here#
            .
            .
            .
          image: &quot;myrepo/sidecarcontainer:xxx&quot;
          imagePullPolicy: IfNotPresent
          command: [&quot;bash&quot;]
          args: [&quot;-c&quot;, &quot;while true; do echo hello; sleep 300; done&quot;]
</code></pre>
