<p>I'm running gitsync container in kubernetes and trying to sync the repository from github. I have already created secret using known_hosts and ssh. However I face following error.</p>
<blockquote>
<p>&quot;msg&quot;=&quot;failed to sync repo, aborting&quot; &quot;error&quot;=&quot;error running command: exit status 128: &quot;Cloning into '/tmp/git'...\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n&quot;&quot;</p>
</blockquote>
<p>Here is my deployment file.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitsync-deployment
  labels:
    app: gitsync
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gitsync
  template:
    metadata:
      labels:
        app: gitsync
    spec:
      containers:
      - name: git-sync
        image: k8s.gcr.io/git-sync:v3.1.5
#        command: [&quot;cat&quot;]
#        args: [&quot;/etc/git-secret/ssh&quot;]
        imagePullPolicy: Always
        volumeMounts:
        - name: git-secret
          mountPath: /etc/git-secret
        env:
        - name: GIT_SYNC_REPO
          value: &quot;git@github.com:username/test.git&quot;
        - name: GIT_SYNC_SSH
          value: &quot;true&quot;
        - name: GIT_SYNC_BRANCH
          value: master
        - name: GIT_SYNC_DEST
          value: git
        - name: GIT_SYNC_DEPTH
          value: &quot;1&quot;
      volumes:
      - name: html
        emptyDir: {}
      - name: git-secret
        secret:
          secretName: git-creds
          defaultMode: 256
</code></pre>

<p>Seems that you followed the <a href="https://github.com/kubernetes/git-sync/blob/master/docs/ssh.md" rel="nofollow noreferrer">official documentation</a>.</p>
<p>But it turns out that this documentation does not mention at all where to put the <strong>public key</strong>.</p>
<p>Actually, a git authentication thru SSH requires the following steps :</p>
<p><strong>1. Generate SSH key-pair :</strong></p>
<pre><code>ssh-keygen -t rsa -N &quot;&quot; -f mykey
</code></pre>
<p>This cmd generates 2 files:</p>
<ul>
<li>private key : <code>./mykey</code></li>
<li>public key : <code>./mykey.pub</code></li>
</ul>
<p><strong>2. Put the public key in your Github Account under Settings &gt;  SSH Keys</strong></p>
<p>Copy the content of <code>./mykey.pub</code> and add it in your github account.</p>
<p><strong>3. Put the Private Key in the k8s secret</strong></p>
<p>The official documentation started from here, and it consider <code>$HOME/.ssh/id_rsa</code> as the private  key.</p>
<pre><code>kubectl create secret generic git-creds \
    --from-file=ssh=./mykey \ 
  ....
</code></pre>
<p>the rest should be the same as the official documentation explained.</p>
