Set static external IP for my load balancer on GKE

10/26/2017

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?

-- jcgh582
google-kubernetes-engine
kubernetes

3 Answers

3/6/2019

This got me stuck as well, I hope someone finds this helpful.

In addition to what Dirk said, if you happen to reserve a global static IP address as oppose to a regional one; you need to use Ingres as describe here in documentation: Configuring Domain Names with Static IP Addresses specifically step 2b.

So basically you reserve the static ip gcloud compute addresses create helloweb-ip --global

and add an Ingres:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: helloweb
# this is where you you add your reserved ip
  annotations:
    kubernetes.io/ingress.global-static-ip-name: helloweb-ip 
  labels:
    app: hello
spec:
  backend:
    serviceName: helloweb-backend
    servicePort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: helloweb-backend
  labels:
    app: hello
spec:
  type: NodePort
  selector:
    app: hello
    tier: web
  ports:
  - port: 8080
    targetPort: 8080

The doc also describe how to assign a static ip if you choose type "LoadBalancer" under step 2a.

-- chriz
Source: StackOverflow

7/13/2018

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

-- Dirk Jablonski
Source: StackOverflow

10/26/2017

After a time consuming search through unnecessarily complicated and long documentation, this simple blog solved my problem: http://terrenceryan.com/blog/index.php/making-kubernetes-ip-addresses-static-on-google-container-engine/

-- jcgh582
Source: StackOverflow