hashicorp / consul-k8s

First-class support for Consul Service Mesh on Kubernetes
https://www.consul.io/docs/k8s
Mozilla Public License 2.0
666 stars 317 forks source link

Consul does not ignore services with consul.hashicorp.com/service-ignore=true #4162

Open kbreit-insight opened 1 month ago

kbreit-insight commented 1 month ago

Community Note


Overview of the Issue

I am deploying RabbitMQ and integrating it into a Consul service mesh. RabbitMQ ships with multiple services pointing towards it server. The consul-connect-inject-init init container is giving errors that there are multiple services pointing to the pod and I should set the consul.hashicorp.com/service-ignore=true label. All but one of the services has this label assigned but it's still giving the error.

2024-07-09T21:09:29.076Z [ERROR] There are multiple Consul services registered for this pod when there must only be one. Check if there are multiple Kubernetes services selecting this pod and add the label `consul.hashicorp.com/service-ignore: "true"` to all services except the one used by Consul for handling requests.
2024-07-09T21:09:29.076Z [ERROR] Timed out waiting for service registration: error="did not find correct number of services, found: 4, services: &{Node:0xc001095050 Services:[0xc000bf4ea0 0xc000bf50e0 0xc000bf5320 0xc000bf57a0]}"
2024-07-09T21:09:29.076Z [INFO]  consul-server-connection-manager: stopping
2024-07-09T21:09:29.078Z [INFO]  consul-server-connection-manager: ACL auth method logout succeeded

on aiocp2(rabbitmq) pcp-dev-sandbox/kbreit/crossplane on  main [!?]
➜ kubectl get svc --show-labels
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE    LABELS
cluster          ClusterIP   172.30.237.192   <none>        15672/TCP,15692/TCP,5672/TCP   63d    app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster,app.kubernetes.io/part-of=rabbitmq,consul.hashicorp.com/service-ignore=true
cluster-nodes    ClusterIP   None             <none>        4369/TCP,25672/TCP             63d    app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster,app.kubernetes.io/part-of=rabbitmq,consul.hashicorp.com/service-ignore=true
cluster-server   ClusterIP   172.30.99.122    <none>        15672/TCP,15692/TCP,5672/TCP   7h3m   app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster-server,app.kubernetes.io/part-of=rabbitmq

Reproduction Steps

Deploy RabbitMQ operator using the instructions at https://www.rabbitmq.com/kubernetes/operator/operator-overview. Alternatively, a statefulset could be deployed with a similar configuration for POC, but I haven't tested it with that setup. Deploy the operator controller with the following manifest. Note, some of this may be populated automatically.

apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
  annotations:
  labels:
    consul.hashicorp.com/service-ignore: "true"
  name: cluster
  namespace: rabbitmq
spec:
  delayStartSeconds: 30
  image: rabbitmq:3.13.1-management
  override:
    statefulSet:
      spec:
        template:
          metadata:
            annotations:
              consul.hashicorp.com/connect-inject: "true"
              consul.hashicorp.com/transparent-proxy: "true"
              k8s.v1.cni.cncf.io/networks: '[{ "name":"consul-cni","namespace": "rabbitmq"
                }]'
          spec:
            containers: []
            securityContext: {}
  persistence:
    storage: 10Gi
  rabbitmq: {}
  replicas: 1
  service:
    type: ClusterIP
  terminationGracePeriodSeconds: 604800
  tls: {}

Logs

Expected behavior

The pod should come up as it should not see the services which have this label.

Environment details

kbreit-insight commented 1 month ago

I tried to set my cluster-server service to have only a single port and it continued to exhibit this behavior.

2024-07-11T16:06:32.475Z [ERROR] There are multiple Consul services registered for this pod when there must only be one. Check if there are multiple Kubernetes services selecting this pod and add the label `consul.hashicorp.com/service-ignore: "true"` to all services except the one used by Consul for handling requests.

on aiocp2(rabbitmq) ~
➜ kubectl get svc --show-labels
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE    LABELS
cluster          ClusterIP   172.30.237.192   <none>        15672/TCP,15692/TCP,5672/TCP   64d    app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster,app.kubernetes.io/part-of=rabbitmq,consul.hashicorp.com/service-ignore=true
cluster-nodes    ClusterIP   None             <none>        4369/TCP,25672/TCP             64d    app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster,app.kubernetes.io/part-of=rabbitmq,consul.hashicorp.com/service-ignore=true
cluster-server   ClusterIP   172.30.99.122    <none>        5672/TCP                       2d1h   app.kubernetes.io/component=rabbitmq,app.kubernetes.io/name=cluster-server,app.kubernetes.io/part-of=rabbitmq