Not able to call external resources through kubernetes ingress

2/26/2020

I am trying to configure ingress resources in kubernetes, I want to know if I can access external resources via kuberntes(Example, I installed kibana in a virtual machine and I want to access through kubernetes ingress as below)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/add-base-url: "true"
spec:
  rules:
  - host: test.com
    http:
      paths:
        - path: "/"
          backend:
            serviceName: service1
            servicePort: 1000
        - path: "/test"
          backend:
            serviceName: service2.test
            servicePort: 2000
        - path: "/kibana"
          backend:
            serviceName: <ip-address>
            servicePort: 9092

Any suggested is this the right way of calling external resources(or) we cannot initiate a call as it is outside of kubernetes...

I am trying to call as test.com/kibana

Please suggest.
-- magic
elasticsearch
kibana
kubernetes
kubernetes-ingress

1 Answer

2/26/2020

For external resources you should create Endpoints object.

This is explained with Services without selectors

Services most commonly abstract access to Kubernetes Pods, but they can also abstract other kinds of backends. For example:

  • You want to have an external database cluster in production, but in your test environment you use your own databases.
  • You want to point your Service to a Service in a different Namespace or on another cluster.
  • You are migrating a workload to Kubernetes. Whilst evaluating the approach, you run only a proportion of your backends in Kubernetes.

In any of these scenarios you can define a Service without a Pod selector. For example:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Because this Service has no selector, the corresponding Endpoint object is not created automatically. You can manually map the Service to the network address and port where it’s running, by adding an Endpoint object manually:

apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: 192.0.2.42
    ports:
      - port: 9376

So once you add the Endpoint setup a Service for it, you will be able to use is inside Ingress.

-- Crou
Source: StackOverflow