简体   繁体   中英

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 kube.netes 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

You can use the Kube.netes plugin for Jenkins , with it you can create a Kube.netes Pod for each agent started:

The Kube.netes plugin allocates Jenkins agents in Kube.netes 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) {
    // ...
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM