Search code examples
kubernetescontainerskubernetes-helm

Pod getting restarted many times when using sidecar container


I'm deploying a sidecar container in a kubernetes deployment.

The issue is that the pod sometimes is getting restarted many times because the main container (container1) is not ready at all.

The deployment is similar to this one but the sidecar container cannot reach propertly the container1 when this one is not ready. I think that's the reason why the pod is getting restarted many times

apiVersion: v1
kind: Pod
metadata:
  name: webserver
spec:
  volumes:
    - name: shared-logs
      emptyDir: {}

  containers:
    - name: container1
      image: image1
      volumeMounts:
        - name: shared-logs
          mountPath: /var/log/nginx

    - name: sidecar-container
      image: busybox
      command: ["sh","-c","while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done"]
      volumeMounts:
        - name: shared-logs
          mountPath: /var/log/nginx

My question is simple. Is there any way to make busy-box container to wait for container1 until is ready?


Solution

  • In my case, to resolve it faster I have just included a sleep before executing the code so I can give enought time to the main container to be ready.

    time.Sleep(8 * time.Second)
    

    That's not the best solution but resolves the issue.