Ingress resource does not give access to exposed services

6/26/2018

Hi I am currently trying to deploy my application using google kubernetes engine. I exposed my front and back services as NodePort, I created a global static IP address named "ip". and I created an ingress ressource . The ingress ressource was working fine until I added the path rules.

here Is my ingress ressource

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: ip
  labels:
    app: myapp
    part: ingress
spec:
 rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: backapp
          servicePort: 9000
      - path: /front/*
        backend:
          serviceName: frontapp
          servicePort: 3000

And here is my services back :

apiVersion: v1 kind: Service metadata:

  labels:
    app: myapp
    part: back
  name: backapp
  namespace: default
spec:
  clusterIP: 10.*.*.*
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30646
    port: 9000
    protocol: TCP
    targetPort: 9000
  selector:
    app:  myapp
    part: back
  sessionAffinity: None
  type: NodePort

front:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: myapp
    part: front
  name: frontapp
  namespace: default
spec:
  clusterIP: 10.*.*.*
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31609
    port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
     app: myapp
     part: front
  sessionAffinity: None
  type: NodePort

Every time I try to go to http://external-ingress-ip/front

http://external-ingress-ip/front/home

http://external-ingress-ip/users

http://external-ingress-ip/...

All I get is default backend - 404

So my question is: what is wrong with my configuration, what changed when I added the paths ?

-- Ennar.ch
kubernetes
kubernetes-ingress

1 Answer

6/29/2018

A Kubernetes NodePort service is the most basic way to get external traffic directly to your service.

NodePort, as the name implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service.

Back to your issue. Try to use that configuration. It is a bit more clear and contain only needed options.

Please keep in mind that ingress.global-static-ip-name and targetPortof both Services to your values of Pods’ ports.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: $IP # Reserved IP address
  labels:
    app: myapp
    part: ingress
spec:
 rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: backapp
          servicePort: 9000
      - path: /front/*
        backend:
          serviceName: frontapp
          servicePort: 3000`

Also, there is a need to define separate services to process incoming traffic:

 apiVersion: v1
 kind: Service
 metadata:
   labels:
     app: myapp
     part: back
   name: backapp
   namespace: default
 spec:
   ports:
   - port: 9000
     protocol: TCP
     targetPort: 9000 # Port on the pod with 'back' application
   selector:
     app: myapp
     part: back
   type: NodePort

And the second configuration for frontend services:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: myapp
    part: front
  name: frontapp
  namespace: default
spec:
  ports:
  - port: 3000
    protocol: TCP
    targetPort: 3000 # Port on the pod with 'front' application
  selector:
     app: myapp
     part: front
  type: NodePort

If it will not be OK with the new configuration, please write a comment with details.

(I would like to say Thank you to Anton Kostenko for helping hands and made configuration files working)

-- d0bry
Source: StackOverflow