K3S集群Istio、MetalLB与CertManager的HTTPS路由故障求助
Istio Gateway HTTPS访问出现ERR_CONNECTION_RESET故障排查(K3S+MetalLB+CertManager环境)
问题描述
在单公网IP的K3S集群(基于VPS搭建)中配置Istio、MetalLB与CertManager时遇到以下问题:
- 服务商无负载均衡服务,使用MetalLB绑定公网IP暴露Istio-ingressgateway
- 集群划分dev、qa、prod三个业务命名空间,已在DNS服务商配置域名指向公网IP
- 通过CertManager的Issuer为不同环境获取Let's Encrypt证书(dev/qa用staging API,prod用正式API),证书已正常签发
- Istio Gateway可正常路由80端口的HTTP流量,但启用443端口HTTPS时,访问报
ERR_CONNECTION_RESET错误,无法正常访问 - 业务应用仅通过80端口提供HTTP服务
相关配置文件
Deployment配置
apiVersion: apps/v1 kind: Deployment metadata: name: hello-v1 spec: replicas: 3 selector: matchLabels: app: hello-v1 template: metadata: labels: app: hello-v1 spec: containers: - name: hello image: pablin.dynu.net:5000/chevaca/chevacaweb:latest imagePullPolicy: IfNotPresent ports: - containerPort: 80 resources: requests: memory: "64Mi" cpu: "200m" limits: memory: "128Mi" cpu: "500m"
Service配置(chevaca-qa命名空间)
kind: Service apiVersion: v1 metadata: name: hello-v1-svc namespace: chevaca-qa spec: selector: app: hello-v1 ports: - protocol: TCP port: 80 targetPort: 80
Istio Gateway配置(chevaca-qa命名空间)
apiVersion: networking.istio.io/v1beta1 kind: Gateway metadata: name: qa-app-gateway namespace: chevaca-qa spec: selector: istio: ingressgateway servers: - port: name: http number: 80 protocol: HTTP hosts: - qa-app.chevaca.com - port: name: https number: 443 protocol: HTTPS tls: mode: SIMPLE credentialName: front-cert hosts: - qa-app.chevaca.com
Istio VirtualService配置(chevaca-qa命名空间)
apiVersion: networking.istio.io/v1beta1 kind: VirtualService metadata: name: front-app namespace: chevaca-qa spec: hosts: - qa-app.chevaca.com gateways: - qa-app-gateway http: - route: - destination: host: hello-v1-svc port: number: 80
排查步骤与解决方案
1. 检查MetalLB对443端口的暴露情况
确认Istio-ingressgateway的Service类型为LoadBalancer,且MetalLB已分配公网IP,同时Service的ports中包含443端口映射:
kubectl get svc istio-ingressgateway -n istio-system
若输出中缺失443端口的映射,需修改Istio-ingressgateway的Service配置,添加443端口的定义。
2. 验证证书Secret的命名空间与权限
CertManager签发的证书Secret(front-cert)需满足以下条件:
- 存在于Istio-ingressgateway所在的命名空间(默认
istio-system);或Istio版本在1.10及以上,可通过命名空间/Secret名称的格式跨命名空间引用 - 检查Secret是否存在:
kubectl get secret front-cert -n istio-system - 若Secret在
chevaca-qa命名空间,可选择:- 修改Gateway的
tls.credentialName为chevaca-qa/front-cert - 或复制Secret到
istio-system命名空间:kubectl get secret front-cert -n chevaca-qa -o yaml | sed 's/namespace: chevaca-qa/namespace: istio-system/' | kubectl apply -f -
- 修改Gateway的
3. 检查Istio-ingressgateway的证书加载日志
查看IngressGateway Pod的日志,确认是否存在证书加载失败的错误:
kubectl logs -l istio=ingressgateway -n istio-system | grep -i "cert"
若出现证书找不到、权限不足等错误,需确认Secret格式正确(包含tls.crt和tls.key字段),且Pod拥有读取该Secret的权限。
4. 验证VPS防火墙与端口放行
- 确认VPS本地防火墙(如ufw、iptables)已放行443端口:
sudo ufw allow 443/tcp # 或使用iptables规则 sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT - 若为云VPS,需同步检查云服务商安全组是否开放443端口的入站流量。
5. 优化Gateway的TLS配置(可选)
针对Let's Encrypt证书,可明确指定TLS协议版本,避免兼容性问题:
tls: mode: SIMPLE credentialName: front-cert minProtocolVersion: TLSV1_2 maxProtocolVersion: TLSV1_3
6. 确认VirtualService与Gateway的关联有效性
验证VirtualService的gateways字段是否正确引用了Gateway名称,且两者在同一命名空间(或Gateway为集群级):
kubectl get gateway qa-app-gateway -n chevaca-qa -o yaml kubectl get virtualservice front-app -n chevaca-qa -o yaml
内容的提问来源于stack exchange,提问作者user15025104
相关产品推荐
相关产品推荐

