Kubernetes Ingress Setup

7/10/2019

I tried to setup a Kubernetes Ingress to route external http traffic towards a frontend pod (with path /) and backend pod (with path /rest/*), but I alway get a 400 error instead of the main nginx index.html.

So I tried the Google Kubernetes example at page https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer, but I get always a 400 error. Any idea?

Following is the deployment descriptor for the frontend "cup-fe" (running nginx with angular app):

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: cup-fe
  namespace: default
  labels:
    app: cup-fe
spec:
  replicas: 2
  selector:
    matchLabels:
      app: "cup-fe"
  template:
    metadata:
      labels:
        app: "cup-fe"
    spec:
      containers:
      - image: "eu.gcr.io/gpi-cup-242708/cup-fe:latest"
        name: "cup-fe"

Next the service NodePort:

apiVersion: v1
kind: Service
metadata:
  name: cup-fe
  namespace: default
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: cup-fe
  type: NodePort

And last, but not least, the Ingress to expose the frontend outside:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: http-ingress
spec:
  rules:
  - host: cup-fe
    http:
      paths:
      - path: /
        backend:
          serviceName: cup-fe
          servicePort: 80
      - path: /rest/*
        backend:
          serviceName: cup-be
          servicePort: 8080

I left behind "cup-be" deployment descriptor (running wildfly), because is pretty similar to the "cup-fe" one. Please note also that if I create a LoadBalancer service instead of NodePort, I can reach the web page but I have some CORS problems to call the backend.

-- duns
google-kubernetes-engine
kubernetes
kubernetes-ingress

1 Answer

7/11/2019

I assume that you have used wrong selector run: cup-fe entire particular service configuration. Since I have replaced label with app: cup-fe in cup-fe service configuration the relevant Pod endpoints showed up and I've received successful responses as well.

$ kubectl get ep | grep cup-fe|awk '{print $2}'
<IP_address>:80,<IP_address>:80

If the issue still persists just let me know and push a comment below my answer.

-- mk_sta
Source: StackOverflow