GKE LoadBalancer Static IP

1/6/2020

I created a regional static IP in the same region of the cluster and I'm trying to use it with a LoadBalancer:

---
apiVersion: v1
kind: Service
metadata:
  name: ambassador
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  ports:
   - port: 80
     targetPort: 8080
  selector:
    service: ambassador
  loadBalancerIP: "x.x.x.x"

However, I don't know why I am getting this error:

Error creating load balancer (will retry): failed to ensure load balancer for service default/ambassador: requested ip "x.x.x.x" is neither static nor assigned to the LB   

Edit: Problem solved but ..

When I created the static IP address, I used:

gcloud compute addresses create regional-ip --region  europe-west1

I used this address with the Service. It didn't work like I said.

However, when I created an external static regional IP using the web console, the IP worked fine with my Service and it was attached without problems.

-- 4m1nh4j1
gke-networking
google-kubernetes-engine
kubernetes
load-balancing

1 Answer

1/6/2020

My bet is that the source IP service is not exposed then. As the official docs say:

As of Kubernetes 1.5, packets sent to Services with Type=LoadBalancer are source NAT’d by default, because all schedulable Kubernetes nodes in the Ready state are eligible for loadbalanced traffic. So if packets arrive at a node without an endpoint, the system proxies it to a node with an endpoint, replacing the source IP on the packet with the IP of the node (as described in the previous section).

Try this command to expose the source IP service to the loadbalancer:

kubectl expose deployment <source-ip-app> --name=loadbalancer --port=80 --target-port=8080 --type=LoadBalancer

On this page, you will find more guidance and a number of diagnostic commands for sanity check.

https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-loadbalancer

-- Nice-Guy
Source: StackOverflow