can i use ingress-nginx to simple route traffic?

6/1/2018

I really like the kubernetes Ingress schematics. I currently run ingress-nginx controllers to route traffic into my kubernetes pods.

I would like to use this to also route traffic to 'normal' machines: ie vm's or physical nodes that are not part of my kubernetes infrastructure. Is this possible? How?

-- yee379
kubernetes
kubernetes-ingress
router

3 Answers

6/2/2018

In Kubernetes you can define an externalName service in which you define a FQND to an external server.

kind: Service
apiVersion: v1
metadata:
  name: my-service
  namespace: prod
spec:
  type: ExternalName
  externalName: my.database.example.com

Then you can use my-service in your nginx rule.

-- Nicola Ben
Source: StackOverflow

6/3/2018

You can create static service and corresponding endpoints for external services which are not k8s and then use k8s service in ingress to route traffic. Also you see ingress doc to enable custom upstream check https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-nginx-upstream-checks

In below example just change port/IP according to your need

apiVersion: v1
kind: Service
metadata:
  labels:
    product: external-service
  name: external-service
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
 ---
 apiVersion: v1
 kind: Endpoints
 metadata:
   labels:
     product: external-service
   name: external-service
 subsets:
 - addresses:
   - ip: x.x.x.x
   - ip: x.x.x.x
   - ip: x.x.x.x
   ports:
   - name: http
     port: 80
     protocol: TCP
-- Pawan Kumar
Source: StackOverflow

6/1/2018

I don't think it's possible, since ingress-nginx get pods info through watch namespace, service, endpoints, ingress resources, then redirect traffic to pods, without these resources specific to kubernetes, ingress-nginx has no way to find the ips that need loadbalance. And ingress-nginx doesn't has health-check method defined, it's up to the kubernetes builtin mechanic to check the health of the running pods.

-- Kun Li
Source: StackOverflow