Expose localhost Kubernetes

This tutorial will guide you on how you can expose services running on your local kubernetes setup.

1. Getting Kubernetes (minikube)

For this tutorial we are using minikube.

Minikube will allow you to setup local kubernetes cluster on Windows, macOS or Linux machine very easily. You can follow this guide on how to setup minikube in your local machine.

Once you have installed minikube, start your cluster.

$minikube start
πŸ˜„  minikube v1.10.1 on Debian Parrot
✨  Using the virtualbox driver based on existing profile
πŸ‘  Starting control plane node minikube in cluster minikube
πŸ”„  Restarting existing virtualbox VM for "minikube" ...
🐳  Preparing Kubernetes v1.18.2 on Docker 19.03.8 ...
🌟  Enabled addons: dashboard, default-storageclass, storage-provisioner
πŸ„  Done! kubectl is now configured to use "minikube"

2. Getting Kubernetes CLI

To interact with your new kubernetes cluster you will need kubectl. Download the latest binary of kubectl for Linux with the commands below.

#Downloading the kubectl binary
$curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

#Making the binary executeable
$chmod +x ./kubectl

#Moving kubectl binary to $PATH
$sudo mv ./kubectl /usr/bin/kubectl

You can find further instructions for Windows & macOS here.

Once you finished setting up kubectl,check it's version. Try using it to check your new local cluster status.

3. Create & Run your Service (nginx)

Let's deploy simple a nginx web-server on our local kubernetes cluster.

4. Expose Nginx Pod with NodePort

In order to access the service in our newly created nginx pod, we need to expose port 80 using NodePort service like following.

Find the the NodePort assigned to our nginx pod.

Alternatively, you can get it withkubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services nginx-server

Verify if you can access nginx default welcome page on http://192.168.99.100:32428.

5. Expose Port assigned by NodePort

Since we can access our nginx service on port 32428, let's go ahead and tunnel it with LocalXpose.

You should be able to access nginx from the domain provided by LocalXpose.

6. Kubernetes Dashboard

Similarly, if you want to expose your kubernetes dashboard,

now, expose port 8001 with LocalXpose.

Alternatively you can use minikube cli to proxy dashboard & expose those port.

Browse, https://<your_domain>/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview

From here you can manage your Kubernetes Cluster.

If you want to use your custom domain or SSL certificate check (creating custom domain name) & (using custom SSL certificate).

Last updated

Was this helpful?