|
| 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