Clyde Barrow
Clyde Barrow

Reputation: 2102

GKE - how to attach static ip to internal load balancer

I want to connect service from one GKE cluster to another one. I created service as a internal load balancer and I would like to attach a static ip to it. I created my service.yml

apiVersion: v1
kind: Service
metadata:
  name: ilb-service
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
    kubernetes.io/ingress.global-static-ip-name: es-test
  labels:
    app: hello
spec:
  type: LoadBalancer
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP

However after apply -f when I check the service the load balancer ingress looks like this:

status:
  loadBalancer:
    ingress:
    - ip: 10.156.0.60

And I cannot connect using the static ip. How to solve it ?

EDIT:

After suggestion I changed the yml file to:
apiVersion: v1
kind: Service
metadata:
  name: ilb-service
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: hello
spec:
  type: LoadBalancer
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  loadBalancerIP: "xx.xxx.xxx.xxx" -- here my static ip

Service now looks like it:

spec:
  clusterIP: 11.11.1.111
  externalTrafficPolicy: Cluster
  loadBalancerIP: xx.xxx.xxx.xxx
  ports:
  - nodePort: 31894
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: hello
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer: {}

And I still cannot connect

Upvotes: 13

Views: 15153

Answers (2)

Abhishek
Abhishek

Reputation: 1230

I had the same issue, and was continuously getting below error

Service event error

Warning  SyncLoadBalancerFailed  0s (x6 over 18s)   loadbalancer-controller
Error syncing load balancer: failed to get address by IP "x.x.x.100" after
reservation attempt, err: "googleapi: Error 404: Address with IP
\"x.x.x.100\" was not found in region \"europe-west1\"", reservation err:
"googleapi: Error 409: IP_IN_USE_BY_ANOTHER_RESOURCE - IP 'x.x.x.100' is
already being used by another resource."

Like me, if you're using Shared VPC, Create the Static IP in the service project and not on the host project.

That's the only difference from the previous answer. For more details refer Reserve a Static Internal IP while using Shared VPC

Upvotes: 2

Alex Ulyanov
Alex Ulyanov

Reputation: 339

November 2021 Update

It is possible to create a static internal IP and assign it to a LoadBalancer k8s service type.

  1. Go to the VPC networks -> Select your VPC -> Static Internal IP Addresses
  2. Click Reserve Static Address, then select a name for your IP and click Reserve. You can choose IP address manually here as well.
  3. In your Service YAML add the following annotation. Also make sure type is LoadBalancer and then assign the IP address.
...
annotations: 
  networking.gke.io/load-balancer-type: "Internal"
...
type: LoadBalancer
loadBalancerIP: <your_static_internal_IP>

This will spin up an internal LB and assign your static IP to it. You can also check in Static Internal IP Addresses screen that new IP is now in use by freshly created load balancer. You can assign a Cloud DNS record to it, if needed. Also, you can choose IP address "shared" during the reservation process so it can be used by up to 50 internal load balancers.

Assigning Static IP to Internal LB

Enabling Shared IP

Upvotes: 14

Related Questions