[英]Unable to connect to ClusterIP service
I've have RabbitMQ deployment with ClusterIP service. 我已经使用RabbitIP部署了ClusterIP服务。
Deployment: 部署:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: rabbit-mq
name: rabbit-mq
spec:
replicas: 1
selector:
matchLabels:
app: rabbit-mq
strategy:
type: Recreate
template:
metadata:
labels:
app: rabbit-mq
spec:
containers:
- image: rabbitmq:3.6.1-management
name: rabbit-mq
ports:
- containerPort: 5672
volumeMounts:
- mountPath: /etc/rabbitmq
name: rabbit-mq-data
restartPolicy: Always
hostname: rabbit-mq
volumes:
- name: rabbit-mq-data
persistentVolumeClaim:
claimName: rabbit-mq-data
Service: 服务:
apiVersion: v1
kind: Service
metadata:
name: rabbit-mq-service
labels:
app: rabbit-mq
namespace: default
spec:
type: ClusterIP
ports:
- port: 5672
selector:
app: rabbit-mq
As I tested with other services and as it says in documentation, ClusterIP service should be visible to all pods and nodes inside cluster. 正如我对其他服务进行的测试以及在文档中所说的那样,ClusterIP服务对于群集内的所有Pod和节点都应该可见。 I need my RabbitMQ service to be accessible only inside cluster.
我需要RabbitMQ服务只能在集群内部访问。 As I defined port 5672, same is used for targetPort.
正如我定义的端口5672一样,它也用于targetPort。
I have .NET Core application connecting to service with following connection string: amqp://user:password@10.100.10.10:5672/
我有.NET Core应用程序使用以下连接字符串连接到服务:
amqp://user:password@10.100.10.10:5672/
kubectl get svc rabbit-mq-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE rabbit-mq-service ClusterIP 10.100.10.10 <none> 5672/TCP 3h7m
kubectl get svc rabbit-mq-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE rabbit-mq-service ClusterIP 10.100.10.10 <none> 5672/TCP 3h7m
When I try to connect to RabbitMQ, I get the error: 当我尝试连接到RabbitMQ时,出现错误:
Unhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.TimeoutException: The operation has timed out.
Have I misunderstood how ClusterIP service works? 我是否误解了ClusterIP服务的工作方式?
Try this: 尝试这个:
apiVersion: v1
kind: Service
metadata:
name: rabbit-mq-service
labels:
app: rabbit-mq
namespace: default
spec:
type: ClusterIP
clusterIP: None
ports:
- port: 5672
selector:
app: rabbit-mq
and amqp://user:password@rabbit-mq-service:5672/
和
amqp://user:password@rabbit-mq-service:5672/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.