<p>I am trying to use <a href="https://github.com/kubernetes/git-sync" rel="nofollow noreferrer">git-sync</a> image as a side car in kubernetes that runs git-pull periodically  and mounts cloned data to shared volume.</p>
<p>Everything is working fine when I configure it for sync one time. I want to run it periodically like every 10 mins. Somehow when I configure it to run periodically pod initializing is failing.</p>
<p>I read documentation but couldn't find proper answer. Would be nice if you help me to figure out what I am missing in my configuration.</p>
<p>Here is my configuration that failing.</p>
<p><strong>Deployment</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx-helloworld
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: www-data
      initContainers:
        - name: git-sync
          image: k8s.gcr.io/git-sync:v3.1.3
          volumeMounts:
            - name: www-data
              mountPath: /data
          env:
            - name: GIT_SYNC_REPO
              value: "https://github.com/musaalp/design-patterns.git" ##repo-path-you-want-to-clone
            - name: GIT_SYNC_BRANCH
              value: "master" ##repo-branch
            - name: GIT_SYNC_ROOT
              value: /data
            - name: GIT_SYNC_DEST
              value: "hello" ##path-where-you-want-to-clone
            - name: GIT_SYNC_PERIOD
              value: "10"
            - name: GIT_SYNC_ONE_TIME
              value: "false"
          securityContext:
            runAsUser: 0
      volumes:
        - name: www-data
          emptyDir: {}</code></pre>
</div>
</div>
</p>
<p><strong>Pod</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx-helloworld
  name: nginx-helloworld
spec:
  containers:
  - image: nginx
    name: nginx-helloworld
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}</code></pre>
</div>
</div>
</p>

Musa
<p>you are using the <code>git-sync</code> as an <code>initContainers</code>, which run only during init (once in lifecycle)</p>
<blockquote>
<p>A Pod can have multiple containers running apps within it, but it can also have one or more init containers, which are run before the app containers are started.</p>
<p>Init containers are exactly like regular containers, except:</p>
<ul>
<li>Init containers always <strong>run to completion</strong>.</li>
<li>Each init container must complete successfully before the next one starts.
<a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init-containers</a></li>
</ul>
</blockquote>
<p>So use this as a regular container</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: git-sync
          image: k8s.gcr.io/git-sync:v3.1.3
          volumeMounts:
            - name: www-data
              mountPath: /data
          env:
            - name: GIT_SYNC_REPO
              value: &quot;https://github.com/musaalp/design-patterns.git&quot; ##repo-path-you-want-to-clone
            - name: GIT_SYNC_BRANCH
              value: &quot;master&quot; ##repo-branch
            - name: GIT_SYNC_ROOT
              value: /data
            - name: GIT_SYNC_DEST
              value: &quot;hello&quot; ##path-where-you-want-to-clone
            - name: GIT_SYNC_PERIOD
              value: &quot;20&quot;
            - name: GIT_SYNC_ONE_TIME
              value: &quot;false&quot;
          securityContext:
            runAsUser: 0
        - name: nginx-helloworld
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: &quot;/usr/share/nginx/html&quot;
              name: www-data
      volumes:
        - name: www-data
          emptyDir: {}
</code></pre>
