You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update README with agent injection in mind (#1606)
* Update README with agent injection in mind
Following #1602, there are several sentences in the README that can be
made more generic, avoiding references to `jnlp`. As it is still the
default value, I couldn't remove all references, but I think it is
slightly clearer now.
* Fix review and refresh pod template screenshot
* Refresh
Copy file name to clipboardExpand all lines: README.md
+45-50
Original file line number
Diff line number
Diff line change
@@ -92,9 +92,15 @@ Feel free to enable it and provide feedback about this functionality.
92
92
## Static pod templates
93
93
94
94
In addition to that, in the **Kubernetes Pod Template** section, we need to configure the image that will be used to
95
-
spin up the agent pod. We do not recommend overriding the `jnlp` container except under unusual circumstances.
96
-
For your agent, you can use the default Jenkins agent image available in [Docker Hub](https://hub.docker.com). In the
97
-
‘Kubernetes Pod Template’ section you need to specify the following (the rest of the configuration is up to you):
95
+
spin up the agent pod. The Jenkins agent runs by default in a container named `jnlp` (historical name, kept for backward compatibility).
96
+
97
+
You may use it, use a different agent container name and/or provide your own container image.
98
+
99
+
To avoid drift between the Jenkins controller and your agent, we recommend *not* to include the agent JAR in your image, but instead use the *Inject Jenkins agent in agent container* checkbox.
100
+
101
+
The provided container image must have a JRE installed that is compatible with the Java version required by the Jenkins controller.
102
+
103
+
In the ‘Kubernetes Pod Template’ section you need to specify the following (the rest of the configuration is up to you):
98
104
Kubernetes Pod Template Name - can be any and will be shown as a prefix for unique generated agent’ names, which will
99
105
be run automatically during builds
100
106
Docker image - the docker image name that will be used as a reference to spin up a new Jenkins agent, as seen below
@@ -115,9 +121,13 @@ use this cloud configuration you will need to add it in the jobs folder's config
115
121
# Usage
116
122
## Overview
117
123
118
-
The Kubernetes plugin allocates Jenkins agents in Kubernetes pods. Within these pods, there is always one special
119
-
container `jnlp` that is running the Jenkins agent. Other containers can run arbitrary processes of your choosing,
120
-
and it is possible to run commands dynamically in any container in the agent pod.
124
+
The Kubernetes plugin allocates Jenkins agents in Kubernetes pods.
125
+
126
+
Within these pods, there is always one special container that is running the Jenkins agent.
127
+
128
+
Its name defaults to `jnlp`, but you can override the name with one of your choosing in pod template configuration.
129
+
130
+
Other containers can run arbitrary processes of your choosing, and it is possible to run commands dynamically in any container in the agent pod using the `container` step (pipeline only).
121
131
122
132
## Using a label
123
133
@@ -146,10 +156,9 @@ podTemplate {
146
156
}
147
157
```
148
158
149
-
Commands will be executed by default in the `jnlp` container, where the Jenkins agent is running.
150
-
(The `jnlp` name is historical and is retained for compatibility.)
159
+
Commands will be executed by default in the designated agent container, where the Jenkins agent is running.
151
160
152
-
This will run in the `jnlp` container:
161
+
This will run in the agent container:
153
162
```groovy
154
163
podTemplate {
155
164
node(POD_LABEL) {
@@ -162,7 +171,7 @@ podTemplate {
162
171
163
172
Find more examples in the [examples dir](examples).
164
173
165
-
The default jnlp agent image used can be customized by adding it to the template
174
+
The default agent image used can be customized by adding it to the template
@@ -462,29 +471,27 @@ See [Defining a liveness command](https://kubernetes.io/docs/tasks/configure-pod
462
471
## Overview
463
472
464
473
A pod template may or may not inherit from an existing template.
465
-
This means that the pod template will inherit node selector, service account, image pull secrets, container templates
466
-
and volumes from the template it inherits from.
467
474
468
-
**yaml** is merged according to the value of `yamlMergeStrategy`.
475
+
Depending on fields, the inheritance behaviour can vary. For simple values (strings), the child template will override the parent template. However for complex values (lists, maps), the child template will merge with the parent template.
469
476
470
-
**Service account** and **Node selector** when are overridden completely substitute any possible value found on the 'parent'.
471
-
472
-
**Container templates** that are added to the podTemplate, that has a matching containerTemplate (a container template
477
+
* **yaml** is merged according to the value of `yamlMergeStrategy` specified in the child pod template.
478
+
* **Service account** and **Node selector** when are overridden completely substitute any possible value found on the 'parent'.
479
+
* **Container templates** that are added to the podTemplate, that has a matching containerTemplate (a container template
473
480
with the same name) in the 'parent' template, will inherit the configuration of the parent containerTemplate.
474
481
If no matching container template is found, the template is added as is.
475
-
476
-
**Volume** inheritance works exactly as **Container templates**.
477
-
478
-
**Image Pull Secrets** are combined (all secrets defined both on 'parent' and 'current' template are used).
482
+
* **Volume** inheritance works exactly as **Container templates**.
483
+
* **Image Pull Secrets** are combined (all secrets defined both on 'parent' and 'current' template are used).
479
484
480
485
In the example below, we will inherit from a pod template we created previously, and will just override the version of
node(POD_LABEL) { // gets a pod with both docker and maven
540
547
…
541
548
}
@@ -618,7 +625,7 @@ pipeline {
618
625
spec:
619
626
containers:
620
627
- name: maven
621
-
image: maven:alpine
628
+
image: maven:3.9.9-eclipse-temurin-17
622
629
command:
623
630
- cat
624
631
tty: true
@@ -671,7 +678,7 @@ pipeline {
671
678
//cloud 'kubernetes'
672
679
containerTemplate {
673
680
name 'maven'
674
-
image 'maven:3.8.1-jdk-8'
681
+
image 'maven:3.9.9-eclipse-temurin-17'
675
682
command 'sleep'
676
683
args '99d'
677
684
}
@@ -684,7 +691,7 @@ pipeline {
684
691
```
685
692
686
693
Run steps within a container by default. Steps will be nested within an implicit `container(name) {...}` block instead
687
-
of being executed in the jnlp container.
694
+
of being executed in the agent container.
688
695
689
696
```groovy
690
697
pipeline {
@@ -760,7 +767,7 @@ pipeline {
760
767
spec:
761
768
containers:
762
769
- name: maven
763
-
image: maven:3.8.1-jdk-8
770
+
image: maven:3.9.9-eclipse-temurin-17
764
771
command:
765
772
- sleep
766
773
args:
@@ -822,7 +829,7 @@ OpenShift runs containers using a _random_ UID that is overriding what is specif
822
829
For this reason, you may end up with the following warning in your build
823
830
824
831
```
825
-
[WARNING] HOME is set to / in the jnlp container. You may encounter troubles when using tools or ssh client. This usually happens if the uid doesnt have any entry in /etc/passwd. Please add a user to your Dockerfile or set the HOME environment variable to a valid directory in the pod template definition.
832
+
[WARNING] HOME is set to / in the agent container. You may encounter troubles when using tools or ssh client. This usually happens if the uid doesnt have any entry in /etc/passwd. Please add a user to your Dockerfile or set the HOME environment variable to a valid directory in the pod template definition.
826
833
```
827
834
828
835
At the moment the jenkinsci agent image is not built for OpenShift and will issue this warning.
@@ -847,18 +854,6 @@ beta.kubernetes.io/os=linux
847
854
You can run pods on Windows if your cluster has Windows nodes.
848
855
See the [example](src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/windows.groovy).
849
856
850
-
# Constraints
851
-
852
-
Multiple containers can be defined in a pod.
853
-
One of them is automatically created with name `jnlp`, and runs the Jenkins JNLP agent service, with args `${computer.jnlpmac} ${computer.name}`,
854
-
and will be the container acting as Jenkins agent.
855
-
856
-
Other containers must run a long running process, so the container does not exit. If the default entrypoint or command
857
-
just runs something and exit then it should be overridden with something like `cat` with `ttyEnabled: true`.
858
-
859
-
**WARNING**
860
-
If you want to provide your own Docker image for the inbound agent, you **must** name the container `jnlp` so it overrides the default one. Failing to do so will result in two agents trying to concurrently connect to the controller.
861
-
862
857
# Configuration on minikube
863
858
864
859
Create and start [minikube](https://github.com/kubernetes/minikube)
0 commit comments