我有一个应该公开 2 x 端口的应用程序,但该应用程序没有返回 /
的默认健康检查端点 200
,因此目前,我提供了一个自定义健康检查端点仅用于 1 个端口。我还没有公开另一个端口,因为我不知道如何为同一个应用程序提供另一个自定义健康检查端点。
这就是我的 Terraform 配置的样子。
resource "kubernetes_deployment" "core" {
metadata {
name = "core"
labels = {
app = "core"
}
}
spec {
replicas = 1
selector {
match_labels = {
app = "core"
}
}
template {
metadata {
labels = {
app = "core"
}
}
spec {
container {
name = "core"
image = "asia.gcr.io/admin/core:${var.app_version}"
port {
container_port = 8069
}
readiness_probe {
http_get {
path = "/web/database/selector"
port = "8069"
}
initial_delay_seconds = 15
period_seconds = 30
}
image_pull_policy = "IfNotPresent"
}
}
}
}
}
resource "kubernetes_service" "core_service" {
metadata {
name = "core-service"
}
spec {
type = "NodePort"
selector = {
app = "core"
}
port {
port = 8080
protocol = "TCP"
target_port = "8069"
}
}
}
如何告诉 GKE 公开另一个端口 (8072) 并为两个端口使用自定义运行状况检查端点?
答案 0 :(得分:1)
有一个名为 FrontendConfig
和 BackendConfig
GKE Ingress feature 的 custom resource definitions (CRDs) 允许您进一步自定义负载均衡器,您可以使用 Unique BackendConfig per Service port 指定一个使用与端口名称或端口号匹配的密钥为服务的特定端口或 BackendConfig
自定义 MultiClusterService
。 Ingress 控制器在为引用的服务端口创建负载均衡器后端服务时使用特定的 BackendConfig
当使用 BackendConfig
提供 custom load balancer health check 时,您用于负载平衡器运行状况检查的端口号可能与服务的 spec.ports[].port
号不同,以下是该服务的示例和自定义健康检查:
服务:
apiVersion: v1
kind: Service
metadata:
annotations:
cloud.google.com/backend-config: '{"ports": {
"service-reference-a":"backendconfig-reference-a",
"service-reference-b":"backendconfig-reference-b"
}}'
spec:
ports:
- name: port-name-1
port: port-number-1
protocol: TCP
targetPort: 50000
- name: port-name-2
port: port-number-2
protocol: TCP
targetPort: 8080
自定义健康检查:
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
name: my-backendconfig
spec:
healthCheck:
checkIntervalSec: interval
timeoutSec: timeout
healthyThreshold: health-threshold
unhealthyThreshold: unhealthy-threshold
type: protocol
requestPath: path
port: port