Clone a secure git repo in Kubernetes pod Clone a secure git repo in Kubernetes pod docker docker

Clone a secure git repo in Kubernetes pod


Try to mount your secret containing your deploy key like this:

volumeMounts:  - mountPath: /root/.ssh    name: ssh-keyvolumes:- name: ssh-key  secret:    secretName: ssh-key    defaultMode: 256

Here is the full example of how I'm using it:

apiVersion: batch/v2alpha1kind: ScheduledJobmetadata:  name: transporterspec:  schedule: 0 5 * * *  jobTemplate:    spec:      template:        spec:          nodeSelector:            role: mysqldump          containers:          - name: transporter            image: camil/mysqldump            command: ["/bin/bash", "-c"]            args:              - ssh-keyscan -t rsa $TARGET_HOST > ~/.ssh/known_hosts && ssh -i /root/.ssh/private/id_rsa $LINUX_USER@$TARGET_HOST 'mkdir mysqldump || true' && scp -i /root/.ssh/private/id_rsa /mysqldump/* $LINUX_USER@$TARGET_HOST:/home/$LINUX_USER/mysqldump            env:              - name: TARGET_HOST                valueFrom:                  configMapKeyRef:                    name: transporter                    key: target.host              - name: LINUX_USER                valueFrom:                  configMapKeyRef:                    name: transporter                    key: linux.user            imagePullPolicy: Always            volumeMounts:              - mountPath: /mysqldump                name: mysqldump              - mountPath: /root/.ssh/private                name: ssh-key          volumes:            - name: mysqldump              hostPath:                path: /home/core/mysqldump            - name: ssh-key              secret:                secretName: ssh-key                defaultMode: 256          restartPolicy: OnFailure