From 276f4460555fec0ab15cd2e90d091e2fd861515c Mon Sep 17 00:00:00 2001 From: Corey O'Brien Date: Sat, 7 Apr 2018 12:55:08 -0400 Subject: [PATCH] [stable/rabbitmq-ha] Clustering fixes (#4610) * Use hostnames instead of IPs for node names since IPs are ephemeral * Always use a headless clusterIP service for clustering * Never use a cached erlang cookie since we are always providing it --- stable/rabbitmq-ha/Chart.yaml | 2 +- stable/rabbitmq-ha/templates/configmap.yaml | 4 +- .../templates/service-discovery.yaml | 70 +++++++++++++++++++ stable/rabbitmq-ha/templates/statefulset.yaml | 17 +++-- 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 stable/rabbitmq-ha/templates/service-discovery.yaml diff --git a/stable/rabbitmq-ha/Chart.yaml b/stable/rabbitmq-ha/Chart.yaml index a25a75bf7c..0da25b86d5 100644 --- a/stable/rabbitmq-ha/Chart.yaml +++ b/stable/rabbitmq-ha/Chart.yaml @@ -1,7 +1,7 @@ name: rabbitmq-ha apiVersion: v1 appVersion: 3.7.3 -version: 1.0.8 +version: 1.1.0 description: Highly available RabbitMQ cluster, the open source message broker software that implements the Advanced Message Queuing Protocol (AMQP). keywords: diff --git a/stable/rabbitmq-ha/templates/configmap.yaml b/stable/rabbitmq-ha/templates/configmap.yaml index 6abd862433..a83caa68c5 100644 --- a/stable/rabbitmq-ha/templates/configmap.yaml +++ b/stable/rabbitmq-ha/templates/configmap.yaml @@ -47,7 +47,7 @@ data: rabbitmq.conf: | ## RabbitMQ configuration ## Ref: https://github.com/rabbitmq/rabbitmq-server/blob/master/docs/rabbitmq.conf.example - + ## Authentification {{- if .Values.rabbitmqAuth.enabled }} {{ .Values.rabbitmqAuth.config | indent 4 }} @@ -56,7 +56,7 @@ data: ## Clustering cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s cluster_formation.k8s.host = kubernetes.default.svc.cluster.local - cluster_formation.k8s.address_type = ip + cluster_formation.k8s.address_type = hostname cluster_formation.node_cleanup.interval = 10 cluster_formation.node_cleanup.only_log_warning = false cluster_partition_handling = autoheal diff --git a/stable/rabbitmq-ha/templates/service-discovery.yaml b/stable/rabbitmq-ha/templates/service-discovery.yaml new file mode 100644 index 0000000000..c602bcb7f0 --- /dev/null +++ b/stable/rabbitmq-ha/templates/service-discovery.yaml @@ -0,0 +1,70 @@ +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.annotations }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +{{- end }} + name: {{ template "rabbitmq-ha.fullname" . }}-discovery + labels: + app: {{ template "rabbitmq-ha.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + clusterIP: None + ports: + - name: http + protocol: TCP + port: {{ .Values.rabbitmqManagerPort }} + targetPort: http + - name: amqp + protocol: TCP + port: {{ .Values.rabbitmqNodePort }} + targetPort: amqp + - name: epmd + protocol: TCP + port: {{ .Values.rabbitmqEpmdPort }} + targetPort: epmd + {{- if .Values.rabbitmqSTOMPPlugin.enabled }} + - name: stomp-tcp + protocol: TCP + port: 1883 + targetPort: stomp-tcp + - name: stomp-ssl + protocol: TCP + port: 8883 + targetPort: stomp-ssl + {{- end }} + {{- if .Values.rabbitmqWebSTOMPPlugin.enabled }} + - name: stomp-ws + protocol: TCP + port: 15674 + targetPort: stomp-ws + {{- end }} + {{- if .Values.rabbitmqMQTTPlugin.enabled }} + - name: mqtt-tcp + protocol: TCP + port: 61613 + targetPort: mqtt-tcp + - name: mqtt-ssl + protocol: TCP + port: 61614 + targetPort: mqtt-ssl + {{- end }} + {{- if .Values.rabbitmqWebMQTTPlugin.enabled }} + - name: mqtt-ws + protocol: TCP + port: 15675 + targetPort: mqtt-ws + {{- end }} + {{- if .Values.rabbitmqAmqpsSupport.enabled }} + - name: amqps + protocol: TCP + port: {{ .Values.rabbitmqAmqpsSupport.amqpsNodePort }} + targetPort: amqps + {{- end }} + selector: + app: {{ template "rabbitmq-ha.name" . }} + release: {{ .Release.Name }} + type: ClusterIP diff --git a/stable/rabbitmq-ha/templates/statefulset.yaml b/stable/rabbitmq-ha/templates/statefulset.yaml index ff46b8811d..b43f6a221a 100644 --- a/stable/rabbitmq-ha/templates/statefulset.yaml +++ b/stable/rabbitmq-ha/templates/statefulset.yaml @@ -8,7 +8,7 @@ metadata: release: {{ .Release.Name }} heritage: {{ .Release.Service }} spec: - serviceName: {{ template "rabbitmq-ha.fullname" . }} + serviceName: {{ template "rabbitmq-ha.fullname" . }}-discovery replicas: {{ .Values.replicaCount }} updateStrategy: type: {{ .Values.updateStrategy }} @@ -27,12 +27,14 @@ spec: initContainers: - name: copy-rabbitmq-config image: busybox - command: ['sh', '-c', 'cp /configmap/* /etc/rabbitmq'] + command: ['sh', '-c', 'cp /configmap/* /etc/rabbitmq; rm -f /var/lib/rabbitmq/.erlang.cookie'] volumeMounts: - name: configmap mountPath: /configmap - name: config mountPath: /etc/rabbitmq + - name: data + mountPath: /var/lib/rabbitmq containers: - name: {{ .Chart.Name }} image: {{ .Values.image.repository }}:{{ .Values.image.tag }} @@ -93,16 +95,19 @@ spec: initialDelaySeconds: 10 timeoutSeconds: 5 env: - - name: MY_POD_IP + - name: MY_POD_NAME valueFrom: fieldRef: - fieldPath: status.podIP + apiVersion: v1 + fieldPath: metadata.name - name: RABBITMQ_USE_LONGNAME value: "true" - name: RABBITMQ_NODENAME - value: "rabbit@$(MY_POD_IP)" + value: rabbit@$(MY_POD_NAME).{{ template "rabbitmq-ha.fullname" . }}-discovery.{{ .Release.Namespace }}.svc.cluster.local + - name: K8S_HOSTNAME_SUFFIX + value: .{{ template "rabbitmq-ha.fullname" . }}-discovery.{{ .Release.Namespace }}.svc.cluster.local - name: K8S_SERVICE_NAME - value: {{ template "rabbitmq-ha.fullname" . }} + value: {{ template "rabbitmq-ha.fullname" . }}-discovery - name: RABBITMQ_ERLANG_COOKIE valueFrom: secretKeyRef: