Skip to content

Setting up Ingress

Gabriel Fernandes de Oliveira edited this page Mar 15, 2021 · 1 revision

Enable the NGINX Ingress controller on minikube:

minikube addons enable ingress

This will create a pod named nginx-ingress-controller on the "kube-system" namespace.

Then, create an ingress resource, configuring the routes your cluster will serve, in our case the following will work to expose the verdict api (listening on port 8083 on service mart).

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: mart-ingress
    annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
    rules:
        - host: mart-route
          http:
              paths:
                  - path: /
                    pathType: Prefix
                    backend:
                        service:
                            name: mart
                            port:
                                number: 8083

The host parameter determines the domain where the server will be accessible.

Create the Ingress resource:

kubectl apply -f k8s/ingress.yml

If the error "Error from server (InternalError): error when creating "k8s/ingress.yml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post "https://ingress-nginx-controller-admission.kube-system.svc:443/networking/v1beta1/ingresses?timeout=30s": dial tcp 10.97.77.156:443: connect: connection refused" pops up, run before retrying to apply:

k delete validatingwebhookconfigurations ingress-nginx-admission

After the creation of the ingress component, run:

kubectl get ingress

To discover the IP address exposing the cluster. This parameter may take some time to appear, it should look something like this:

NAME           CLASS    HOSTS        ADDRESS        PORTS   AGE
mart-ingress   <none>   mart-route   192.168.49.2   80      53s

The last step is to add "mart-route" to /etc/hosts pointing it to the shown address.

Now the requests for the verdict can be sent to "mart-route" (port 80).

Clone this wiki locally