'How to deploy multiple Jenkins jobs in the same node?
actually i have deployed jenkins master in a GKE cluster, i have a nodepool called jenkins with autoscaling with 2 nodes max. so when i run a job in jenkins, always is using that nodepool, so, thats cool, but, the problem that i have actually, is that when i run a job, jenkins is using 1 node per job, instead of use 1 node per two or more jobs, if a do a kubectl describe node nodename, i can see that i have only 1 jenkins agent deployed in each kubernetes node.
How can i fix this and use 1 node for more than 1 jenkins agent at the same time? because actually im "underusing" my jenkins nodes, because 1 job per node only use half of node resources.
Example of kubectl describe node jenkinsnode (you can see that only have 1 jenkins pod in that node):
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits Age
--------- ---- ------------ ---------- --------------- ------------- ---
jenkins atlas-test-atlas-full-tests-2-mrc47-2h7fb-t1vdn 850m (21%) 1250m (31%) 1536Mi (54%) 2560Mi (91%) 118s
kube-system fluentbit-gke-f296j 100m (2%) 0 (0%) 200Mi (7%) 500Mi (17%) 5m8s
kube-system gke-metadata-server-nc58q 100m (2%) 100m (2%) 100Mi (3%) 100Mi (3%) 5m7s
kube-system gke-metrics-agent-q6xl4 3m (0%) 0 (0%) 50Mi (1%) 50Mi (1%) 5m8s
kube-system kube-proxy-gke-develop-jenkins-eb1faad2-9m00 100m (2%) 0 (0%) 0 (0%) 0 (0%) 5m7s
kube-system netd-s6v8s 0 (0%) 0 (0%) 0 (0%) 0 (0%) 5m7s
Thanks in advance
Solution 1:[1]
You can use the Kubernetes plugin for Jenkins, with it you can create a Kubernetes Pod for each agent started:
The Kubernetes plugin allocates Jenkins agents in Kubernetes pods. Within these pods, there is always one special container jnlp that is running the Jenkins agent. Other containers can run arbitrary processes of your choosing, and it is possible to run commands dynamically in any container in the agent pod.
Example:
pod.yaml
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: maven:3.8.1-jdk-8
command:
- sleep
args:
- 99d
- name: golang
image: golang:1.16.5
command:
- sleep
args:
- 99d
Jenkinsfile
podTemplate(yaml: readTrusted('pod.yaml')) {
node(POD_LABEL) {
// ...
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gabriel Robledo Ahumada |