Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ingress multiple paths vs multiple ingresses

Tags:

kubernetes

I have the following Ingress definition that works well (I use docker-for-mac):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: zwoop-ing
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: localhost
    http:
      paths:
      - path: /
        backend:
          serviceName: posts-api-svc
          servicePort: 8083

Where I'm confused is how I would deal with multiple api microservices that I want to expose.

The options that I had in mind:

  • Multiple ingresses
  • Single ingress with different paths
  • Single ingress with different subdomains (when on the Cloud)

I assume that multiple ingresses would cost more (?).
For some reason, I have problems using a subpath segment (ingress-nginx).

When I define: - path: /api in the ingress resource, I receive a 404 on GET request.
It is unclear how to define a subpath (here I use /api, but that would be posts-api, users-api etc).

For a single posts-api, I currently have the following setup:

apiVersion: v1
kind: Service
metadata:
  name: posts-api-svc
  # namespace: nginx-ingress
  labels:
    app: posts-api
    #rel: beta
    #env: dev
spec:
  type: ClusterIP
  selector:
    app: posts-api
    # rel: beta
    # env: dev
  ports:
    - protocol: TCP
      port: 8083

With a deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: posts-api-deployment
  # namespace: nginx-ingress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: posts-api
  template:
    metadata:
      labels:
        app: posts-api
        # env: dev
        # rel: beta
    spec:
      containers:
        - name: posts-api
          image: kimgysen/posts-api:latest
          ports:
          - containerPort: 8083
          livenessProbe:
            httpGet:
              path: /api/v1/posts/health
              port: 8083
            initialDelaySeconds: 120
            timeoutSeconds: 1

The health check on the pod works fine for endpoint: /api/v1/posts/health

like image 328
html_programmer Avatar asked Jan 21 '19 22:01

html_programmer


1 Answers

I assume that multiple ingresses would cost more (?).

  • Multiple ingress controllers like nginx-ingress: Yes, it would cost more if you are using an external load balancer and a cloud provider like AWS, GCP or Azure because you will be using as many load balancers as ingress controller. It would not cost more if you are using just a ClusterIP (accessing within the cluster) and it will vary if you are using a NodePort service to expose it.
  • Multiple Ingress Kubernetes resources: No it would not cost more if you are using the same ingress controller.

When I define: - path: /api in the ingress resource, I receive a 404 on GET request.

This means it's going to the default backend and likely because of this annotation nginx.ingress.kubernetes.io/rewrite-target: /. Essentially, that's stripping the /api from your request that is going to your backend. If you want to preserve the path, I suggest you remove the annotation.

You can always check the nginx ingress controller nginx.conf file with something like:

$ kubectl cp <pod-where-nginx-controller-is-running>:nginx.conf .
$ cat nginx.conf
like image 147
Rico Avatar answered Sep 20 '22 14:09

Rico