KingJ
KingJ

Reputation: 245

Assign an External IP to a Node

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?

Upvotes: 14

Views: 21101

Answers (3)

Arne Winter
Arne Winter

Reputation: 13

While Services should generally be used, for severe edge cases it is worth to mention that k3s supports the --node-external-ip command line parameter. running kubectl get nodes -o wide will have the external-ip record populated.

Upvotes: 0

adam wilhelm
adam wilhelm

Reputation: 159

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.

Upvotes: 6

iamnat
iamnat

Reputation: 4166

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.

Upvotes: 8

Related Questions