How to add NGINX Ingress controller in your local k8s

After for the umpteenth time type the command port-forward I noticed that I had to use Ingress 😜 and avoid the famous DRY (Don’t Repeat Yourself).

Disclaimer → Is not wrong use port-forward command, but if you can don’t remember it, looks great.

Assumptions → You’re familiar with docker and has installed the softwares below.

For this tutorial I’m using the following softwares

In terms of deploy, I’m using an application built with Quarkus, with 2 endpoints, /resteasy-jackson/quarks and /hello-resteasy. The image is available on my Docker hub.

This is an overview of those piece together, and let’s analyse how configure them.

16-bits diagram
  1. Create a cluster using kind, such as the content below
cat <<EOF | kind create cluster --name=16-bits --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF

A screen like that is expected

kind cluster 16-bits

2. Check the localhost using curl and nothing should be returned

curl localhost
curl localhost

3. Create the Ingress. The Ingress will be the key piece to connect our service to external environment without use the port-forward command.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml
create the Ingress

4. Check the k8s namespaces, and the new namespace has been created, ingress-nginx.

kubectl get namespaces
kubectl get namespaces

5. Check if the service has been deployed and execute a request to localhost. Now a NGINX error is returned, and it’s the expected result.

kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
curl localhost
check the service

6. Create a namespace to deploy the service, for it type the command below

kubectl create namespace 16-bits
create namespace

7. Using the namespace 16-bits, deploy the service

kubectl -n 16-bits apply -f https://github.com/luizgustavocosta/16-bits-quarkus/blob/main/service-4-k8s/src/main/resources/k8s/kubernetes.yml
Service deployed

8. Check wether the service is running. First, you need to know the pod, follow the instructions below

kubectl get pods -n 16-bits
get pods
kubectl logs -n bits <pod name>
logs

9. Ingress NGINX 🖥 is on fire 🔥

You can use cURL or your browser.

curl http://localhost/hello-resteasy
CURL
Browser

Coming up → k8s dashboard

Conclusion

Is more easy and more professional has a Ingress instead of manage the ports by myself, since this decrease the error prone.

References

Hi there 👋 , I’m Luiz Gustavo I’m a Brazilian and don’t play soccer very well, then I became a software developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store