From abffa00b76b31a92a9d5c4035f15b12ff6ad12d7 Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Thu, 15 Mar 2018 09:55:02 +0530 Subject: [PATCH] Update healthcheck related examples and add head support (#5650) - Add head method for healthcheck endpoint. Some platforms/users may use the HTTP Head method to check for health status. - Add liveness and readiness probe examples in Kubernetes yaml example docs. Note that readiness probe not added to StatefulSet example due to https://github.com/kubernetes/kubernetes/issues/27114 --- cmd/generic-handlers.go | 2 +- cmd/healthcheck-router.go | 2 ++ docs/healthcheck/README.md | 28 ++++--------------- docs/orchestration/kubernetes-yaml/README.md | 27 ++++++++++++++++++ .../minio-distributed-statefulset.yaml | 9 ++++++ .../minio-standalone-deployment.yaml | 18 ++++++++++++ 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index 696c5eeed..fee8cbb20 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -200,7 +200,7 @@ func guessIsHealthCheckReq(req *http.Request) bool { return false } aType := getRequestAuthType(req) - return req.Method == http.MethodGet && aType == authTypeAnonymous && + return aType == authTypeAnonymous && (req.Method == http.MethodGet || req.Method == http.MethodHead) && (req.URL.Path == healthCheckPathPrefix+healthCheckLivenessPath || req.URL.Path == healthCheckPathPrefix+healthCheckReadinessPath) } diff --git a/cmd/healthcheck-router.go b/cmd/healthcheck-router.go index 421dddec9..538f925d8 100644 --- a/cmd/healthcheck-router.go +++ b/cmd/healthcheck-router.go @@ -37,7 +37,9 @@ func registerHealthCheckRouter(mux *router.Router) { // Liveness handler healthRouter.Methods(http.MethodGet).Path(healthCheckLivenessPath).HandlerFunc(LivenessCheckHandler) + healthRouter.Methods(http.MethodHead).Path(healthCheckLivenessPath).HandlerFunc(LivenessCheckHandler) // Readiness handler healthRouter.Methods(http.MethodGet).Path(healthCheckReadinessPath).HandlerFunc(ReadinessCheckHandler) + healthRouter.Methods(http.MethodHead).Path(healthCheckReadinessPath).HandlerFunc(ReadinessCheckHandler) } diff --git a/docs/healthcheck/README.md b/docs/healthcheck/README.md index 0a956a3ab..313e09573 100644 --- a/docs/healthcheck/README.md +++ b/docs/healthcheck/README.md @@ -3,37 +3,21 @@ Minio server exposes two un-authenticated, healthcheck endpoints - liveness probe and readiness probe at `/minio/health/live` and `/minio/health/ready` respectively. ### Liveness probe + This probe is used to identify situations where the server is running but may not behave optimally, i.e. sluggish response or corrupt backend. Such problems can be *only* fixed by a restart. Internally, Minio liveness probe handler does a ListBuckets call. If successful, the server returns 200 OK, otherwise 503 Service Unavailable. -When liveness probe fails, Kubernetes like platforms restart the container. - -Sample configuration in a Kubernetes `yaml` file. - -```yaml -livenessProbe: - httpGet: - path: /minio/health/live - port: 9000 - initialDelaySeconds: 10 - periodSeconds: 20 -``` +When liveness probe fails, Kubernetes like platforms restart the container. ### Readiness probe + This probe is used to identify situations where the server is not ready to accept requests yet. In most cases, such conditions recover in some time. Internally, Minio readiness probe handler checks for total go-routines. If the number of go-routines is less than 1000 (threshold), the server returns 200 OK, otherwise 503 Service Unavailable. -Platforms like Kubernetes *do not* forward traffic to a pod until its readiness probe is successful. +Platforms like Kubernetes *do not* forward traffic to a pod until its readiness probe is successful. -Sample configuration in a Kubernetes `yaml` file. +### Configuration example -```yaml -livenessProbe: - httpGet: - path: /minio/health/ready - port: 9000 - initialDelaySeconds: 10 - periodSeconds: 20 -``` \ No newline at end of file +Sample `liveness` and `readiness` probe configuration in a Kubernetes `yaml` file can be found [here](https://github.com/minio/minio/blob/master/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml). diff --git a/docs/orchestration/kubernetes-yaml/README.md b/docs/orchestration/kubernetes-yaml/README.md index 4e39e3740..130af2b17 100644 --- a/docs/orchestration/kubernetes-yaml/README.md +++ b/docs/orchestration/kubernetes-yaml/README.md @@ -135,6 +135,24 @@ spec: value: "minio123" ports: - containerPort: 9000 + # Readiness probe detects situations when Minio server instance + # is not ready to accept traffic. Kubernetes doesn't forward + # traffic to the pod till readiness checks fail. + readinessProbe: + httpGet: + path: /minio/health/ready + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 + # Liveness probe detects situations where Minio server instance + # is not working properly and needs restart. Kubernetes automatically + # restarts the pods if liveness checks fail. + livenessProbe: + httpGet: + path: /minio/health/live + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 ``` Create the Deployment @@ -298,6 +316,15 @@ spec: volumeMounts: - name: data mountPath: /data + # Liveness probe detects situations where Minio server instance + # is not working properly and needs restart. Kubernetes automatically + # restarts the pods if liveness checks fail. + livenessProbe: + httpGet: + path: /minio/health/live + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 # These are converted to volume claims by the controller # and mounted at the paths mentioned above. volumeClaimTemplates: diff --git a/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml b/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml index abfd6a7d8..62df250f9 100644 --- a/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml +++ b/docs/orchestration/kubernetes-yaml/minio-distributed-statefulset.yaml @@ -35,6 +35,15 @@ spec: volumeMounts: - name: data mountPath: /data + # Liveness probe detects situations where Minio server instance + # is not working properly and needs restart. Kubernetes automatically + # restarts the pods if liveness checks fail. + livenessProbe: + httpGet: + path: /minio/health/live + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 # These are converted to volume claims by the controller # and mounted at the paths mentioned above. volumeClaimTemplates: diff --git a/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml b/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml index f61c0df81..3a213ea73 100644 --- a/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml +++ b/docs/orchestration/kubernetes-yaml/minio-standalone-deployment.yaml @@ -41,3 +41,21 @@ spec: value: "minio123" ports: - containerPort: 9000 + # Readiness probe detects situations when Minio server instance + # is not ready to accept traffic. Kubernetes doesn't forward + # traffic to the pod while readiness checks fail. + readinessProbe: + httpGet: + path: /minio/health/ready + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20 + # Liveness probe detects situations where Minio server instance + # is not working properly and needs restart. Kubernetes automatically + # restarts the pods if liveness checks fail. + livenessProbe: + httpGet: + path: /minio/health/live + port: 9000 + initialDelaySeconds: 120 + periodSeconds: 20