At the end of my last post I created a docker image for Jenkins that extended the official docker image by disabling the setup wizard, installing the default plugins and installing maven. I skipped over:
setting up ssh for GitHub.
automating the configuration of the Jenkins job(s).
creating appropriate Jenkins slave images.
In this post I’ll describe how to set up SSH for GitHub.
Setting Up SSH for GitHub
To set up SSH for GitHub I created a ConfigMap containing the ssh config. I did this by creating the ConfigMap from a file.
The SSH config specifies the identity to use as ~/.ssh/id_jenkins_rsa. As the private key is something I want to secure, I will generate the key and store it as a Kubernetes secret. First, follow the instructions on GitHub to generate a new ssh key and add it to your Github account. Then you can store the private and public key as a Kubernetes secret.
Now that we have made the SSH config and keys available to Kubernetes we need to configure the Jenkins container. I’ve done this using the Kubernetes Init Container feature which is in beta as of version 1.5.
I have defined 3 volumes as part of the deployment. The first populates the volume with the contents of the jenkins-ssh-config ConfigMap, the second with the contents of the jenkins-ssh-key Secret and the third is the Jenkins home directory.
I have also defined an Init Container that:
mounts all 3 volumes.
copies the contents of jenkins-ssh-config to /var/jenkins_home/.ssh
copies the contents of jenkins-ssh-key to /var/jenkins_home/.ssh
changes the permissions of the Jenkins ssh keys to those allowed by the git client.
generates the ssh known_hosts file.
One thing of note (and this may be related to minikube itself) but the volumes may or may not be mounted at the start of the command so I needed to insert a statement tat waits until the jenkins-ssh-config and jenkins-ssh-key volumes are mounted before executing the remainder of the script.