Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set static external IP for my load balancer on GKE

I am trying to set up a static external IP for my load balancer on GKE but having no luck. Here is my Kubernetes service config file:

kind: Service
apiVersion: v1
metadata:
  name: myAppService
spec:
  selector:
    app: myApp
  ports:
  - protocol: TCP
    port: 3001
    targetPort: 3001
  type: LoadBalancer
  loadBalancerIP: *********

This doesn't work. I expect to see my external IP as ********* but it just says pending:

➜  git:(master) kubectl get services
NAME         CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes   *********    <none>        443/TCP          5m
myAppService   *********   <pending>     3001:30126/TCP   5m

More details:

➜  git:(master) kubectl describe services
Name:           kubernetes
Namespace:      default
Labels:         component=apiserver
            provider=kubernetes
Annotations:        <none>
Selector:       <none>
Type:           ClusterIP
IP:         *********
Port:           https   443/TCP
Endpoints:      *********
Session Affinity:   ClientIP
Events:         <none>


Name:           myAppService
Namespace:      default
Labels:         <none>
Annotations:        <none>
Selector:       app=myApp
Type:           LoadBalancer
IP:         *********
Port:           <unset> 3001/TCP
NodePort:       <unset> 30126/TCP
Endpoints:
Session Affinity:   None
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath   Type        Reason              Message
  --------- --------    -----   ----            -------------   --------    ------              -------
  5m        20s     7   service-controller          Normal      CreatingLoadBalancer        Creating load balancer
  5m        19s     7   service-controller          Warning     CreatingLoadBalancerFailed  Error creating load balancer (will retry): Failed to create load balancer for service default/myAppService: Cannot EnsureLoadBalancer() with no hosts

Any ideas?

like image 521
jcgh582 Avatar asked Oct 26 '17 02:10

jcgh582


People also ask

How can you get a static IP for a Kubernetes load balancer?

To create a LoadBalancer service with the static public IP address, add the loadBalancerIP property and the value of the static public IP address to the YAML manifest. Create a file named load-balancer-service. yaml and copy in the following YAML. Provide your own public IP address created in the previous step.


1 Answers

I've encountered the same problem, but after reading the docs carefully, it turned out that I was just reserving the static IP incorrectly. A service of type LoadBalancer creates a network load balancer, which is regional. Therefore, also the static IP address you reserve needs to be regional also (in the regoin of your cluster). When I changed to this solution, everything worked fine for me...

like image 83
Dirk Jablonski Avatar answered Sep 27 '22 20:09

Dirk Jablonski