Kubernetes - Intra cluster communication - Ingress Rules or Node Ports

11/17/2021

I have a number of restful services within our system

  • Some are our within the kubernetes cluster
  • Others are on legacy infrasture and are hosted on VM's

Many of our restful services make synchronous calls to each other (so not asynchronously using message queues)

We also have a number of UI's (fat clients or web apps) that make use of these services

We might define a simple k8s manifest file like this 1. Pod 2. Service 3. Ingress

apiVersion: v1
kind: Pod
metadata:
  name: "orderManager"
spec:
  containers:
    - name: "orderManager"
      image: "gitlab-prem.com:5050/image-repo/orderManager:orderManager_1.10.22"
---
apiVersion: v1
kind: Service
metadata:
  name: "orderManager-service"
spec:
  type: NodePort
  selector:
    app: "orderManager"
  ports:
    - protocol: TCP
      port: 50588
      targetPort: 50588
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: orderManager-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /orders
            pathType: Prefix
            backend:
              service:
                name: "orderManager-service"
                port:
                  number: 50588

I am really not sure what the best way for restful services on the cluster to talk to each other.

  • It seems like there is only one good route for callers outside the cluster which is use the url built by the ingress rule
  • Two options within the cluster

This might illustrate it further with an example

CallerReceiverExample Url
UIOn Clusterhttp://clusterip/ordersThe UI would use the cluster ip and the ingress rule to reach the order manager
Service off clusterOn Clusterhttp://clusterip/ordersJust like the UI
On ClusterOn Clusterhttp://clusterip/ordersCould use ingress rule like the above approach
On ClusterOn Clusterhttp://orderManager-service:50588/Could use the service name and port directly

I write cluster ip a few times above but in real life we put something top so there is a friendly name like http://mycluster/orders

So when caller and reciever are both on cluster is it either

  • Use the ingress rule which is also used by services and apps outside the cluster
  • Use the nodeport service name which is used in the ingress rule
  • Or perhaps something else!

One benefit of using nodeport service name is that you do not have to change your base URL.

  • The ingress rule appends an extra elements to the route (in the above case orders)
  • When I move a restful service from legacy to k8s cluster it will increase the complexity
-- ThePravinDeshmukh
kubernetes
kubernetes-ingress
nginx-ingress

0 Answers