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=''   # 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
endpoints   <pending>     80/TCP    23m
kubernetes    <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?


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


$ kubectl get services | grep node3
hello-node3     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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.