Update docs

This commit is contained in:
Tomasz Sęk 2019-06-18 23:09:48 +02:00
parent 92081e8360
commit cc4b104607
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
3 changed files with 80 additions and 76 deletions

View File

@ -79,9 +79,9 @@ make deepcopy-gen
### Getting Jenkins URL and basic credentials ### Getting Jenkins URL and basic credentials
```bash ```bash
minikube service jenkins-operator-http-example --url minikube service jenkins-operator-http-<cr_name> --url
kubectl get secret jenkins-operator-credentials-example -o 'jsonpath={.data.user}' | base64 -d kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.user}' | base64 -d
kubectl get secret jenkins-operator-credentials-example -o 'jsonpath={.data.password}' | base64 -d kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.password}' | base64 -d
``` ```

View File

@ -26,27 +26,37 @@ metadata:
name: example name: example
spec: spec:
master: master:
image: jenkins/jenkins containers:
readinessProbe: - name: jenkins-master
httpGet: image: jenkins/jenkins:lts
path: /login imagePullPolicy: Always
port: 8080 livenessProbe:
scheme: HTTP failureThreshold: 12
failureThreshold: 12 httpGet:
initialDelaySeconds: 20 path: /login
periodSeconds: 10 port: http
successThreshold: 1 scheme: HTTP
timeoutSeconds: 5 initialDelaySeconds: 80
livenessProbe: periodSeconds: 10
httpGet: successThreshold: 1
path: /login timeoutSeconds: 5
port: 8080 readinessProbe:
scheme: HTTP failureThreshold: 3
initialDelaySeconds: 20 httpGet:
failureThreshold: 12 path: /login
periodSeconds: 10 port: http
successThreshold: 1 scheme: HTTP
timeoutSeconds: 5 initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources:
limits:
cpu: 1500m
memory: 3Gi
requests:
cpu: "1"
memory: 500Mi
seedJobs: seedJobs:
- id: jenkins-operator - id: jenkins-operator
targets: "cicd/jobs/*.jenkins" targets: "cicd/jobs/*.jenkins"
@ -69,22 +79,20 @@ kubectl get pods -w
Get Jenkins credentials: Get Jenkins credentials:
```bash ```bash
kubectl get secret jenkins-operator-credentials-example -o 'jsonpath={.data.user}' | base64 -d kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.user}' | base64 -d
kubectl get secret jenkins-operator-credentials-example -o 'jsonpath={.data.password}' | base64 -d kubectl get secret jenkins-operator-credentials-<cr_name> -o 'jsonpath={.data.password}' | base64 -d
``` ```
Connect to Jenkins (minikube): Connect to Jenkins (minikube):
```bash ```bash
minikube service jenkins-operator-example --url minikube service jenkins-operator-http-<cr_name> --url
``` ```
Pick up the first URL.
Connect to Jenkins (actual Kubernetes cluster): Connect to Jenkins (actual Kubernetes cluster):
```bash ```bash
kubectl describe svc jenkins-operator-example kubectl port-forward jenkins-<cr_name> 8080:8080
kubectl port-forward jenkins-operator-example 8080:8080
``` ```
Then open browser with address http://localhost:8080. Then open browser with address http://localhost:8080.
![jenkins](../assets/jenkins.png) ![jenkins](../assets/jenkins.png)
@ -145,7 +153,11 @@ podTemplate(label: label,
containers: [ containers: [
containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:alpine'), containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:alpine'),
containerTemplate(name: 'go', image: 'golang:1-alpine', command: 'cat', ttyEnabled: true), containerTemplate(name: 'go', image: 'golang:1-alpine', command: 'cat', ttyEnabled: true),
]) { ],
envVars: [
envVar(key: 'GOPATH', value: workspace),
],
) {
node(label) { node(label) {
dir(workdir) { dir(workdir) {
@ -158,6 +170,18 @@ podTemplate(label: label,
} }
} }
stage('Dep') {
container('go') {
sh 'make dep'
}
}
stage('Test') {
container('go') {
sh 'make test'
}
}
stage('Build') { stage('Build') {
container('go') { container('go') {
sh 'make build' sh 'make build'
@ -178,8 +202,6 @@ kind: Jenkins
metadata: metadata:
name: example name: example
spec: spec:
master:
image: jenkins/jenkins:lts
seedJobs: seedJobs:
- id: jenkins-operator - id: jenkins-operator
targets: "cicd/jobs/*.jenkins" targets: "cicd/jobs/*.jenkins"
@ -210,8 +232,6 @@ kind: Jenkins
metadata: metadata:
name: example name: example
spec: spec:
master:
image: jenkins/jenkins:lts
seedJobs: seedJobs:
- id: jenkins-operator-ssh - id: jenkins-operator-ssh
credentialType: basicSSHUserPrivateKey credentialType: basicSSHUserPrivateKey
@ -248,8 +268,6 @@ kind: Jenkins
metadata: metadata:
name: example name: example
spec: spec:
master:
image: jenkins/jenkins:lts
seedJobs: seedJobs:
- id: jenkins-operator-user-pass - id: jenkins-operator-user-pass
credentialType: usernamePassword credentialType: usernamePassword
@ -262,7 +280,10 @@ spec:
and create Kubernetes Secret(name of secret should be the same from `credentialID` field): and create Kubernetes Secret(name of secret should be the same from `credentialID` field):
``` #### Create PVC
Save to file pvc.yaml:
```yaml
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
metadata: metadata:
@ -275,33 +296,28 @@ data:
## Jenkins Customisation ## Jenkins Customisation
Jenkins can be customized using groovy scripts or configuration as code plugin. All custom configuration is stored in Jenkins can be customized using groovy scripts or configuration as code plugin. All custom configuration is stored in
the **jenkins-operator-user-configuration-example** ConfigMap which is automatically created by **jenkins-operator**. the **jenkins-operator-user-configuration-<cr_name>** ConfigMap which is automatically created by **jenkins-operator**.
**jenkins-operator** creates **jenkins-operator-user-configuration-example** secret where user can store sensitive **jenkins-operator** creates **jenkins-operator-user-configuration-<cr_name>** secret where user can store sensitive
information used for custom configuration. If you have entry in secret named `PASSWORD` then you can use it in information used for custom configuration. If you have entry in secret named `PASSWORD` then you can use it in
Configuration as Plugin as `adminAddress: "${PASSWORD}"`. Configuration as Plugin as `adminAddress: "${PASSWORD}"`.
``` ```
kubectl get secret jenkins-operator-user-configuration-example -o yaml kubectl get secret jenkins-operator-user-configuration-<cr_name> -o yaml
kind: Secret
apiVersion: v1 apiVersion: v1
type: Opaque
metadata:
name: jenkins-operator-user-configuration-<cr_name>
namespace: default
data: data:
SECRET_JENKINS_ADMIN_ADDRESS: YXNkZgo= SECRET_JENKINS_ADMIN_ADDRESS: YXNkZgo=
kind: Secret
metadata:
creationTimestamp: 2019-03-03T11:54:36Z
labels:
app: jenkins-operator
jenkins-cr: example
watch: "true"
name: jenkins-operator-user-configuration-example
namespace: default
type: Opaque
``` ```
``` ```
kubectl get configmap jenkins-operator-user-configuration-example -o yaml kubectl get configmap jenkins-operator-user-configuration-<cr_name> -o yaml
apiVersion: v1 apiVersion: v1
data: data:
@ -316,13 +332,12 @@ data:
Jenkins jenkins = Jenkins.getInstance() Jenkins jenkins = Jenkins.getInstance()
def decorator = Jenkins.instance.getDescriptorByType(org.codefirst.SimpleThemeDecorator.class) Run command:
```bash
$ kubectl -n <namesapce> create -f pvc.yaml
```
List<ThemeElement> configElements = new ArrayList<>(); #### Configure Jenkins CR
configElements.add(new CssTextThemeElement("DEFAULT"));
configElements.add(new CssUrlThemeElement("https://cdn.rawgit.com/afonsof/jenkins-material-theme/gh-pages/dist/material-light-green.css"));
decorator.setElements(configElements);
decorator.save();
jenkins.save() jenkins.save()
1-system-message.yaml: |2 1-system-message.yaml: |2
@ -331,22 +346,16 @@ data:
adminAddress: "${SECRET_JENKINS_ADMIN_ADDRESS}" adminAddress: "${SECRET_JENKINS_ADMIN_ADDRESS}"
kind: ConfigMap kind: ConfigMap
metadata: metadata:
labels: name: jenkins-operator-user-configuration-<cr_name>
app: jenkins-operator
jenkins-cr: example
watch: "true"
name: jenkins-operator-user-configuration-example
namespace: default namespace: default
``` ```
When **jenkins-operator-user-configuration-example** ConfigMap is updated Jenkins automatically When **jenkins-operator-user-configuration-<cr_name>** ConfigMap is updated Jenkins automatically
runs the **jenkins-operator-user-configuration** Jenkins Job which executes all scripts then runs the **jenkins-operator-user-configuration** Jenkins Job which executes all scripts then
runs the **jenkins-operator-user-configuration-casc** Jenkins Job which applies Configuration as Code configuration. runs the **jenkins-operator-user-configuration-casc** Jenkins Job which applies Configuration as Code configuration.
## Install Plugins ## Install Plugins
### Via CR
Edit CR under `spec.master.plugins`: Edit CR under `spec.master.plugins`:
``` ```
@ -356,11 +365,9 @@ metadata:
name: example name: example
spec: spec:
master: master:
image: jenkins/jenkins:lts
plugins: plugins:
simple-theme-plugin:0.5.1: [] - name: simple-theme-plugin
configuration-as-code:1.4: version: 0.5.1
- configuration-as-code-support:1.4
``` ```
Then **jenkins-operator** will automatically install plugins after Jenkins master pod restart. Then **jenkins-operator** will automatically install plugins after Jenkins master pod restart.
@ -458,7 +465,7 @@ kubectl get events --sort-by='{.lastTimestamp}'
Verify Jenkins master logs: Verify Jenkins master logs:
```bash ```bash
kubectl logs -f jenkins-master-example kubectl logs -f jenkins-<cr_name>
``` ```
Verify jenkins-operator logs: Verify jenkins-operator logs:
@ -472,7 +479,7 @@ kubectl logs deployment/jenkins-operator
Delete Jenkins master pod and wait for the new one to come up: Delete Jenkins master pod and wait for the new one to come up:
```bash ```bash
kubectl delete pod jenkins-operator-example kubectl delete pod jenkins-<cr_name>
``` ```
[job-dsl]:https://github.com/jenkinsci/job-dsl-plugin [job-dsl]:https://github.com/jenkinsci/job-dsl-plugin

View File

@ -22,10 +22,7 @@ kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator
Apply Service Account and RBAC roles: Apply Service Account and RBAC roles:
```bash ```bash
kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/service_account.yaml kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/all-in-one-v1alpha2.yaml
kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/role.yaml
kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/role_binding.yaml
kubectl apply -f https://raw.githubusercontent.com/jenkinsci/kubernetes-operator/master/deploy/operator.yaml
``` ```
Watch **jenkins-operator** instance being created: Watch **jenkins-operator** instance being created: