0

I currently trying to deploy simple RabbitMQ cluster for my project. So far, I found this two example that suit my needed. https://www.linkedin.com/pulse/deploying-rabbitmq-cluster-kubernetes-part-1-darshana-dinushal/

https://github.com/marcel-dempers/docker-development-youtube-series/blob/master/messaging/rabbitmq/kubernetes/rabbit-statefulset.yaml

And since official website, articles and tutorial videos about RabbitMQ on Kubernetes are pointing to large production deployment. I only get this 2 example to follow.

And when I try it RabbitMQ pod is stuck on pending state while other pods are running fine. I currently use YAML files from the first example.

kubectl describe pod rabbitmq-0
Name:           rabbitmq-0
Namespace:      default
Priority:       0
Node:           <none>
Labels:         app=rabbitmq
                controller-revision-hash=rabbitmq-84b847b5d5
                statefulset.kubernetes.io/pod-name=rabbitmq-0
Annotations:    <none>
Status:         Pending
IP:
IPs:            <none>
Controlled By:  StatefulSet/rabbitmq
Init Containers:
  config:
    Image:      busybox
    Port:       <none>
    Host Port:  <none>
    Command:
      /bin/sh
      -c
      cp /tmp/config/rabbitmq.conf /config/rabbitmq.conf && ls -l /config/ && cp /tmp/config/enabled_plugins /etc/rabbitmq/enabled_plugins
    Environment:  <none>
    Mounts:
      /config/ from config-file (rw)
      /etc/rabbitmq/ from plugins-file (rw)
      /tmp/config/ from config (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-ffj67 (ro)
Containers:
  rabbitmq:
    Image:       rabbitmq:3.8-management
    Ports:       4369/TCP, 5672/TCP
    Host Ports:  0/TCP, 0/TCP
    Environment:
      RABBIT_POD_NAME:         rabbitmq-0 (v1:metadata.name)
      RABBIT_POD_NAMESPACE:    default (v1:metadata.namespace)
      RABBITMQ_NODENAME:       rabbit@$(RABBIT_POD_NAME).rabbitmq.$(RABBIT_POD_NAMESPACE).svc.cluster.local
      RABBITMQ_USE_LONGNAME:   true
      RABBITMQ_CONFIG_FILE:    /config/rabbitmq
      RABBITMQ_ERLANG_COOKIE:  <set to the key 'RABBITMQ_ERLANG_COOKIE' in secret 'rabbit-secret'>  Optional: false
      K8S_HOSTNAME_SUFFIX:     .rabbitmq.$(RABBIT_POD_NAMESPACE).svc.cluster.local
    Mounts:
      /config/ from config-file (rw)
      /etc/rabbitmq/ from plugins-file (rw)
      /var/lib/rabbitmq from data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-ffj67 (ro)
Conditions:
  Type           Status
  PodScheduled   False
Volumes:
  data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  data-rabbitmq-0
    ReadOnly:   false
  config-file:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  plugins-file:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      rabbitmq-config
    Optional:  false
  kube-api-access-ffj67:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason            Age                   From               Message
  ----     ------            ----                  ----               -------
  Warning  FailedScheduling  2m25s (x39 over 89m)  default-scheduler  0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
David Maze
  • 130,717
  • 29
  • 175
  • 215
TaeXtreme
  • 135
  • 3
  • 11
  • It can be in Pending state for a lot of reasons. Do a `kubectl describe pod ` to find out why it is pending and add that to you question. – Chris Jun 15 '22 at 06:07
  • @Chris posted output from kubectl describe pod – TaeXtreme Jun 15 '22 at 06:11
  • 1 pod has unbound immediate PersistentVolumeClaims <--- there is your error. Prob. something to do with the volume-mount data-rabbitmq-0. – JustLudo Jun 15 '22 at 06:25
  • Does [Kubernetes - pod has unbound immediate PersistentVolumeClaims](https://stackoverflow.com/questions/60774220/kubernetes-pod-has-unbound-immediate-persistentvolumeclaims) have an answer for you? Usually this is something that would be handled at the cluster level and not a programming problem _per se_. – David Maze Jun 15 '22 at 10:23

1 Answers1

2

Since I had tested deploying RabbitMQ via docker-compose and it worked before.

I discovered a tool called Kompose and I use it to convert my rabbitmq docker-compose file to k8s yaml files.

And it works!.

Yaml files that generate from Kompose.

service file

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.26.0 (40646f47)
  labels:
    io.kompose.service: rabbitmq3
  name: rabbitmq3
spec:
  type: LoadBalancer
  ports:
    - name: amqp
      port: 5672
      targetPort: 5672
    - name: discovery
      port: 15672
      targetPort: 15672
  selector:
    io.kompose.service: rabbitmq3

deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.26.0 (40646f47)
  labels:
    io.kompose.service: rabbitmq3
  name: rabbitmq3
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: rabbitmq3
  strategy: { }
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.26.0 (40646f47)
      labels:
        io.kompose.service: rabbitmq3
    spec:
      containers:
        - env:
            - name: RABBITMQ_DEFAULT_PASS
              value: rabbitpassword
            - name: RABBITMQ_DEFAULT_USER
              value: rabbituser
          image: rabbitmq:management-alpine
          name: rabbitmq
          ports:
            - containerPort: 15672
              name: discovery
            - containerPort: 5672
              name: amqp
          resources: { }
      restartPolicy: Always
TaeXtreme
  • 135
  • 3
  • 11