Start Docker Machine
-
docker-machine start default
Start Kubernetes on Docker machine VM
-
kid up
Install Jenkins and Docker registry on kubernetes using Helm
-
helmc install jenkinsor-
kubectl create -f jenkins-rc.yamland -
kubectl create -f jenkins-svc.yaml
-
-
helmc install docker-registry
apiVersion: v1
kind: ReplicationController
metadata:
name: jenkins
labels:
app: jenkins
spec:
replicas: 1
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: vineetreynolds/jenkins-host
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkins-data
- mountPath: /var/run/docker.sock
name: docker-socket
volumes:
- name: jenkins-data
hostPath:
path: /Users/vineet/apps/docker_volumes/jenkins
- name: docker-socket
hostPath:
path: /var/run/docker.sock
Recreate vineetreynolds/jenkins-host from https://github.com/VineetReynolds/NoveaBank/blob/step-3/jenkins/jenkins-host/Dockerfile if necessary. Be mindful of jenkinsci/docker#177 where you will need to chown the jenkins-data directory on Docker host to UID 1000.
apiVersion: v1
kind: Service
metadata:
name: jenkins
labels:
app: jenkins
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: jenkins
Expose Jenkins via a NodePort
-
kubectl expose rc jenkins --port=80 --target-port=8080 --type=NodePort --name=jenkins-http
or
-
kubectl create -f jenkins-http-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: jenkins-http
labels:
app: jenkins
spec:
ports:
- port: 80
targetPort: 8080
nodePort: 31080
type: NodePort
selector:
app: jenkins
Install Git, Kubernetes and NodeJS plugins in Jenkins
Register a new cloud provider in Jenkins
-
Name: Kubernetes Local
-
Kubernetes URL: https://kubernetes.default.svc.cluster.local
-
Disable https certificate check: true (check this box)
-
Jenkins URL: http://172.17.0.4:8080 (from 'kubectl describe services/jenkins'), or http://jenkins.default.svc.cluster.local (port 80 because Jenkins service created in Kubernetes is remapped to 80 from 8080)
-
Images
-
Name: Jenkins Slave Pod
-
Labels: jenkins-slave
-
Docker image: vineetreynolds/jenkins-slave (since
jenkinsci/jnlp-slavedoes not have bzip2 required for PhantomJS extraction; rebuild fromhttps://github.com/VineetReynolds/NoveaBank/tree/step-3/jenkins/jenkins-slaveif necessary) -
Add a volume (for accessing Docker outside of Docker, as a service):
-
Host path: /var/run/docker.sock
-
Mount path: /var/run/docker.sock
Save the above config.
Create a new Jenkins job.
-
Restrict where the project is run. Provide a value of 'jenkins-slave' (same as label of Docker image)