EKS loadbalancer created successfully with external ip but web app is unreachable on assigned port

44 views Asked by At

I am learning k8s with eksctl and used this to create a loadbalancer:

apiVersion: v1
kind: Service
metadata:
  name: lb
spec:
  type: LoadBalancer
  selector:
    app: lb
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000

it was created ok and kubectl get service/lb lists it as well a long aws domain name representing the external IP (let's call this <awsdomain>).

I then deployed my app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  namespace: default
  labels:
    app: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: <account-id>.dkr.ecr.<region>.amazonaws.com/myapp:latest
          ports:
            - containerPort: 3000

I did kubectl apply -f deployment.yml and that also seems to have worked. However, when I go to my browser, http://<awsdomain>:3000 doesn't return anything :(

Is there another resource I'm supposed to create? Thanks.

2

There are 2 answers

0
gohm'c On BEST ANSWER

Your service selector will not select any pod. Try:

apiVersion: v1
kind: Service
metadata:
  name: lb
spec:
  type: LoadBalancer
  selector:
    app: myapp    # <-- change to match the pod template
...
2
Mehdi On

I think you should try port 80 instead of 3000. Those ports you set are for the K, not for AWS infrastructure. AWS LB is on port 80.

Use "k get svc" and it should give you the external address which it should be available. And It must be on port 80.