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.
- Create a cluster using kind, such as the content below
cat <<EOF | kind create cluster --name=16-bits --config=-
- role: control-plane
- containerPort: 80
- containerPort: 443
A screen like that is expected
2. Check the localhost using curl and nothing should be returned
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
4. Check the k8s namespaces, and the new namespace has been created, ingress-nginx.
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 \
6. Create a namespace to deploy the service, for it type the command below
kubectl create namespace 16-bits
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
8. Check wether the service is running. First, you need to know the pod, follow the instructions below
kubectl get pods -n 16-bits
kubectl logs -n bits <pod name>
9. Ingress NGINX 🖥 is on fire 🔥
You can use cURL or your browser.
Coming up → k8s dashboard
Is more easy and more professional has a Ingress instead of manage the ports by myself, since this decrease the error prone.
ingress-nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer. Learn more…
kind is a tool for running local Kubernetes clusters using Docker container "nodes". kind was primarily designed for…
Quarkus is a full-stack, Kubernetes-native, Java Application Framework tailored for OpenJDK HotSpot and GraalVM…