kubernetes - GCP GKE - 具有 2 个暴露端口的同一应用程序的原生 GKE 入口的健康检查
问题描述
我有一个应该公开 2 个端口的应用程序,并且该应用程序没有/
返回的默认运行状况检查端点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) 并为两个端口使用自定义运行状况检查端点?
解决方案
有一个称为GKE Ingress 的功能FrontendConfig
和BackendConfig
自定义资源定义 (CRD),可让您进一步自定义负载均衡器,您可以使用Unique BackendConfig per Service 端口BackendConfig
来为服务的特定端口或端口指定自定义,或者MultiClusterService
使用与端口名称或端口号匹配的密钥。Ingress 控制器在BackendConfig
为引用的服务端口创建负载均衡器后端服务时使用特定的
使用 aBackendConfig
提供自定义负载均衡器健康检查时,您用于负载均衡器健康检查的端口号可能与 Service 的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
推荐阅读
- android - Parse-SDK-Android:parse:1.24.0 有修复吗
- python - 相对 import_module 不知道包含包的名称
- outlook-addin - 调用方法需要提升权限:'mailbox.getUserIdentityToken'
- jekyll - kernel_require.rb 无法加载此类文件 jekyll
- dotnetnuke - 将 DNN (DotNetNuke) 迁移到 Godaddy Plesk
- acumatica - 如何使用 put 在 acumatica 中上传照片
- google-dfp - 亚马逊与 prebid 并行使用更简单的 GPT 和刷新
- reactjs - 在 UIManager 中找不到 RNCSafareAreaView
- api - 如何使用 YouTube 数据 API
- flutter - 如何从自定义绘画中保存图像?