How to send tcp data into kubernetes cluster from outside

I have a kube cluster running on minikube locally. Inside the cluster, there is an elastic agent running. It is a daemonset.apps. I would like to send logs to this agent through port 8080 with TCP.

When I am working inside the pod, I can send the log to the agent and the logs can hit the cloud. Here are the steps I used:

$ kubectl exec -it elastic-agent-zhkh2 -n kube-system -- bash
$ echo "Test message" | nc.openbsd -q0 localhost 8080

The problem is that the pod can only receive my logs when I am inside the pod.
I would like to ask how can I send logs to the agent from the outside of the kube cluster.

Cluster information:

  • minikube version: v1.28.0
  • kubectl version:
Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.0", GitCommit:"b46a3f887ca979b1a5d14fd39cb1af43e7e5d12d", GitTreeState:"clean", BuildDate:"2022-12-08T19:58:30Z", GoVersion:"go1.19.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:49:09Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"}
  • helm version: v3.10.3
  • ubuntu: 20.04

I have tried to create a service and link to the dameonset, and I also follow this page to set the tcp service for ingress:

Here are some yaml file and commands I used:
elastic-agent-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: elastic-agent
  namespace: kube-system
spec:
  selector:
    app: elastic-agent
  ports:
    - name: tcp-logs
      port: 8080
      targetPort: 8080
      protocol: TCP

tcp-services.yaml

apiVersion: v1
kind: ConfigMap
data:
  "8080": kube-system/elastic-agent:8080
metadata:
  name: tcp-services
  namespace: ingress-nginx

ingress-nginx-controller-patch.yaml

  template:
    spec:
      containers:
      - name: controller
        ports:
         - containerPort: 8080
           hostPort: 8080

Thanks