'Kubernetes ingress not routing

I have 2 services and deployments deployed on minikube on local dev. Both are accessible when I run minikube start service. For the sake of simplicity I have attached code with only one service

However, ingress routing is not working

CoffeeApiDeployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: coffeeapi-deployment
  labels:
    app: coffeeapi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: coffeeapi
  template:
    metadata:
      labels:
        app: coffeeapi
    spec:
      containers:
      - name: coffeeapi
        image: manigupta31286/coffeeapi:latest
        env:
        - name: ASPNETCORE_URLS
          value: "http://+"
        - name: ASPNETCORE_ENVIRONMENT
          value: "Development"
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: coffeeapi-service
spec:
  selector:
    app: coffeeapi
  type: NodePort
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80
      nodePort: 30036

Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - http:
        paths:
        - path: /coffee
          pathType: Prefix
          backend:
            service:
              name: coffeeapi-service
              port: 
                number: 8080


Solution 1:[1]

You are missing the ingress class in the spec.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-ingress
spec:
  ingressClassName: nginx # (or the class you configured)

Using NodePort on your service may also be problematic. At least it's not required since you want to use the ingress controller to route traffic via the ClusterIP and not use the NodePort directly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 The Fool