Search code examples
nginxkubernetesnginx-ingress

kubernetes ingress controller with cluster ip service and default nginx not working as expected


There is a kubernetes baremetal cluster which has 7 nodes. Installed is helm and added a helm repo added

What works: https://matthewpalmer.net/kubernetes-app-developer/articles/kubernetes-ingress-guide-nginx-example.html

I am able to access the apple and the banana location on the dns A record mentioned before.

When i deploy a default nginx image with a service with port 80 and of type cluster-ip the following nginx-ingress resource does not work

kubectl run nginx --image=nginx ; kubectl exposed pod nginx --port=80 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-test
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: kubernetes.somename.lan
    http:
      paths:
        - path: /test
          pathType: Prefix
          backend:
            serviceName: nginx
            servicePort: 80

I am seeing in the logs that the file is being deployed in the nginx-ingress image, not seeing anything strange in comparison to the apple and banana ingress entry. Only difference I can come up with is that ingress controller and nginx image are bot using port 80

So what I need is that when I access http://somelan.lan/test, I will end up at the placeholder of the nginx server (which is accessible by nginx service )


How can I access nginx on my A dns record under the path /test?


Solution

  • Ok, after research i found out how to solve this. Hope this helps anyone https://www.reddit.com/r/kubernetes/comments/j2neuf/nginxingress_path_routing/

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: ingress-precious
      annotations:
        nginx.org/rewrites: "serviceName=nginx-ingress rewrite=/;"
    spec:
      rules:
      - host: kubernetes.somelan.lan
        http:
          paths:
          - path: /test1
            backend:
              serviceName: nginx-ingress
              servicePort: 80