Kubernetes - - k8s - v1.12.3 持久化安装rabbitmq集群

时间:2022-12-22 17:57:14

1,下载文件

  • https://github.com/xiaoqshuo/k8s-cluster/tree/master/k8s-rabbitmq-cluster

2,创建namespace

kubectl create namespace public-service
  • 注:如果不使用public-service,需要更改所有yaml文件的public-service为你namespace。
sed -i "s#public-service#YOUR_NAMESPACE#g" *.yaml

3,创建持久化pv

  • 此处采用的是静态PV方式,后端使用的是NFS,为了方便扩展可以使用动态PV较好。
  • 注:本文档使用 k8s-node02 为 NFS 服务器
[root@k8s-node01 nfs]# mkdir -p rmp-cluster/{rmp-cluster01,rmp-cluster02,rmp-cluster03}
[root@k8s-node01 nfs]# cd rmp-cluster/
[root@k8s-node01 rmp-cluster]# ls
rmp-cluster01  rmp-cluster02  rmp-cluster03

4,创建集群

[root@k8s-master01 k8s-cluster]# kubectl apply -f k8s-rabbitmq-cluster/
statefulset.apps/rmq-cluster created
configmap/rmq-cluster-config created
persistentvolume/pv-rmq-1 created
persistentvolume/pv-rmq-2 created
persistentvolume/pv-rmq-3 created
serviceaccount/rmq-cluster created
role.rbac.authorization.k8s.io/rmq-cluster created
rolebinding.rbac.authorization.k8s.io/rmq-cluster created
secret/rmq-cluster-secret created
service/rmq-cluster created
service/rmq-cluster-balancer created

5,查看 pods、pv、pvc

[root@k8s-master01 k8s-efk]# kubectl get pod -n public-service
NAME            READY   STATUS    RESTARTS   AGE
rmq-cluster-0   1/1     Running   1          16m
rmq-cluster-1   1/1     Running   0          12m
rmq-cluster-2   1/1     Running   0          8m39s

[root@k8s-master01 k8s-efk]# kubectl get pv -n public-service
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                                   STORAGECLASS        REASON   AGE
pv-rmq-1   4Gi        RWX            Recycle          Bound       public-service/rabbitmq-storage-rmq-cluster-0           rmq-storage-class            16m
pv-rmq-2   4Gi        RWX            Recycle          Bound       public-service/rabbitmq-storage-rmq-cluster-1           rmq-storage-class            16m
pv-rmq-3   4Gi        RWX            Recycle          Bound       public-service/rabbitmq-storage-rmq-cluster-2           rmq-storage-class            16m

[root@k8s-master01 k8s-efk]# kubectl get pvc -n public-service
NAME                             STATUS   VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS        AGE
rabbitmq-storage-rmq-cluster-0   Bound    pv-rmq-1   4Gi        RWX            rmq-storage-class   16m
rabbitmq-storage-rmq-cluster-1   Bound    pv-rmq-2   4Gi        RWX            rmq-storage-class   12m
rabbitmq-storage-rmq-cluster-2   Bound    pv-rmq-3   4Gi        RWX            rmq-storage-class   8m47s

6,访问测试

  • 通过NodePort的端口 http://k8s-master-lb:31146
  • 账号密码:guest

Kubernetes - - k8s - v1.12.3 持久化安装rabbitmq集群

Kubernetes - - k8s - v1.12.3 持久化安装rabbitmq集群

7,存在问题

  • yaml中有个secret
[root@k8s-master01 k8s-rabbitmq-cluster]# more rabbitmq-secret.yaml
kind: Secret
apiVersion: v1
metadata:
  name: rmq-cluster-secret
  namespace: public-service
stringData:
  cookie: ERLANG_COOKIE
  password: RABBITMQ_PASS
  url: amqp://RABBITMQ_USER:RABBITMQ_PASS@rmq-cluster-balancer
  username: RABBITMQ_USER
type: Opaque
  • 定义了username和password,然后在rabbitmq-cluster-ss.yaml引用作为默认账号密码,而且在configmap中也禁用了guest,但是没有生效。此问题待解决。
[root@k8s-master01 k8s-rabbitmq-cluster]# more rabbitmq-cluster-ss.yaml
...
        env:
        - name: RABBITMQ_DEFAULT_USER
          valueFrom:
            secretKeyRef:
              key: username
              name: rmq-cluster-secret
        - name: RABBITMQ_DEFAULT_PASS
          valueFrom:
            secretKeyRef:
              key: password
              name: rmq-cluster-secret
...
  • 参考
    • https://www.cnblogs.com/dukuan/p/9897443.html