fatal: Could not read from remote repository
I am using the kubernetes integration guide, I am not using namespaces since gitlab generates its own.
In my repo I have:
- gitlab-ci.yml
- example-app.yml
- example-service.yml
I have created a user on gitlab and assigned them the maintainer of the application repo and also the source code repo. The application repo is where all the deployment files with the gitlab-ci are. The souce code repo just contains an index.php file with some text inside. For the user I created I also generated a private and public ssh key using: ssh-keygen -t rsa -b 2048 -C "username-file" I also tried with some other methods such as ED25519. I added that ssh pub key to their account.
Then in my file I tried with just the private key, and also with it encoded in 64 like: cat username-file | base64 and then pasted here:
example-app.yml:
apiVersion: v1
kind: ReplicationController
metadata:
name: example-app
labels:
example-component: example-app
spec:
replicas: 1
selector:
example-component: example-app
template:
metadata:
labels:
example-component: example-app
spec:
containers:
- name: example-app
image: richarvey/nginx-php-fpm:latest
imagePullPolicy: Always
env:
- name: SSH_KEY
value: 'the-ssh-key-value'
- name: GIT_REPO
value: 'git@gitlab.mydomain.com:project/site-source.git'
- name: GIT_EMAIL
value: 'useremail@userdomain.com'
- name: GIT_NAME
value: 'username'
ports:
- containerPort: 80
I am getting the following issue when it tries to connect to the source repo. Here are the logs of the pod:
base64: truncated base64 input
Cloning into '/var/www/html'...
load pubkey "/root/.ssh/id_rsa": invalid format
Warning: Permanently added 'gitlab.mydomain.com,ip-address-here' (ECDSA) to the list of known hosts.
Load key "/root/.ssh/id_rsa": invalid format
git@gitlab.mydomain.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
my .gitlab-ci.yml:
services:
- docker:18-dind
stages:
- deploy
deploy:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy
environment:
name: staging
url: https://staging.mydomain.com/
script:
- echo ${CI_JOB_NAME}
- kubectl version
- kubectl apply -f example-app.yml
- kubectl apply -f example-service.yml