Kubernetes External Load Balancer Service on DigitalOcean

狂风中的少年 提交于 2019-12-03 13:08:02

问题


I'm building a container cluster using CoreOs and Kubernetes on DigitalOcean, and I've seen that in order to expose a Pod to the world you have to create a Service with Type: LoadBalancer. I think this is the optimal solution so that you don't need to add external load balancer outside kubernetes like nginx or haproxy. I was wondering if it is possible to create this using DO's Floating IP.


回答1:


The LoadBalancer type of service is implemented by adding code to the kubernetes master specific to each cloud provider. There isn't a cloud provider for Digital Ocean (supported cloud providers), so the LoadBalancer type will not be able to take advantage of Digital Ocean's Floating IPs.

Instead, you should consider using a NodePort service or attaching an ExternalIP to your service and mapping the exposed IP to a DO floating IP.




回答2:


Things have changed, DigitalOcean created their own cloud provider implementation as answered here and they are maintaining a Kubernetes "Cloud Controller Manager" implementation:

Kubernetes Cloud Controller Manager for DigitalOcean

Currently digitalocean-cloud-controller-manager implements:

  • nodecontroller - updates nodes with cloud provider specific labels and addresses, also deletes kubernetes nodes when deleted on the cloud provider.

  • servicecontroller - responsible for creating LoadBalancers when a service of Type: LoadBalancer is created in Kubernetes.

To try it out clone the project on your master node.

Next get the token key from https://cloud.digitalocean.com/settings/api/tokens and run:

export DIGITALOCEAN_ACCESS_TOKEN=abc123abc123abc123
scripts/generate-secret.sh
kubectl apply -f do-cloud-controller-manager/releases/v0.1.6.yml

There more examples here

What will happen once you do the above? DO's cloud manager will create a load balancer (that has a failover mechanism out of the box, more on it in the load balancer's documentation

Things will change again soon as DigitalOcean are jumping on the Kubernetes bandwagon, check here and you will have a choice to let them manage your Kuberentes cluster instead of you worrying about a lot of the infrastructure (this is my understanding of the service, let's see how it works when it becomes available...)




回答3:


It is actually possible to expose a service through a floating ip. The only catch is that the external IP that you need to use is a little unintuitive.

From what it seems DO has some sort of overlay network for their Floating IP service. To get the actual IP you need to expose you need to ssh into your gateway droplet and find its anchor IP by hitting up the metadata service:

curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address

and you will get something like

10.x.x.x

This is the address that you can use as an external ip in LoadBalancer type service in kubernetes.

Example:

kubectl expose rc my-nginx --port=80 --public-ip=10.x.x.x --type=LoadBalancer


来源:https://stackoverflow.com/questions/35884643/kubernetes-external-load-balancer-service-on-digitalocean

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