Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign an External IP to a Node

Tags:

kubernetes

I'm running a bare metal Kubernetes cluster and trying to use a Load Balancer to expose my services. I know typically that the Load Balancer is a function of the underlying public cloud, but with recent support for Ingress Controllers it seems like it should now be possible to use nginx as a self-hosted load balancer.

So far, i've been following the example here to set up an nginx Ingress Controller and some test services behind it. However, I am unable to follow Step 6 which displays the external IP for the node that the load balancer is running on as my node does not have an ExternalIP in the addresses section, only a LegacyHostIP and InternalIP.

I've tried manually assigning an ExternalIP to my cluster by specifying it in the service's specification. However, this appears to be mapped as the externalID instead.

How can I manually set my node's ExternalIP address?

like image 693
KingJ Avatar asked Oct 15 '16 12:10

KingJ


People also ask

Does NodePort have external IP?

The administrator must ensure the external IPs are routed to the nodes and local firewall rules on all nodes allow access to the open port. NodePorts and external IPs are independent and both can be used concurrently.


2 Answers

This is something that is tested and works for an nginx service created on a particular node.

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: default
spec:
    ports:
    -   port: 80
        protocol: TCP
        targetPort: 80
        name: http
    -   port: 443
        protocol: TCP
        targetPort: 443
        name: https
    externalIPs:
      - '{{external_ip}}'
    selector:
        app: nginx

Assumes an nginx deployment upstream listening on port 80, 443. The externalIP is the public IP of the node.

like image 147
iamnat Avatar answered Sep 19 '22 20:09

iamnat


I would suggest checking out MetalLB: https://github.com/google/metallb

It allows for externalIP addresses in a baremetal cluster using either ARP or BGP. It has worked great for us and allows you to simply request a LoadBalancer service like you would in the cloud.

like image 21
adam wilhelm Avatar answered Sep 20 '22 20:09

adam wilhelm