我已经通过RabbitIP部署了ClusterIP服务。
部署:
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
服务:
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
正如我对其他服务进行的测试以及在文档中所述,ClusterIP服务对于群集内的所有pod和节点都应该可见。 我需要RabbitMQ服务只能在集群内部访问。 正如我定义的5672端口一样,它也用于targetPort。
我有.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
当我尝试连接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.
我是否误解了ClusterIP服务的工作原理?
答案 0 :(得分:1)
尝试一下:
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
和amqp://user:password@rabbit-mq-service:5672/