GKE Load Balancer Connection Refused

11/5/2019

I am trying to set up my app on GKE and use an internal load balancer for public access. I am able to deploy the cluster / load balancer service without any issues, but when I try to access the external ip address of the load balancer, I get Connection Refused and I am not sure what is wrong / how to debug this.

These are the steps I did:

I applied my deployment yaml file via kubectl apply -f file.yaml then after, I applied my load balancer service yaml file with kubectl apply -f service.yaml. After both were deployed, I did kubectl get service to fetch the External IP Address from the Load Balancer.

Here is my deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app-api
          image: gcr.io/...
          ports:
            - containerPort: 8000
          resources:
            requests:
              memory: "250M"
              cpu: "250m"
            limits:
              memory: "1G"
              cpu: "500m"
        - name: my-app
          image: gcr.io/...
          ports:
            - containerPort: 3000
          resources:
            requests:
              memory: "250M"
              cpu: "250m"
            limits:
              memory: "1G"
              cpu: "500m"

and here is my service.yaml file:

apiVersion: v1
kind: Service
metadata:
  name: my-app-ilb
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: my-app-ilb
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
  - port: 3000
    targetPort: 3000
    protocol: TCP

My deployment file has two containers; a backend api and a frontend. What I want to happen is that I should be able to go on [external ip address]:3000 and see my web app.

I hope this is enough information; please let me know if there is anything else I may be missing / can add.

Thank you all!

-- kennycodes
google-cloud-platform
google-kubernetes-engine
kubernetes
load-balancing
networking

1 Answer

11/5/2019

You need to allow traffic to flow into your cluster by creating firewall rule.

gcloud compute firewall-rules create my-rule --allow=tcp:3000

Remove this annotation :

  annotations:
    cloud.google.com/load-balancer-type: "Internal"

You need external Load Balancer.

-- fg78nc
Source: StackOverflow