8

I am trying to expose a kubernetes "deployment" via the kubectl expose command, wih a static IP address, on Google Container Engine.

With an ephemeral IP, everything works fine:

kubectl expose deployment my-application \
    --type="LoadBalancer" --port=80 --target-port=8080

I use kubectl get services and wait a few minutes to see the ephemeral IP having been assigned. I enter the IP in my browser and I see the applicaiton, i.e. everything works.

However, when I do the following:

  1. Create a static IP address using the gcloud web interface (Networking -> External IP addresses -> Reserve Static IP address)

  2. Re-create the service with the same command as above but with the extra --load-balancer-ip option

    kubectl expose deployment my-application \
        --type="LoadBalancer" --port=80 --target-port=8080 \
        --load-balancer-ip='1.2.3.4'   # IP as assigned by web interface above
    

The command is successful, but the application is not reachable under that IP address, and when I use the following command:

$ kubectl get services
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
endpoints    10.119.247.39   <pending>     80/TCP    23m
kubernetes   10.119.240.1    <none>        443/TCP   1d

I see that the EXTERNAL-IP is still <pending> although I've waited 23 minutes so far.

What am I doing wrong?

Adrian Smith
  • 276
  • 4
  • 9

1 Answers1

6

The command you provided worked for me. In a first attempt to exposed the service I used a static IP address defined in a different region from where the Load Balancer was being created. As a result the Load Balancer was not created and the service kept in a "Pending" state.

$ kubectl get services | grep node3
hello-node3   10.3.242.65    <pending>      80/TCP     1m
$kubectl get events  
48s        2m          5         hello-node3   Service               Normal    CreatingLoadBalancer         {service-controller }   Creating load balancer
47s        2m          5         hello-node3   Service               Warning   CreatingLoadBalancerFailed   {service-controller }   Error creating load balancer (will retry): Failed to create load balancer for service default/hello-node3: requested ip W.X.Y.Z is neither static nor assigned to LB a059cdb738ef911e6a83642010af001b(default/hello-node3): <nil>

Then I used an IP defined in us-central where my nodes lives.

kubectl expose deployment hello-node3 --type="LoadBalancer" --target-port=8080 --load-balancer-ip='A.B.C.D'

Then:

$ kubectl get services | grep node3
hello-node3   10.3.241.0     A.B.C.D   80/TCP     20m
$ curl A.B.C.D
Hello World!

I would suggest making sure the IP exists in the same region the cluster lives. If that fails, to obtain more information on the state by using kubectl get events. That might shed some light.

jeyanthinath
  • 103
  • 3
Carlos
  • 1,385
  • 8
  • 15