Kubernetes External Load Balancer Service on DigitalOcean
Asked Answered
A

3

9

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.

Archaism answered 9/3, 2016 at 6:37 Comment(0)
M
5

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.

Maritsa answered 9/3, 2016 at 7:7 Comment(3)
So does this mean that I have to create an external load balancer outside the kubernetes cluster?Archaism
NodePorts are designed to be used with load balancers outside of the cluster. The Loadbalancer type helps automate the configuration of external load balancers on supported cloud platforms. Since it looks like Digital Ocean may not offer load balancers, you can also look at using ExternalIPs and mapping the exposed IP to a DO floating IP.Maritsa
You could use an NGINX ingress controller and point a DigitalOcean LB to the host where the controller is deployed. With some more tinkering you could probably make this a highly available setup. Reference: github.com/hobby-kube/guide#bringing-traffic-to-the-clusterNeopythagoreanism
M
9

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

Midriff answered 9/7, 2018 at 13:30 Comment(0)
M
5

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.

Maritsa answered 9/3, 2016 at 7:7 Comment(3)
So does this mean that I have to create an external load balancer outside the kubernetes cluster?Archaism
NodePorts are designed to be used with load balancers outside of the cluster. The Loadbalancer type helps automate the configuration of external load balancers on supported cloud platforms. Since it looks like Digital Ocean may not offer load balancers, you can also look at using ExternalIPs and mapping the exposed IP to a DO floating IP.Maritsa
You could use an NGINX ingress controller and point a DigitalOcean LB to the host where the controller is deployed. With some more tinkering you could probably make this a highly available setup. Reference: github.com/hobby-kube/guide#bringing-traffic-to-the-clusterNeopythagoreanism
M
2

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
Mcgill answered 20/5, 2016 at 8:2 Comment(1)
I am getting a "Error: unknown flag: --public-ip" with k8s 1.5.2Equipage

© 2022 - 2024 — McMap. All rights reserved.