0
votes

I'm a k8s newbie and I am trying to expose a port from the cluster into the local network. I've tried to do it with metallb config layer2 + load balancer controller and this runs ok.

I have set up a 3-node environment with kubespray. ((192.168.0.1[5,6,7]))

However, I'm trying to expose an api with NodePort and NGINX-Ingress. The nodeport api service is running ok (i can make successfull requests via NODE_IP:NODE_nodeport). But if I try this ingress configuration it justs keeps telling me "connection refused":

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-api
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: "k8s.customhostname.com" # solves to 192.168.0.17 which has a running pod with the api.
    http:
      paths:
      - path: /test
        pathType: Prefix
        backend:
          service:
            name: svc-api
            port:
              number: 8080

Then i check the services:

Name:              svc-smouapimapes
Namespace:         smouapi
Labels:            app=apimapes
Annotations:       <none>
Selector:          app=apimapes
Type:              ClusterIP
IP:                10.233.26.225
Port:              springboot  8080/TCP
TargetPort:        8080/TCP
Endpoints:         10.233.90.4:8080,10.233.92.8:8080
Session Affinity:  None
Events:            <none>

And then check the ingress:

Name:             ingress-smouapimapes
Namespace:        smouapi
Address:          192.168.0.17
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                     Path  Backends
  ----                     ----  --------
  k8s.nexusgeografics.com
                           /test   svc-smouapimapes:8080   10.233.90.4:8080,10.233.92.8:8080)
Annotations:               nginx.ingress.kubernetes.io/ssl-redirect: false
Events:                    <none>

Whenever i call :

curl -I http://k8s.nexusgeografics.com/test
# CONNECTION REFUSED

What am I doing wrong? Thanks

2

2 Answers

1
votes

Try adding the following in the Nginx config ingress-smouapimapes. Add annotation :

nginx.ingress.kubernetes.io/rewrite-target: /$2

And instead of this path: /test add path: /test(/|$)(.*)

0
votes

Enin, you should configure the domain k8s.nexusgeografics.com to be resolved to the ip that providing the nginx-ingress service, thus, you can access your service through nginx-ingress.