kubernetesamazon-ekseksctl

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


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.


Solution

  • 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
    ...