Loved by developers around the world, Ngrok is a cross-platform application that enables developers to expose a local development server to the Internet.
Last year, the Ngrok team announced the release of an ingress controller, this was exciting as a long-time user of Ngrok, in this tutorial, we will look at how to expose an application using the Ngrok ingress for Kubernetes.
Prerequisites
This tutorial assumes some familiarity with Kubernetes, in addition, you would need the following:
Creating a cluster
We’ll begin by creating a Kubernetes cluster.
For simplicity, we will be doing it from the CLI:
civo k3s create --create-firewall --nodes 2 -m --save --switch --wait ngrok-demo -r=Traefik
Using the -r
flag, removes the default ingress controller (Traefik), as we will be using the Ngrok ingress to expose applications,
Using the -m
flag tells the Civo command line to merge the kubeconfig for the cluster with our existing kube-config
Installing the Ngrok Ingress Controller
To install the Ngrok ingress controller using Helm, run the following commands in your terminal:
Add the helm repo
helm repo add ngrok <https://ngrok.github.io/kubernetes-ingress-controller>
Export your credentials
export NGROK_API_KEY=<your API key >
export NGROK_AUTHTOKEN=<your auth token>
Install the Helm Chart
helm install ngrok-ingress-controller ngrok/kubernetes-ingress-controller \\
--set credentials.apiKey=$NGROK_API_KEY \\
--set credentials.authtoken=$NGROK_AUTHTOKEN
Creating a deployment
Begin by creating a file called deployment.yaml
this would house the Kubernetes deployment and service for the application:
apiVersion: apps/v1
kind: Deployment
metadata:
name: whoami
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: traefik/whoami
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: whoami
namespace: default
spec:
selector:
app: whoami
ports:
- protocol: TCP
port: 80
targetPort: 80
The code above would deploy the whoami
web server with one replica and create a Kubernetes service.
Apply the deployment
kubectl apply -f deployment.yaml
Exposing the Deployment
Create a file named ingress.yaml
and follow along with the code below:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
spec:
ingressClassName: ngrok
rules:
- host: globally-uniquedomainname.ngrok.app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80
Ensure you replace
Once you update the host
section with the appropriate domain name, apply the manifest:
kubectl apply -f ingress.yaml
To view the exposed application, navigate to your browser and paste in the domain name you obtained from the Ngrok dashboard. You should see something like this:
Out of the box, Ngrok handles TLS termination, eliminating the need to manage certificates ourselves.
Summary
The Ngrok Ingress is a welcome addition to the ingress controller family as it provides a viable alternative to some of the more popular ingress controllers while still providing a robust feature set.
If you’re looking to explore ingress controllers further, here are some ideas:
- Take a look at how you can rate-limit applications using the Nginx ingress in this guide.
- Learn how to securely expose your applications using Cert-Manger and Traefik ingress.
- Learn how to perform A/B tests using the Nginx ingress in this guide.