Home > Net >  Cannot reach nginx on EKS cluster
Cannot reach nginx on EKS cluster

Time:11-17

I am trying to deploy this basic nginx image on an eks cluster but cannot seem to reach it when trying to hit the public IP. I am using the official EKS module and have this setup: enter image description here

I also have this deployment setup using the k8s provider:


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"
  }
}

When i go to check kubectl describe pods i am told that the service is unreachable:

enter image description here

what am i missing here?

CodePudding user response:

to reach it when trying to hit the public IP

Expose your nginx with a load balancer service:

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

Get the external IP:

kubectl get services helloworld-service

Do a curl <external IP> and your helloworld nginx should response to you.

  • Related