|
1 | 1 | title: Jenkins X - Java Native Image Prod
|
2 |
| -description: Creating a Java Native Image application and run it as Production with Jenkins X - Jenkins X Import - 1/8 |
| 2 | +description: Creating a Java Native Image application and run it as Production with Jenkins X - Jenkins X Import - 4/8 |
3 | 3 | hero: Jenkins X Import - 4/8
|
4 | 4 |
|
5 | 5 | # Jenkins X Import
|
@@ -77,26 +77,118 @@ CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Xmx64m"]
|
77 | 77 |
|
78 | 78 | One of the most important aspects of your application running in Kubernetes, is giving Kubernetes enough information about the state of your application. Kubernetes does this via [Liveness and Readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
|
79 | 79 |
|
| 80 | +### What Are These Probes |
| 81 | + |
80 | 82 | If you don't know much about these probes, or want to understand them better, [read the Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/). For the lazy, I've added quotes for this docs page.
|
81 | 83 |
|
82 | 84 | > **livenessProbe**: Indicates whether the Container is running. If the liveness probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a liveness probe, the default state is Success.
|
83 | 85 |
|
84 | 86 | > **readinessProbe**: Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod’s IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure. If a Container does not provide a readiness probe, the default state is Success.
|
85 | 87 |
|
| 88 | +We recommend servicing each probe with a distinct endpoint if you can. |
86 | 89 |
|
| 90 | +### Quarkus Health Checks |
87 | 91 |
|
88 |
| -```xml |
89 |
| -<dependency> |
90 |
| - <groupId>io.quarkus</groupId> |
91 |
| - <artifactId>quarkus-smallrye-health</artifactId> |
92 |
| -</dependency> |
93 |
| -``` |
| 92 | +Luckily, Quarkus has a dependency that gives us exactly that: `quarkus-smallrye-health`. |
| 93 | +`quarkus-smallrye-health` is an implementation of MicroProfile's Health specification, and they [have a guide on using and extending it](https://quarkus.io/guides/microprofile-health). |
| 94 | + |
| 95 | +For those wanting to skip the line, for the minimal implementation we add one dependency to our `pom.xml`, namely, the mentioned `quarkus-smallrye-health`. This dependency automatically gives us three endpoints for health checks: |
94 | 96 |
|
95 | 97 | * `/health/live`: The application is up and running.
|
96 | 98 | * `/health/ready`: The application is ready to serve requests.
|
97 | 99 | * `/health`: Accumulating all health check procedures in the application.
|
98 | 100 |
|
99 |
| -https://quarkus.io/guides/microprofile-health |
100 |
| - |
| 101 | +### Add Dependency |
101 | 102 |
|
| 103 | +```xml |
| 104 | +<dependency> |
| 105 | + <groupId>io.quarkus</groupId> |
| 106 | + <artifactId>quarkus-smallrye-health</artifactId> |
| 107 | +</dependency> |
| 108 | +``` |
102 | 109 |
|
| 110 | +### Update Our Kubernetes Configuration |
| 111 | + |
| 112 | +We now have the ability to give Kubernetes the information it needs to understand the status of our application. |
| 113 | +We still have to ensure Kubernetes knows how to get this information. |
| 114 | + |
| 115 | +To do so, we have two choices. |
| 116 | + |
| 117 | +1. Update the `values.yaml` of our Chart, it has one entry for both checks, so not optimal, but minimal effort |
| 118 | +1. Update the `templates/deployment.yaml` of our Chart, where we have to set both endpoints |
| 119 | + |
| 120 | +#### Update Values |
| 121 | + |
| 122 | +By default, the Helm chart that is generated has one variable for both the liveness and readyness probes: `probePath`. |
| 123 | + |
| 124 | +The value is specified between `resources` and `livenessProbe`: |
| 125 | + |
| 126 | +We set the value of `probePath` to `/health`: |
| 127 | + |
| 128 | +!!! example "charts/Name-Of-Your-App/values.yaml" |
| 129 | + |
| 130 | + ```yaml hl_lines="8" |
| 131 | + resources: |
| 132 | + limits: |
| 133 | + cpu: 250m |
| 134 | + memory: 64Mi |
| 135 | + requests: |
| 136 | + cpu: 250m |
| 137 | + memory: 64Mi |
| 138 | + probePath: /health |
| 139 | + livenessProbe: |
| 140 | + initialDelaySeconds: 60 |
| 141 | + periodSeconds: 10 |
| 142 | + successThreshold: 1 |
| 143 | + timeoutSeconds: 1 |
| 144 | + ``` |
| 145 | + |
| 146 | +#### Update Deployment |
| 147 | + |
| 148 | +The second way of make the required change, is to update our Deployment definition. |
| 149 | +You can choose to set the values directly in the template, or better, change the variables used in the probe paths and set the values of these variables in the `values.yaml`. |
| 150 | + |
| 151 | +We will do the latter here: |
| 152 | + |
| 153 | +!!! example "charts/Name-Of-Your-App/templates/deployment.yaml" |
| 154 | + |
| 155 | + ```yaml hl_lines="3 11" |
| 156 | + livenessProbe: |
| 157 | + httpGet: |
| 158 | + path: {{ .Values.livenessProbePath }} |
| 159 | + port: {{ .Values.service.internalPort }} |
| 160 | + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} |
| 161 | + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} |
| 162 | + successThreshold: {{ .Values.livenessProbe.successThreshold }} |
| 163 | + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} |
| 164 | + readinessProbe: |
| 165 | + httpGet: |
| 166 | + path: {{ .Values.readinessProbePath }} |
| 167 | + port: {{ .Values.service.internalPort }} |
| 168 | + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} |
| 169 | + successThreshold: {{ .Values.readinessProbe.successThreshold }} |
| 170 | + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} |
| 171 | + ``` |
| 172 | + |
| 173 | +!!! example "charts/Name-Of-Your-App/values.yaml" |
| 174 | + |
| 175 | + ```yaml hl_lines="8 9" |
| 176 | + resources: |
| 177 | + limits: |
| 178 | + cpu: 250m |
| 179 | + memory: 64Mi |
| 180 | + requests: |
| 181 | + cpu: 250m |
| 182 | + memory: 64Mi |
| 183 | + livenessProbePath: /health/live |
| 184 | + readinessProbePath: /health/ready |
| 185 | + livenessProbe: |
| 186 | + initialDelaySeconds: 60 |
| 187 | + periodSeconds: 10 |
| 188 | + successThreshold: 1 |
| 189 | + timeoutSeconds: 1 |
| 190 | + ``` |
| 191 | + |
| 192 | +## Next Steps |
| 193 | + |
| 194 | +We are going to do a lot more things, but this concludes the initial steps to import our application in Jenkins X. Our application still can't run, because it doesn't have the information to connect to the database. This is our next stop. |
0 commit comments