[英]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
给出:
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:您有三种可能的解决方案:
Use a service with type NodePort
or LoadBalancer
to make the service reachable outside the cluster.使用类型为
NodePort
或LoadBalancer
的服务使服务可在集群外访问。
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。
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,请使用此选项。
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.