DEV Community

chauhoangminhnguyen
chauhoangminhnguyen

Posted on • Originally published at howtodevez.blogspot.com

Setting Up an EXTERNAL-IP for Local LoadBalancer Service

Introduction

If you've used a LoadBalancer service from a Cloud Provider, you'll know how convenient it is to have an EXTERNAL-IP assigned automatically. However, when using local Kubernetes, the default setting doesn't provide an EXTERNAL-IP. Building on our previous discussion, this guide will show you how to use cloud-provider-kind to assign an EXTERNAL-IP to your local LoadBalancer service.

First, make sure you've set up your local Kubernetes using Kind as outlined in my previous guide. This is necessary to proceed with the next steps.

Local Load Balancer

Installing cloud-provider-kind

Since this is a Go package, you'll need to install Go first. Then, you can install the package with the following steps:

go install sigs.k8s.io/cloud-provider-kind@latest
Enter fullscreen mode Exit fullscreen mode

Then execute command to use:

cloud-provider-kind
Enter fullscreen mode Exit fullscreen mode

Keep in mind that you need to keep the terminal running while using Kubernetes to create the EXTERNAL-IP.

Testing with local EXTERNAL-IP

Create a deployment and expose a LoadBalancer service to check if the EXTERNAL-IP has been generated.

kubectl create deploy whoami --image traefik/whoami
kubectl expose deploy whoami --port 80 --type LoadBalancer
Enter fullscreen mode Exit fullscreen mode

The results will be as follows:
kubectl get all

You can access the EXTERNAL-IP to use it locally.

Result deployed

Using cloud-provider-kind as a service

If you're on Ubuntu, there's a way to automatically run cloud-provider-kind when you start your machine as a service, so you don't have to manually start it every time you want to use it.

First, navigate to the directory /etc/systemd/system and create a file called cloud-provider-kind.service with the following content:

cd /etc/systemd/system
touch cloud-provider-kind.service
Enter fullscreen mode Exit fullscreen mode
[Unit]
Description = Your description
After = docker.service

[Service]
Type = simple
ExecStart = {direction to cloud-provider-kind}
StandardOutput = journal
User = {user id}
Group = {group id}

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
  • ExecStart: Use the command which cloud-provider-kind to replace your directory.
  • User, Group: Use the command id to get the appropriate values.

To start the service:

sudo systemctl enable --now cloud-provider-kind
Enter fullscreen mode Exit fullscreen mode

Then check status:
symtemctl status

If you have any suggestions or questions regarding the content of the article, please don't hesitate to leave a comment below!


If you found this content helpful, please visit the original article on my blog to support the author and explore more interesting content.

BlogspotBlogspotDev.toFacebookX


Some series you might find interesting:

Top comments (0)