Skip to content

Commit 96eead4

Browse files
authored
Merge pull request #34709 from sjhala-ccs/BZ-1901643
BZ-1901643: Updated Monitoring VM health assembly
2 parents 2c985c5 + 8ddc772 commit 96eead4

8 files changed

+153
-190
lines changed

modules/virt-about-liveness-readiness-probes.adoc

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/logging_events_monitoring/virt-monitoring-vm-health.adoc
4+
5+
[id="virt-about-readiness-liveness-probes_{context}"]
6+
7+
= About readiness and liveness probes
8+
9+
Use readiness and liveness probes to detect and handle unhealthy virtual machine instances (VMIs). You can include one or more probes in the specification of the VMI to ensure that traffic does not reach a VMI that is not ready for it and that a new instance is created when a VMI becomes unresponsive.
10+
11+
A _readiness probe_ determines whether a VMI is ready to accept service requests. If the probe fails, the VMI is removed from the list of available endpoints until the VMI is ready.
12+
13+
A _liveness probe_ determines whether a VMI is responsive. If the probe fails, the VMI is deleted and a new instance is created to restore responsiveness.
14+
15+
You can configure readiness and liveness probes by setting the `spec.readinessProbe` and the `spec.livenessProbe` fields of the `VirtualMachineInstance` object. These fields support the following tests:
16+
17+
HTTP GET:: The probe determines the health of the VMI by using a web hook. The test is successful if the HTTP response code is between 200 and 399. You can use an HTTP GET test with applications that return HTTP status codes when they are completely initialized.
18+
19+
TCP socket:: The probe attempts to open a socket to the VMI. The VMI is only considered healthy if the probe can establish a connection. You can use a TCP socket test with applications that do not start listening until initialization is complete.

modules/virt-define-http-liveness-probe.adoc

Lines changed: 26 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,43 @@
44

55
[id="virt-define-http-liveness-probe_{context}"]
66

7-
= Define an HTTP liveness probe
7+
= Defining an HTTP liveness probe
8+
9+
Define an HTTP liveness probe by setting the `spec.livenessProbe.httpGet` field of the virtual machine instance (VMI) configuration. You can define both HTTP and TCP tests for liveness probes in the same way as readiness probes. This procedure configures a sample liveness probe with an HTTP GET test.
810

9-
This procedure provides an example configuration file for defining HTTP
10-
liveness probes.
1111

1212
.Procedure
1313

14-
. Customize a YAML configuration file to create an HTTP liveness probe, using
15-
the following code block as an example. In this example:
16-
+
17-
--
18-
* You configure a probe using `spec.livenessProbe.httpGet`, which queries port `1500` of the virtual machine instance, after an initial delay of `120` seconds.
19-
* The virtual machine instance installs and runs a minimal HTTP server
20-
on port `1500` using `cloud-init`.
21-
--
22-
+
23-
[NOTE]
24-
====
25-
The `timeoutSeconds` value must be lower than the `periodSeconds` value. The `timeoutSeconds` default value is `1`. The `periodSeconds` default value is `10`.
26-
====
14+
. Include details of the HTTP liveness probe in the VMI configuration file.
2715
+
16+
17+
.Sample liveness probe with an HTTP GET test
2818
[source,yaml]
2919
----
30-
apiVersion: kubevirt.io/v1alpha3
31-
kind: VirtualMachineInstance
32-
metadata:
33-
labels:
34-
special: vmi-fedora
35-
name: vmi-fedora
20+
...
3621
spec:
37-
domain:
38-
devices:
39-
disks:
40-
- disk:
41-
bus: virtio
42-
name: containerdisk
43-
- disk:
44-
bus: virtio
45-
name: cloudinitdisk
46-
resources:
47-
requests:
48-
memory: 1024M
4922
livenessProbe:
50-
initialDelaySeconds: 120
51-
periodSeconds: 20
52-
httpGet:
53-
port: 1500
54-
timeoutSeconds: 10
55-
terminationGracePeriodSeconds: 0
56-
volumes:
57-
- name: containerdisk
58-
registryDisk:
59-
image: kubevirt/fedora-cloud-registry-disk-demo
60-
- cloudInitNoCloud:
61-
userData: |-
62-
#cloud-config
63-
password: fedora
64-
chpasswd: { expire: False }
65-
bootcmd:
66-
- setenforce 0
67-
- dnf install -y nmap-ncat
68-
- systemd-run --unit=httpserver nc -klp 1500 -e '/usr/bin/echo -e HTTP/1.1 200 OK\\n\\nHello World!'
69-
name: cloudinitdisk
23+
initialDelaySeconds: 120 <1>
24+
periodSeconds: 20 <2>
25+
httpGet: <3>
26+
port: 1500 <4>
27+
path: /healthz <5>
28+
httpHeaders:
29+
- name: Custom-Header
30+
value: Awesome
31+
timeoutSeconds: 10 <6>
32+
...
7033
----
71-
+
72-
. Create the virtual machine instance by running the following command:
34+
<1> The time, in seconds, after the VMI starts before the liveness probe is initiated.
35+
<2> The delay, in seconds, between performing probes. The default delay is 10 seconds. This value must be greater than `timeoutSeconds`.
36+
<3> The HTTP GET request to perform to connect to the VMI.
37+
<4> The port of the VMI that the probe queries. In the above example, the probe queries port 1500. The VMI installs and runs a minimal HTTP server on port 1500 via cloud-init.
38+
<5> The path to access on the HTTP server. In the above example, if the handler for the server's `/healthz` path returns a success code, the VMI is considered to be healthy. If the handler returns a failure code, the VMI is deleted and a new instance is created.
39+
<6> The number of seconds of inactivity after which the probe times out and the VMI is assumed to have failed. The default value is 1. This value must be lower than `periodSeconds`.
40+
41+
. Create the VMI by running the following command:
7342
+
7443
[source,terminal]
7544
----
76-
$ oc create -f <file name>.yaml
45+
$ oc create -f <file_name>.yaml
7746
----
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/logging_events_monitoring/virt-monitoring-vm-health.adoc
4+
5+
[id="virt-define-http-readiness-probe_{context}"]
6+
7+
= Defining an HTTP readiness probe
8+
9+
Define an HTTP readiness probe by setting the `spec.readinessProbe.httpGet` field of the virtual machine instance (VMI) configuration.
10+
11+
12+
.Procedure
13+
. Include details of the readiness probe in the VMI configuration file.
14+
+
15+
16+
.Sample readiness probe with an HTTP GET test
17+
[source,yaml]
18+
----
19+
...
20+
spec:
21+
readinessProbe:
22+
httpGet: <1>
23+
port: 1500 <2>
24+
path: /healthz <3>
25+
httpHeaders:
26+
- name: Custom-Header
27+
value: Awesome
28+
initialDelaySeconds: 120 <4>
29+
periodSeconds: 20 <5>
30+
timeoutSeconds: 10 <6>
31+
failureThreshold: 3 <7>
32+
successThreshold: 3 <8>
33+
...
34+
----
35+
<1> The HTTP GET request to perform to connect to the VMI.
36+
<2> The port of the VMI that the probe queries. In the above example, the probe queries port 1500.
37+
<3> The path to access on the HTTP server. In the above example, if the handler for the server’s /healthz path returns a success code, the VMI is considered to be healthy. If the handler returns a failure code, the VMI is removed from the list of available endpoints.
38+
<4> The time, in seconds, after the VMI starts before the readiness probe is initiated.
39+
<5> The delay, in seconds, between performing probes. The default delay is 10 seconds. This value must be greater than `timeoutSeconds`.
40+
<6> The number of seconds of inactivity after which the probe times out and the VMI is assumed to have failed. The default value is 1. This value must be lower than `periodSeconds`.
41+
<7> The number of times that the probe is allowed to fail. The default is 3. After the specified number of attempts, the pod is marked `Unready`.
42+
<8> The number of times that the probe must report success, after a failure, to be considered successful. The default is 1.
43+
44+
. Create the VMI by running the following command:
45+
+
46+
[source,terminal]
47+
----
48+
$ oc create -f <file_name>.yaml
49+
----

modules/virt-define-readiness-probe.adoc

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/logging_events_monitoring/virt-monitoring-vm-health.adoc
4+
5+
[id="virt-define-tcp-readiness-probe_{context}"]
6+
7+
= Defining a TCP readiness probe
8+
9+
Define a TCP readiness probe by setting the `spec.readinessProbe.tcpSocket` field of the virtual machine instance (VMI) configuration.
10+
11+
12+
.Procedure
13+
14+
. Include details of the TCP readiness probe in the VMI configuration file.
15+
+
16+
17+
.Sample readiness probe with a TCP socket test
18+
[source,yaml]
19+
----
20+
...
21+
spec:
22+
readinessProbe:
23+
initialDelaySeconds: 120 <1>
24+
periodSeconds: 20 <2>
25+
tcpSocket: <3>
26+
port: 1500 <4>
27+
timeoutSeconds: 10 <5>
28+
...
29+
----
30+
<1> The time, in seconds, after the VMI starts before the readiness probe is initiated.
31+
<2> The delay, in seconds, between performing probes. The default delay is 10 seconds. This value must be greater than `timeoutSeconds`.
32+
<3> The TCP action to perform.
33+
<4> The port of the VMI that the probe queries.
34+
<5> The number of seconds of inactivity after which the probe times out and the VMI is assumed to have failed. The default value is 1. This value must be lower than `periodSeconds`.
35+
36+
. Create the VMI by running the following command:
37+
+
38+
[source,terminal]
39+
----
40+
$ oc create -f <file_name>.yaml
41+
----

modules/virt-define-tcp-liveness-probe.adoc renamed to modules/virt-template-vmi-probe-config.adoc

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,9 @@
22
//
33
// * virt/logging_events_monitoring/virt-monitoring-vm-health.adoc
44

5-
[id="virt-define-tcp-liveness-probe_{context}"]
5+
[id="virt-template-vmi-probe-config_{context}"]
6+
= Template: Virtual machine instance configuration file for defining health checks
67

7-
= Define a TCP liveness probe
8-
9-
This procedure provides an example configuration file for defining
10-
TCP liveness probes.
11-
12-
.Procedure
13-
14-
. Customize a YAML configuration file to create an TCP liveness probe, using
15-
this code block as an example. In this example:
16-
+
17-
--
18-
* You configure a probe using `spec.livenessProbe.tcpSocket`, which queries port `1500` of the virtual machine instance, after an initial delay of `120` seconds.
19-
* The virtual machine instance installs and runs a minimal HTTP server
20-
on port `1500` using `cloud-init`.
21-
--
22-
+
23-
[NOTE]
24-
====
25-
The `timeoutSeconds` value must be lower than the `periodSeconds` value. The `timeoutSeconds` default value is `1`. The `periodSeconds` default value is `10`.
26-
====
27-
+
288
[source,yaml]
299
----
3010
apiVersion: kubevirt.io/v1alpha3
@@ -46,16 +26,18 @@ spec:
4626
resources:
4727
requests:
4828
memory: 1024M
49-
livenessProbe:
29+
readinessProbe:
30+
httpGet:
31+
port: 1500
5032
initialDelaySeconds: 120
5133
periodSeconds: 20
52-
tcpSocket:
53-
port: 1500
5434
timeoutSeconds: 10
35+
failureThreshold: 3
36+
successThreshold: 3
5537
terminationGracePeriodSeconds: 0
5638
volumes:
5739
- name: containerdisk
58-
registryDisk:
40+
containerDisk:
5941
image: kubevirt/fedora-cloud-registry-disk-demo
6042
- cloudInitNoCloud:
6143
userData: |-
@@ -68,10 +50,3 @@ spec:
6850
- systemd-run --unit=httpserver nc -klp 1500 -e '/usr/bin/echo -e HTTP/1.1 200 OK\\n\\nHello World!'
6951
name: cloudinitdisk
7052
----
71-
+
72-
. Create the virtual machine instance by running the following command:
73-
+
74-
[source,terminal]
75-
----
76-
$ oc create -f <file name>.yaml
77-
----

virt/logging_events_monitoring/virt-monitoring-vm-health.adoc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ include::modules/virt-document-attributes.adoc[]
55

66
toc::[]
77

8-
Use this procedure to create liveness and readiness probes
9-
to monitor virtual machine health.
8+
A virtual machine instance (VMI) can become unhealthy due to transient issues such as connectivity loss, deadlocks, or problems with external dependencies. A health check periodically performs diagnostics on a VMI by using any combination of the readiness and liveness probes.
109

11-
include::modules/virt-about-liveness-readiness-probes.adoc[leveloffset=+1]
10+
include::modules/virt-about-readiness-liveness-probes.adoc[leveloffset=+1]
11+
include::modules/virt-define-http-readiness-probe.adoc[leveloffset=+1]
12+
include::modules/virt-define-tcp-readiness-probe.adoc[leveloffset=+1]
1213
include::modules/virt-define-http-liveness-probe.adoc[leveloffset=+1]
13-
include::modules/virt-define-tcp-liveness-probe.adoc[leveloffset=+1]
14-
include::modules/virt-define-readiness-probe.adoc[leveloffset=+1]
14+
include::modules/virt-template-vmi-probe-config.adoc[leveloffset=+1]
15+
16+
[id="additional-resources_monitoring-vm-health"]
17+
== Additional resources
18+
19+
* xref:../../applications/application-health.adoc#application-health[Monitoring application health by using health checks]

0 commit comments

Comments
 (0)