- "Whenever you trigger a Jenkins job, the Jenkins Kubernetes plugin will make an API call to create a Kubernetes agent pod. Then, the Jenkins agent pod gets deployed in the kubernetes with few environment variables containing the Jenkins server details and secrets."
- "When the agent pod comes up, it used the details in its environment variables and talks back to Jenkins using the JNLP method" (Ref: DevopsCube)
-
K8s cluster was created before:
-
On that cluster, helm was installed on the master node.
- Install on Ubuntu 20.04 (for other platforms: https://helm.sh/docs/intro/install/)
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
helm version
helm repo add jenkins https://charts.jenkins.io
helm repo list
mkdir helm
cd helm
helm pull jenkins/jenkins
tar zxvf jenkins-3.11.4.tgz
- After unzipping, entered into the jenkins directory, you'll find values.yaml file. Disable the persistence with false.
- If your cluster on-premise does not support storage class (like our multipass VM cluster), PVC and PV, disable persistence. But if you are working on minikube, minikube supports PVC and PV automatically.
- If you don't disable persistence, you'll encounter that your PODs will not run (wait pending). You can inspect PVC, PV and Pod with kubectl describe command.
- Install Helm Jenkins Release:
helm install j1 jenkins
kubectl get pods
kubectl get svc
kubectl get pods -o wide
- To get Jenkins password (username:admin), run:
kubectl exec --namespace default -it svc/j1-jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo
- Port Forwarding:
kubectl --namespace default port-forward svc/j1-jenkins 8080:8080
- Install ubuntu-desktop, so you can reach multipass VM's browser using Windows RDP (Xrdp) (https://discourse.ubuntu.com/t/graphical-desktop-in-multipass/16229)
sudo apt update
sudo apt install ubuntu-desktop xrdp
sudo passwd ubuntu # set password
- Helm also downloads automatically some of the plugins (kubernetes:1.31.3, workflow-aggregator:2.6, git:4.10.2, configuration-as-code:1.55.1) (Jenkins Version: 2.319.3)
- Manage Jenkins > Configure System > Cloud
- New Item on main page:
- Add script > Build > Execute Shell:
- After triggering jobs, Jenkins (on Master) creates agents on Worker1 automatically. After jobs are completed, they are terminated.