How can I send the data from fluentd in kubernetes cluster to the elasticsearch in remote standalone server outside cluster? How can I send the data from fluentd in kubernetes cluster to the elasticsearch in remote standalone server outside cluster? kubernetes kubernetes

How can I send the data from fluentd in kubernetes cluster to the elasticsearch in remote standalone server outside cluster?


There are two common ways mentioned in documentation to access external resources from inside the Pod:

  1. Create a Service and Endpoint objects. Set external IP address in Endpoint's specification:

    kind: ServiceapiVersion: v1metadata:  name: ext-elastic  namespace: defaultspec:  ports:  - protocol: TCP    port: 80    targetPort: 9200---kind: EndpointsapiVersion: v1metadata:  name: ext-elastic  namespace: defaultsubsets:  - addresses:      - ip: 1.2.3.4    ports:      - port: 9200

NOTE: The endpoint IPs may not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast (224.0.0.0/24). They cannot be the cluster IPs of other Kubernetes services either because the kube-proxy component doesn’t support virtual IPs as destination yet.

You can access this service by using http://ext-elastic inside the same namespace or by using http://ext-elastic.default.svc.cluster.local from a different namespace.

  1. Create the ExternalName Service and specify a name of the external resource in the specification:

An ExternalName service is a special case of service that does not have selectors. It does not define any ports or Endpoints. Rather, it serves as a way to return an alias to an external service residing outside the cluster.

kind: ServiceapiVersion: v1metadata:  name: ext-elastic  namespace: defaultspec:  type: ExternalName  externalName: my.external.elasticsearch.com  ports:  - port: 80

When looking up the host my-service.prod.svc.CLUSTER, the cluster DNS service will return a CNAME record with the value my.database.example.com. Accessing such a service works in the same way as others, with the only difference that the redirection happens at the DNS level and no proxying or forwarding occurs. Should you later decide to move your database into your cluster, you can start its pods, add appropriate selectors or endpoints and change the service type.

Check out another article to see some more examples.