K8S Ingress Controller 健康检查原理剖析

阅读全文请点击

健康检查配置

nginx_ingress_controller_health_check

我们知道K8S本身提供了LivenessReadiness机制来对Pod进行健康监控,同样我们在部署K8S Ingress Controller时也配置了LivenessProbe和ReadinessProbe对其进行健康检查,具体配置如下所示:

livenessProbe:
  failureThreshold: 3
  httpGet:
    path: /healthz
    port: 10254
    scheme: HTTP
  initialDelaySeconds: 10
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1
readinessProbe:
  failureThreshold: 3
  httpGet:
    path: /healthz
    port: 10254
    scheme: HTTP
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1

那么Kubelet在对Nginx Ingress Controller Pod进行定期健康检查时,就会通过HTTP协议发送GET请求,类似于如下请求:

curl -XGET http://<NGINX_INGRESS_CONTROLLER_POD_ID>:10254/healthz

健康检查成功则会返回ok,检查失败则返回失败信息。

原理剖析

那么当Kubelet发起对Ingress Controller Pod的健康检查时,Nginx Ingress Controller内部到底做了什么,以及为什么是10254端口和/healthz路径,今天我们简单剖析下K8S Ingress Controller内部的健康检查逻辑。

1、10254 和 /healthz

首先,Nginx Ingress Controller在启动时会通过goroutine启动一个HTTP Server:

// 初始化一个 HTTP Request Handler
mux := http.NewServeMux()
go registerHandlers(conf.EnableProfiling, conf.ListenPorts.Health, ng

猜你喜欢

转载自www.cnblogs.com/ls123/p/9253952.html