1
votes

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 ?

1
try to remove the * sign from the path and the forward slash, what happens?iomv
thank you for responding. I tried without the * and without the * and the forward slash. It did not work, still the same issueEnnar.ch
can you add the front service too please?iomv
I edited my post to include front service. In fact I changed the ressource to - http: paths: - path: /* backend: serviceName: frontapp servicePort: 3000 - path: /back/* backend: serviceName: backapp servicePort: 9000 the service mapped to the (/* works fine ( I triedto map both service each time to the /* and each time it worked , but the other service mapped to external-ingress-ip/back return a 404 error )Ennar.ch
How are you making the requests?suren

1 Answers

0
votes

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)