Unable to connect to ClusterIP service

9/9/2019

I've have RabbitMQ deployment with ClusterIP service.

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. I need my RabbitMQ service to be accessible only inside cluster. As I defined port 5672, same is used for targetPort.

I have .NET Core application connecting to service with following connection string: 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

When I try to connect to RabbitMQ, I get the error:

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?

-- Andrija
.net-core
kubernetes
rabbitmq

1 Answer

9/9/2019

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/

-- FL3SH
Source: StackOverflow