Skip to content

Commit 3ed40c1

Browse files
authored
Merge pull request #192771 from craigshoemaker/aca/observ
[Container Apps] Health probes
2 parents 95a7fac + 8abb4df commit 3ed40c1

File tree

3 files changed

+227
-2
lines changed

3 files changed

+227
-2
lines changed

articles/container-apps/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
href: application-lifecycle-management.md
3939
- name: Microservices
4040
href: microservices.md
41+
- name: Health probes
42+
href: health-probes.md
4143
- name: How-to guides
4244
items:
4345
- name: Scale an app

articles/container-apps/azure-resource-manager-api-spec.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Changes made to the `template` section are [revision-scope changes](revisions.md
162162

163163
### <a name="container-app-examples"></a>Examples
164164

165+
For details on health probes, refer to [Heath probes in Azure Container Apps](./health-probes.md).
166+
165167
# [ARM template](#tab/arm-template)
166168

167169
The following example ARM template deploys a container app.
@@ -254,7 +256,45 @@ The following example ARM template deploys a container app.
254256
"resources": {
255257
"cpu": 0.5,
256258
"memory": "1Gi"
257-
}
259+
},
260+
"probes":[
261+
{
262+
"type":"liveness",
263+
"httpGet":{
264+
"path":"/health",
265+
"port":8080,
266+
"httpHeaders":[
267+
{
268+
"name":"Custom-Header",
269+
"value":"liveness probe"
270+
}]
271+
},
272+
"initialDelaySeconds":7,
273+
"periodSeconds":3
274+
},
275+
{
276+
"type":"readiness",
277+
"tcpSocket":
278+
{
279+
"port": 8081
280+
},
281+
"initialDelaySeconds": 10,
282+
"periodSeconds": 3
283+
},
284+
{
285+
"type": "startup",
286+
"httpGet": {
287+
"path": "/startup",
288+
"port": 8080,
289+
"httpHeaders": [
290+
{
291+
"name": "Custom-Header",
292+
"value": "startup probe"
293+
}]
294+
},
295+
"initialDelaySeconds": 3,
296+
"periodSeconds": 3
297+
}]
258298
}
259299
],
260300
"scale": {
@@ -278,7 +318,7 @@ The following example YAML configuration deploys a container app when used with
278318

279319
```yaml
280320
kind: containerapp
281-
location: northeurope
321+
location: canadacentral
282322
name: mycontainerapp
283323
resourceGroup: myresourcegroup
284324
type: Microsoft.App/containerApps
@@ -323,6 +363,30 @@ properties:
323363
resources:
324364
cpu: 0.5
325365
memory: 1Gi
366+
probes:
367+
- type: liveness
368+
httpGet:
369+
- path: "/health"
370+
port: 8080
371+
httpHeaders:
372+
- name: "Custom-Header"
373+
value: "liveness probe"
374+
initialDelaySeconds: 7
375+
periodSeconds: 3
376+
- type: readiness
377+
tcpSocket:
378+
- port: 8081
379+
initialDelaySeconds: 10
380+
periodSeconds: 3
381+
- type: startup
382+
httpGet:
383+
- path: "/startup"
384+
port: 8080
385+
httpHeaders:
386+
- name: "Custom-Header"
387+
value: "startup probe"
388+
initialDelaySeconds: 3
389+
periodSeconds: 3
326390
scale:
327391
minReplicas: 1
328392
maxReplicas: 3
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
---
2+
title: Health probes in Azure Container Apps
3+
description: Check startup, liveness, and readiness with Azure Container Apps health probes
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: container-apps
7+
ms.topic: conceptual
8+
ms.date: 03/30/2022
9+
ms.author: cshoe
10+
---
11+
12+
# Health probes in Azure Container Apps
13+
14+
Health probes in Azure Container Apps are based on [Kubernetes health probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/). You can set up probes using either TCP or HTTP(S) exclusively.
15+
16+
Container Apps support the following probes:
17+
18+
- [Liveness](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command): Reports the overall health of your replica.
19+
- [Startup](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-startup-probes): Delay reporting on a liveness or readiness state for slower apps with a startup probe.
20+
- [Readiness](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes): Signals that a replica is ready to accept traffic.
21+
22+
For a full listing of the specification supported in Azure Container Apps, refer to [Azure Rest API specs](https://github.com/Azure/azure-rest-api-specs/blob/main/specification/app/resource-manager/Microsoft.App/stable/2022-03-01/CommonDefinitions.json#L119-L236).
23+
24+
## HTTP probes
25+
26+
HTTP probes allow you to implement custom logic to check the status of application dependencies before reporting a healthy status. Configure your health probe endpoints to respond with an HTTP status code greater than or equal to `200` and less than `400` to indicate success. Any other response code outside this range indicates a failure.
27+
28+
The following example demonstrates how to implement a liveness endpoint in JavaScript.
29+
30+
```javascript
31+
const express = require('express');
32+
const app = express();
33+
34+
app.get('/liveness', (req, res) => {
35+
let isSystemStable = false;
36+
37+
// check for database availability
38+
// check filesystem structure
39+
// etc.
40+
41+
// set isSystemStable to true if all checks pass
42+
43+
if (isSystemStable) {
44+
res.status(200); // Success
45+
} else {
46+
res.status(503); // Service unavailable
47+
}
48+
})
49+
```
50+
51+
## TCP probes
52+
53+
TCP probes wait for a connection to be established with the server to indicate success. A probe failure is registered if no connection is made.
54+
55+
## Restrictions
56+
57+
- You can only add one of each probe type per container.
58+
- `exec` probes aren't supported.
59+
- Port values must be integers; named ports aren't supported.
60+
61+
## Examples
62+
63+
The following code listing shows how you can define health probes for your containers.
64+
65+
The `...` placeholders denote omitted code. Refer to [Container Apps Preview ARM template API specification](./azure-resource-manager-api-spec.md) for full ARM template details.
66+
67+
# [ARM template](#tab/arm-template)
68+
69+
```json
70+
{
71+
...
72+
"containers":[
73+
{
74+
"image":"nginx",
75+
"name":"web",
76+
"probes": [
77+
{
78+
"type": "liveness",
79+
"httpGet": {
80+
"path": "/health",
81+
"port": 8080,
82+
"httpHeaders": [
83+
{
84+
"name": "Custom-Header",
85+
"value": "liveness probe"
86+
}],
87+
"initialDelaySeconds": 7,
88+
"periodSeconds": 3
89+
}
90+
},
91+
{
92+
"type": "readiness",
93+
"tcpSocket": {
94+
"port": 8081
95+
},
96+
"initialDelaySeconds": 10,
97+
"periodSeconds": 3
98+
},
99+
{
100+
"type": "startup",
101+
"httpGet": {
102+
"path": "/startup",
103+
"port": 8080,
104+
"httpHeaders": [
105+
{
106+
"name": "Custom-Header",
107+
"value": "startup probe"
108+
}],
109+
"initialDelaySeconds": 3,
110+
"periodSeconds": 3
111+
}
112+
}]
113+
}]
114+
...
115+
}
116+
```
117+
118+
# [YAML](#tab/yaml)
119+
120+
```yml
121+
...
122+
containers:
123+
- image: nginx
124+
name: web
125+
probes:
126+
- type: liveness
127+
httpGet:
128+
path: "/health"
129+
port: 8080
130+
httpHeaders:
131+
- name: Custom-Header
132+
value: "liveness probe"
133+
initialDelaySeconds: 7
134+
periodSeconds: 3
135+
- type: readiness
136+
tcpSocket:
137+
port: 8081
138+
initialDelaySeconds: 10
139+
periodSeconds: 3
140+
- type: startup
141+
httpGet:
142+
path: "/startup"
143+
port: 8080
144+
httpHeaders:
145+
- name: Custom-Header
146+
value: "startup probe"
147+
initialDelaySeconds: 3
148+
periodSeconds: 3
149+
...
150+
```
151+
152+
---
153+
154+
The optional [failureThreshold](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes) setting defines the number of attempts Kubernetes tries if the probe if execution fails. Attempts that exceed the `failureThreshold` amount cause different results for each probe. Refer to [Configure Liveness, Readiness and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes) for details.
155+
156+
## Next steps
157+
158+
> [!div class="nextstepaction"]
159+
> [Monitor an app](monitor.md)

0 commit comments

Comments
 (0)