# Deploy Jenkins on a existing cluster
- Just follow the [official tutorial](https://www.jenkins.io/doc/book/installing/kubernetes/)
---
## Deploy by microk8s
### Pre-request
If you don't have helm3 add-on, install it.
```bash
microk8s enable helm3
```
### Installation
```bash
microk8s kubectl create namespace jenkins
# get default configuration
wget https://raw.githubusercontent.com/jenkinsci/helm-charts/main/charts/jenkins/values.yaml
# add jenkins repo to helm3
microk8s helm3 repo add jenkinsci https://charts.jenkins.io
microk8s helm3 repo update
# deploy with configuration
chart=jenkinsci/jenkins
microk8s helm3 install jenkins -n jenkins -f values.yaml $chart
# proxy to the pod
microk8s kubectl -n jenkins port-forward $pod_name 8080:8080
```
- Check `127.0.0.1:8080`
- Get `admin` password
```bash
jsonpath="{.data.jenkins-admin-password}"
secret=$(kubectl get secret -n jenkins jenkins -o jsonpath=$jsonpath)
echo $(echo $secret | base64 --decode)
```
### Deploy the job to certain node
- Create pod template with certain label
- Add nodeSelector for selecting the node you want ([reference](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/))
- Create job and launch with node has certain label
### TODO
- Change the configuration to satisfy our condition.
### Troubleshooting
#### Fail to install using helm3
```
Error: parse error at (jenkins/templates/_helpers.tpl:59): function "lookup" not defined
```
- It is `helm3`'s [bug](https://github.com/helm/helm/pull/7969), just upgrade it to fix the problem. (v3.5.0 work well)
- Downlaod the [pre-build](https://github.com/helm/helm/releases) and replace the binary at `$SNAP_DATA/bin/helm3` with the latest version.
#### Fail at pod CrashLoopBackOff
- Check the error log first
```
microk8s kubectl logs POD_NAME -n jenkins
```
- If it look like this, just set the correct permission of the storage folder
```
disable Setup Wizard
/var/jenkins_config/apply_config.sh: 4: /var/jenkins_config/apply_config.sh: cannot create /var/jenkins_home/jenkins.install.UpgradeWizard.state: Permission denied
```