简体   繁体   English

Kafka 连接 - 无法连接到本地主机端口 8083:连接被拒绝

[英]Kafka connect - Failed to connect to localhost port 8083: Connection refused

I have an application that relies on a kafka service.我有一个依赖 kafka 服务的应用程序。

With Kafka connect, I'm getting an error when trying to curl localhost:8083 , on the Linux VM that's running the kube.netes pod for Kafka connect.使用 Kafka 连接时,在运行用于 Kafka 连接的 kube.netes pod 的 Linux VM 上尝试curl localhost:8083时出现错误。

curl -v localhost:8083 gives: curl -v localhost:8083给出:

  • Rebuilt URL to: localhost:8083/重建 URL 为:localhost:8083/
  • Trying 127.0.0.1...正在尝试 127.0.0.1...
  • connect to 127.0.0.1 port 8083 failed: Connection refused连接到 127.0.0.1 端口 8083 失败:连接被拒绝
  • Failed to connect to localhost port 8083: Connection refused无法连接到本地主机端口 8083:连接被拒绝
  • Closing connection 0 curl: (7) Failed to connect to localhost port 8083: Connection refused关闭连接 0 curl: (7) 无法连接到本地主机端口 8083:连接被拒绝

kubectl get po -o wide for my kube.netes namespace gives: kubectl get po -o wide for my kube.netes 命名空间给出:

在此处输入图像描述

When I check open ports using sudo lsof -i -P -n | grep LISTEN当我使用sudo lsof -i -P -n | grep LISTEN检查打开的端口时sudo lsof -i -P -n | grep LISTEN I don't see 8083 listed. sudo lsof -i -P -n | grep LISTEN我没有看到列出的 8083。 The kafka connect pod is running and there's nothing suspicious in the logs for the pod. kafka connect pod 正在运行,并且该 pod 的日志中没有任何可疑之处。

There's a kube.netes manifest that I think was probably used to set up the Kafka connect service, these are the relevant parts.我认为有一个 kube.netes 清单可能用于设置 Kafka 连接服务,这些是相关部分。 I'd really appreciate any advice about how to figure out why I can't curl localhost:8083我非常感谢有关如何弄清楚为什么我不能 curl localhost:8083 的任何建议

apiVersion: apps/v1
kind: Deployment
metadata:
   name: kafka-connect
   namespace: my-namespace
spec:

   ...

   template:
     metadata:
       labels:
         app: connect
     spec:
        containers:
          - name: kafka-connect
            image: confluentinc/cp-kafka-connect:3.0.1
            ports:
              - containerPort: 8083

            env:
              
              - name: CONNECT_REST_PORT
                value: "8083"
              - name: CONNECT_REST_ADVERTISED_HOST_NAME
                value: "kafka-connect"

        volumes:
          - name: connect-plugins
            persistentVolumeClaim:
                claimName: pvc-connect-plugin
          - name: connect-helpers          
            secret:
              secretName: my-kafka-connect-config
---
apiVersion: v1
kind: Service
metadata:
  name: kafka-connect
  namespace: my-namespace
  labels:
    app: connect  
spec:
  ports:
    - port: 8083
  selector:
    app: connect

You can't connect to a service running inside your cluster, from outside your cluster, without a little bit of tinkering.如果不进行一些修改,您无法从集群外部连接到集群内部运行的服务。

You have three possible solutions:您有三种可能的解决方案:

  1. Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster.使用类型为NodePortLoadBalancer的服务使服务可在集群外访问。

    See the services and kubectl expose documentation.请参阅服务kubectl 公开文档。
    Be aware, depending on your environment, this may expose the service to the inte.net.请注意,根据您的环境,这可能会将服务暴露给 inte.net。

  2. Access using Proxy Verb: (see here )使用代理动词访问:(参见此处

    This only works for HTTP/HTTPS.这仅适用于 HTTP/HTTPS。 Use this if your service is not secure enough to be exposed to the inte.net.如果您的服务不够安全,无法暴露给 inte.net,请使用此选项。

  3. Access from pod running inside your cluster.从集群内运行的 pod 进行访问。

    As you have noticed in the comments, you can curl from inside the pod.正如您在评论中注意到的那样,您可以从 pod 内部curl You can also do this from any other pod running in the same cluster.您也可以从同一集群中运行的任何其他 pod 执行此操作。 Pods can communicate with each other without any additional configuration. Pod 无需任何额外配置即可相互通信。


Why can I not curl 8083 when I ssh onto the VM?为什么我ssh不能curl 8083到VM上?

Pods/services are not reachable from outside the cluster, if not exposed using aforementioned methods (point 1 or 2).如果不使用上述方法(第 1 点或第 2 点)公开,则无法从集群外部访问 Pod/服务。

Why isn't the port exposed on the host VM that has the pods?为什么没有在具有 pod 的主机 VM 上公开端口?

It's not exposed on your VM, it's exposed inside your cluster.它不会暴露在您的 VM 上,而是暴露在您的集群内部。


I would strongly recommend going through Cluster Networking documentation to learn more.我强烈建议您阅读集群网络文档以了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到主机 localhost 端口 22:连接被拒绝 - connect to host localhost port 22: Connection refused 无法连接到端口 8080:连接被拒绝错误号:7 (cURL) - Failed to connect to port 8080: Connection refused Error number: 7 (cURL) 临时:ssh:连接到主机失败:连接被拒绝 - Temporary: ssh: connect to host failed: Connection refused git lab runner 无法连接到 api.local 端口 80:连接被拒绝 - git lab runner Failed to connect to api.local port 80: Connection refused 安装hadoop:连接到主机主端口22时ssh失败:连接被拒绝 - ssh failed when installing hadoop:connect to host master port 22: connection refused 拒绝连接到本地主机上的虚拟主机 - Refused to connect to virtual host on localhost curl:(7)无法连接到127.0.0.1:5984; 连接被拒绝[有时] - curl: (7) Failed connect to 127.0.0.1:5984; Connection refused [Sometimes] 使用c connect()拒绝连接? - Connection refused using the c connect()? Odoo 容器:数据库连接失败:无法连接到服务器:连接被拒绝(将 odoo 与 localhost postgres 链接) - Odoo container : Database connection failure: could not connect to server: Connection refused (linking odoo with localhost postgres) nodejs 5500 端口 API 获取连接被拒绝 - nodejs 5500 port API get connect refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM