Last active
October 10, 2018 22:42
-
-
Save dlstadther/f9cd396d9cf3122dc9f9409b1c22ea4b to your computer and use it in GitHub Desktop.
Sample code and configuration for creating a Stateless Jenkins build server on Kubernetes using the Jenkins Configuration as Code Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
minikube start | |
minikube dashboard | |
# cd to dir with the supporting k8s/docker files | |
cd ~/sample/k8s-jenkins-casc/ | |
eval $(minikube docker-env) | |
docker build -t sample/jenkins:2.143 . | |
kubectl apply -f jenkins.yml | |
# get http address for jenkins | |
echo $(minikube ip):$(kubectl get services/jenkins -o jsonpath='{.spec.ports[0].nodePort}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cd to dir with the supporting k8s/docker files | |
cd ~/sample/k8s-jenkins-casc/ | |
kubectl delete -f jenkins.yml | |
docker rmi sample/jenkins:2.143 | |
minikube stop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jenkins/jenkins:2.143 | |
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt | |
RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: jenkins | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: Role | |
metadata: | |
name: jenkins | |
rules: | |
- apiGroups: [""] | |
resources: ["pods"] | |
verbs: ["create","delete","get","list","patch","update","watch"] | |
- apiGroups: [""] | |
resources: ["pods/exec"] | |
verbs: ["create","delete","get","list","patch","update","watch"] | |
- apiGroups: [""] | |
resources: ["pods/log"] | |
verbs: ["get","list","watch"] | |
- apiGroups: [""] | |
resources: ["secrets"] | |
verbs: ["get"] | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: RoleBinding | |
metadata: | |
name: jenkins | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: Role | |
name: jenkins | |
subjects: | |
- kind: ServiceAccount | |
name: jenkins | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: jenkins-configuration-as-code | |
data: | |
configuration-as-code.yml: | | |
jenkins: | |
systemMessage: "Welcome to Jenkins - configured with code!" | |
mode: EXCLUSIVE | |
numExecutors: 3 | |
tool: | |
git: | |
installations: | |
- home: "git" | |
name: "Default" | |
--- | |
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: jenkins | |
spec: | |
replicas: 1 | |
template: | |
metadata: | |
name: jenkins | |
labels: | |
name: jenkins | |
spec: | |
serviceAccountName: jenkins | |
containers: | |
- name: jenkins | |
image: sample/jenkins:2.143 | |
env: | |
- name: JAVA_OPTS | |
value: -Djenkins.install.runSetupWizard=false -Dhudson.slaves.NodeProvisioner.initialDelay=0 | |
- name: CASC_JENKINS_CONFIG | |
# https://github.com/jenkinsci/configuration-as-code-plugin/issues/425 | |
value: /var/jenkins_config/..data/configuration-as-code.yml | |
ports: | |
- name: http-port | |
containerPort: 8080 | |
- name: jnlp-port | |
containerPort: 50000 | |
volumeMounts: | |
- name: jenkins-home | |
mountPath: /var/jenkins_home | |
- name: jenkins-configuration-as-code | |
mountPath: /var/jenkins_config | |
livenessProbe: | |
httpGet: | |
path: / | |
port: 8080 | |
initialDelaySeconds: 60 | |
timeoutSeconds: 5 | |
readinessProbe: | |
httpGet: | |
path: / | |
port: 8080 | |
initialDelaySeconds: 60 | |
timeoutSeconds: 5 | |
volumes: | |
- name: jenkins-home | |
emptyDir: {} | |
- name: jenkins-configuration-as-code | |
configMap: | |
name: jenkins-configuration-as-code | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: jenkins | |
spec: | |
type: NodePort | |
ports: | |
- port: 8080 | |
targetPort: 8080 | |
nodePort: 30123 | |
protocol: TCP | |
selector: | |
name: jenkins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timestamper:latest | |
command-launcher:latest | |
jdk-tool:latest | |
ssh-slaves:latest | |
kubernetes:latest | |
workflow-aggregator:latest | |
configuration-as-code:latest | |
configuration-as-code-support:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment