diff --git a/README.md b/README.md index 98d4c4053e..4ae67b6dfc 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ see the [Docker image source code](https://github.com/carlossg/jenkins-slave-doc Create a cluster ``` - gcloud beta container clusters create jenkins --num-nodes 1 --machine-type g1-small + gcloud container clusters create jenkins --num-nodes 1 --machine-type g1-small ``` and note the admin password and server certitifate. Or use Google Developer Console to create a Container Engine cluster, then run ``` - gcloud beta container get-credentials + gcloud container clusters get-credentials kubectl config view --raw ``` the last command will output kubernetes cluster configuration including API server URL, admin password and root certificate @@ -73,32 +73,52 @@ More info Assuming you created a Kubernetes cluster named `jenkins` this is how to run both Jenkins and slaves there. -Create a GCE disk named `kubernetes-jenkins` to store the data, and format it as ext4. -Formatting is not needed in new versions of Kubernetes. +Create a GCE disk named `kubernetes-jenkins` to store the data. -Creating the pods and services + gcloud compute disks create --size 20GB kubernetes-jenkins - gcloud preview container pods create --config-file ./src/main/kubernetes/pod.yml - gcloud preview container services create --config-file ./src/main/kubernetes/service-http.yml - gcloud preview container services create --config-file ./src/main/kubernetes/service-slave.yml +Creating the pods and services -Open the firewall to the Jenkins master running in a pod + kubectl create -f ./src/main/kubernetes/pod.yml + kubectl create -f ./src/main/kubernetes/service.yml + +Connect to the ip of the network load balancer created by Kubernetes, port 80. +Get the ip (in this case `104.197.19.100`) with `kubectl describe services/jenkins` +(it may take a bit to populate) + + $ kubectl describe services/jenkins + Name: jenkins + Namespace: default + Labels: + Selector: name=jenkins + Type: LoadBalancer + IP: 10.175.244.232 + LoadBalancer Ingress: 104.197.19.100 + Port: http 80/TCP + NodePort: http 30080/TCP + Endpoints: 10.172.1.5:8080 + Port: slave 50000/TCP + NodePort: slave 32081/TCP + Endpoints: 10.172.1.5:50000 + Session Affinity: None + No events. - gcloud compute firewall-rules create jenkins-node-master --allow=tcp:8888 --target-tags k8s-jenkins-node +Configure Jenkins, adding the `Kubernetes` cloud under configuration, setting +Kubernetes URL to the container engine cluster endpoint or simply `https://kubernetes.default.svc.cluster.local`. +Under credentials, click `Add` and select `Kubernetes Service Account`, +or alternatively use the Kubernetes API username and password. -Connect to the ip of the network load balancer created by Kubernetes, port 8888. Get the ip with +![image](credentials.png) - gcloud compute forwarding-rules describe jenkins +You may want to set `Jenkins URL` to the internal service IP, `http://10.175.244.232` in this case, +to connect through the internal network. -Configure Jenkins, adding the `Kubernetes` cloud under configuration, setting -Kubernetes URL to the container engine cluster endpoint, and the correct username and password. -Set Container Cap to a reasonable number for tests, i.e. 3. +Set `Container Cap` to a reasonable number for tests, i.e. 3. Add an image with -* ID: `csanchez/jenkins-slave` -* Remote filesystem root: `/home/jenkins` -* Remote FS Root Mapping: `/home/jenkins` +* Docker image: `jenkinsci/jnlp-slave` +* Jenkins slave root directory: `/home/jenkins` ![image](configuration.png) @@ -106,9 +126,8 @@ Now it is ready to be used. Tearing it down - gcloud preview container pods delete jenkins - gcloud preview container services delete jenkins - gcloud preview container services delete jenkins-slave + kubectl delete pods/jenkins + kubectl delete services/jenkins diff --git a/credentials.png b/credentials.png new file mode 100644 index 0000000000..3107b4e48d Binary files /dev/null and b/credentials.png differ diff --git a/src/main/kubernetes/pod.yml b/src/main/kubernetes/pod.yml index d85df3ae52..cc5b1510c2 100644 --- a/src/main/kubernetes/pod.yml +++ b/src/main/kubernetes/pod.yml @@ -9,14 +9,12 @@ containers: - name: "jenkins" - image: "csanchez/jenkins-kubernetes" + image: "csanchez/jenkins-kubernetes:latest" ports: - containerPort: 8080 - hostPort: 8080 - containerPort: 50000 - hostPort: 50000 volumeMounts: - name: "jenkins-data" @@ -24,11 +22,6 @@ volumes: - name: "jenkins-data" - # hostPath: - # path: "/home/docker/jenkins" gcePersistentDisk: pdName: kubernetes-jenkins fsType: ext4 - # awsElasticBlockStore: - # volumeID: aws:/// - # fsType: ext4 diff --git a/src/main/kubernetes/service-slave.yml b/src/main/kubernetes/service-slave.yml deleted file mode 100644 index f25209339e..0000000000 --- a/src/main/kubernetes/service-slave.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- - apiVersion: "v1" - kind: "Service" - metadata: - name: "jenkins-slave" - spec: - type: "NodePort" - selector: - name: "jenkins" - ports: - - - name: "http" - port: 50000 - nodePort: 50000 - protocol: "TCP" diff --git a/src/main/kubernetes/service-http.yml b/src/main/kubernetes/service.yml similarity index 56% rename from src/main/kubernetes/service-http.yml rename to src/main/kubernetes/service.yml index d24657cc99..777a6efda1 100644 --- a/src/main/kubernetes/service-http.yml +++ b/src/main/kubernetes/service.yml @@ -4,12 +4,16 @@ metadata: name: "jenkins" spec: - type: "NodePort" + type: "LoadBalancer" selector: name: "jenkins" ports: - name: "http" - port: 8080 - nodePort: 8888 + port: 80 + targetPort: 8080 + protocol: "TCP" + - + name: "slave" + port: 50000 protocol: "TCP"