How to specify static IP address for Kubernetes load balancer?

大憨熊 提交于 2019-11-28 22:51:44

Kubernetes v1.1 will make a few changes.

First, all load-balancers in GCE will get static IPs. This allows us to simulate "update" operations that GCE does not support.

Second, https://github.com/kubernetes/kubernetes/pull/13005 proposes a new field to explicitly set the IP of a load balancer.

Note though that your "ephemeral" IP is yours as long as your Service exists. This is roughly akin to what AWS does with ELB names (randomly assigned, yours until you release it).

publicIPs (or deprecatedPublicIPs in v1) will be replaced with externalIPs with very similar semantics. These are "unmanaged" IPs - kubernetes will not establish a load-balancer using them, but it will accept traffic for them.

clusterIP is an in-cluster address and generally is not available outside of the cluster or "project" or VPC (in GCE or AWS terms)

TL;DR Google Container Engine running Kubernetes v1.1 supports loadBalancerIP just mark the auto-assigned IP as static first.

Kubernetes v1.1 supports externalIPs:

apiVersion: v1
kind: Service
spec:
  type: LoadBalancer
  loadBalancerIP: 10.10.10.10
  ...

So far there isn't a really good consistent documentation on how to use it on GCE. What is sure is that this IP must first be one of your pre-allocated static IPs.

The cross-region load balancing documentation is mostly for Compute Engine and not Kubernetes/Container Engine, but it's still useful especially the part "Configure the load balancing service".

If you just create a Kubernetes LoadBalancer on GCE, it will create a network Compute Engine > Network > Network load balancing > Forwarding Rule pointing to a target pool made of your machines on your cluster (normally only those running the Pods matching the service selector). It looks like deleting a namespace doesn't nicely clean-up the those created rules.


Update

It is actually now supported (even though under documented):

  1. Check that you're running Kubernetes 1.1 or later (under GKE edit your cluster and check "Node version")
  2. Allocate static IPs under Networking > External IP addresses, either:
    • Deploy once without loadBalancerIP, wait until you've an external IP allocated when you run kubectl get svc, and look up that IP in the list on that page and change those from Ephemeral to Static.
    • Click "Reserver a static address" regional in the region of your cluster, attached to None.
  3. Edit your LoadBalancer to have loadBalancerIP=10.10.10.10 as above (adapt to the IP that was given to you by Google).

Now if you delete your LoadBalancer or even your namespace, it'll preserve that IP address upon re-reploying on that cluster.


Update 2016-11-14

See also Kubernetes article describing how to set up a static IP for single or multiple domains on Kubernetes.

If you are running on Google Container Engine, and are using type: LoadBalancer, then Google Cloud Platform should have made a Network Load Balancer for you with a static IP address that will route to this service. You don't need to specify any IP addresses.

To find the network load balancer's IP, run:

gcloud compute forwarding-rules list --project "YOUR-PROJECT-ID"

You should also be able to run:

kubectl get services

Which will return both the cluster and external IP and port for your services.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!