You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Teleport至Kubernetes后出现502 Bad Gateway问题求助

问题:Teleport集群K8s部署遇502 Bad Gateway及SSL证书异常

背景

我在Kubernetes集群部署Teleport集群,用Route53将域名流量路由到Application Load Balancer(ALB)。同集群内其他应用的Ingress都正常,但执行官方文档里的curl https://teleport.example.com/webapi/ping时,返回502 Bad Gateway错误:

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>

部署配置

Helm安装命令

helm install teleport --set acme=true --set acmeEmail=<我的邮箱地址> --set clusterName=teleport.example.com --set service.type=ClusterIP teleport/teleport-cluster

Ingress配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: teleport
  namespace: telport-cluster
  annotations:
    alb.ingress.kubernetes.io/certificate-arn: <证书ARN>
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/ssl-redirect: "443"
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.name: <Ingress组名称>
spec:
  ingressClassName: alb
  rules:
  - host: teleport.example.com
    http:
      paths:
      - backend:
          service:
            name: teleport
            port:
              number: 443
        path: /
        pathType: Prefix
  - host: '*.teleport.example.com'
    http:
      paths:
      - backend:
          service:
            name: teleport-cluster
            port:
              number: 443
        path: /
        pathType: Prefix

更新排查信息

  • 直接curl服务端点curl -k https://10.0.1.96:3080/webapi/ping能得到预期结果,但不加-k无法访问;
  • 进入Pod内执行curl -k https://teleport.teleport.svc.cluster.local:443/webapi/ping返回跳转信息,移除-k则提示SSL证书自签名问题。

排查与解决步骤

一、先解决502 Bad Gateway问题

502一般是ALB和后端服务的通信链路出了问题,结合你的配置,重点查这几个点:

  1. Ingress服务与端口的匹配错误

    • 你的Ingress里,teleport.example.com指向teleport:443,*.teleport.example.com指向teleport-cluster:443。先确认集群里这两个服务是否存在,端口映射是否正确:
      执行kubectl get svc -n telport-cluster,重点看服务的TARGET PORT是否对应Teleport Pod实际监听的端口。Teleport默认容器监听3080(HTTPS),如果服务把targetPort设成了443而非3080,ALB的请求根本打不通Pod,直接返回502。
  2. ALB与后端的SSL验证失败

    • ALB通过HTTPS转发请求到后端443端口,但后端Pod用的是自签名证书,ALB默认会强制验证后端证书的合法性,验证不通过就会返回502。
    • 临时解决:给Ingress添加注解跳过后端证书验证:
      alb.ingress.kubernetes.io/backend-protocol: HTTPS
      # 关键注解:关闭后端证书验证
      alb.ingress.kubernetes.io/backend-auth-scheme: none
      # 补充健康检查配置,避免ALB误判服务不健康
      alb.ingress.kubernetes.io/healthcheck-protocol: HTTPS
      alb.ingress.kubernetes.io/healthcheck-port: traffic-port
      
    • 更稳妥的方案:让ALB用HTTP和后端通信,把Ingress里的后端端口改成Teleport的HTTP端口(默认3023),同时添加注解alb.ingress.kubernetes.io/backend-protocol: HTTP。

二、解决SSL证书相关问题

你的场景涉及两层SSL:ALB对外的公网证书(你配置的ACM证书),以及Teleport Pod内部的服务证书。

  1. 外部访问无需-k的解决

    • ALB对外的证书已经配置正确,但因为ALB和后端通信时证书验证失败导致502,只要解决了ALB和后端的通信问题,外部访问https://teleport.example.com就不需要加-k了。
  2. Teleport内部证书异常的修复

    • 你用了acme=true的Helm参数,理论上Teleport会通过cert-manager自动申请Let's Encrypt证书,但目前Pod用的是自签名证书,说明证书流程没走通:
      • 先确认集群里已安装cert-manager(版本建议v1.13及以上),如果没装,用官方yaml部署即可。
      • 检查证书资源状态:kubectl get certificates -n telport-cluster,看是否有状态为Ready的证书。
      • 如果cert-manager正常,检查域名解析是否生效:确保teleport.example.com已经指向ALB,Let's Encrypt能通过HTTP01或DNS01验证域名所有权。

三、快速验证流程

  1. 先调整Ingress的后端端口:把teleport服务的端口从443改成3080,同时更新Ingress里的端口配置。
  2. 添加ALB的后端协议注解,比如用HTTP通信就加alb.ingress.kubernetes.io/backend-protocol: HTTP,先让502错误消失。
  3. 确认cert-manager正常运行后,重新更新Helm部署:helm upgrade teleport teleport/teleport-cluster --reuse-values,触发证书重新申请。

内容的提问来源于stack exchange,提问作者floormind

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:28:10