【问题标题】:How can i expose my nginx EKS cluster to the world?如何向世界公开我的 nginx EKS 集群?
【发布时间】:2026-01-12 21:00:01
【问题描述】:

我正在尝试在 eks 集群上部署此基本 nginx 映像,但在尝试访问公共 IP 时似乎无法访问它。 我正在使用官方 EKS 模块并进行以下设置:

我还使用 k8s 提供程序进行了此部署设置:


resource "kubernetes_deployment" "helloworld" {
    metadata {
       name = "helloworld"
    }
    spec {
      replicas = 2
      selector {
        match_labels = {
          app = "helloworld"
        } 
      }
      template {
        metadata {
          labels = {
            app = "helloworld"
          }
        }
        spec {
          container {
            name = "nginx"
            image = "nginx"
            port {
              container_port = 80 
            }
          } 
        }  
      } 
    }
}

resource "kubernetes_service" "example" {
  metadata {
    name = "helloworld"
  }
  spec {
    selector = {
      app = "helloworld"
    }
    session_affinity = "ClientIP"
    port {
      port        = 8080
      target_port = 80
    }

    type = "NodePort"
  }
}

当我去检查kubectl describe pods时,我被告知服务无法访问:

我在这里错过了什么?

【问题讨论】:

  • 分享描述 pod 截图或细节,而不是用自己的话。
  • @HarshManvar 我添加了更新截图
  • 您是如何尝试访问该服务的?所以使用 terraform pod 被部署但之后面临问题是这样吗?你试过 :

标签: amazon-web-services kubernetes terraform


【解决方案1】:

在尝试访问公共 IP 时到达它

使用负载均衡器服务公开您的 nginx:

kubectl expose deployment helloworld --port 80 --target-port 80 --name helloworld-service --type LoadBalancer

获取外部IP:

kubectl get services helloworld-service

执行curl <external IP>,你的 helloworld nginx 应该会响应你。

【讨论】:

  • 谢谢!这些服务类型把我搞糊涂了哈哈