How to assign external IP address to running service?

4/13/2020

I have the following service:

NAME      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
rancher   ClusterIP   10.245.162.197   <none>        80/TCP    10h

that I would like to assign an EXTERNAL-IP to it. I tried:

kubectl expose deployment rancher --type=LoadBalancer --name=rancher-access

but the EXTERNAL-IP does not still get assigned. I am using Digital Ocean Kubernetes.
How to get an EXTERNAL-IP for rancher service.

-- zero_coding
digital-ocean
kubernetes

1 Answer

4/13/2020

You have two options:

  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 Digital Ocean's floating IP.

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
  1. Use Digital Ocean created cloud provider implementation

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

https://github.com/hobby-kube/guide#bringing-traffic-to-the-cluster

-- Arghya Sadhu
Source: StackOverflow