1. 程式人生 > >kubernetes實戰(四):k8s持久化安裝rabbitmq叢集

kubernetes實戰(四):k8s持久化安裝rabbitmq叢集

1、下載檔案

https://github.com/dotbalo/k8s/tree/master/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較好。

[[email protected] rabbitmq-cluster-1]# cat /etc/exports
/k8s/rmq-cluster/rabbitmq-cluster-1/ *(rw,sync,no_subtree_check,no_root_squash)
/k8s/rmq-cluster/rabbitmq-cluster-2/ *(rw,sync,no_subtree_check,no_root_squash)
/k8s/rmq-cluster/rabbitmq-cluster-3/ *(rw,sync,no_subtree_check,no_root_squash)
[[email protected]
rabbitmq-cluster]# pwd /root/efk/rabbitmq-cluster [[email protected]-master01 rabbitmq-cluster]# ls rabbitmq-cluster-ss.yaml rabbitmq-pv.yaml rabbitmq-secret.yaml rabbitmq-service-lb.yaml rabbitmq-configmap.yaml rabbitmq-rbac.yaml rabbitmq-service-cluster.yaml README.md

  建立叢集

[
[email protected]
rabbitmq-cluster]# kubectl apply -f .

 

4、檢視

  pods、pv、pvc

[[email protected] rabbitmq-cluster]# kubectl get pods -n public-service
NAME            READY     STATUS    RESTARTS   AGE
rmq-cluster-0   1/1       Running   0          40m
rmq-cluster-1   1/1       Running   0          39m
rmq-cluster-2   1/1       Running   0          39m
[[email protected] rabbitmq-cluster]# 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-2   rmq-storage-class             49m
pv-rmq-2   4Gi        RWX            Recycle          Bound     public-service/rabbitmq-storage-rmq-cluster-1   rmq-storage-class             49m
pv-rmq-3   4Gi        RWX            Recycle          Bound     public-service/rabbitmq-storage-rmq-cluster-0   rmq-storage-class             49m
[[email protected]-master01 rabbitmq-cluster]# kubectl get pvc -n public-service
NAME                             STATUS    VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS        AGE
rabbitmq-storage-rmq-cluster-0   Bound     pv-rmq-3   4Gi        RWX            rmq-storage-class   48m
rabbitmq-storage-rmq-cluster-1   Bound     pv-rmq-2   4Gi        RWX            rmq-storage-class   48m
rabbitmq-storage-rmq-cluster-2   Bound     pv-rmq-1   4Gi        RWX            rmq-storage-class   48m
[[email protected]-master01 rabbitmq-cluster]#

  services,此時使用的NodePort方式,可改為traefik模式

[[email protected] rabbitmq-cluster]# kubectl get services -n public-service
NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                          AGE
rmq-cluster            ClusterIP   None            <none>        5672/TCP                         1h
rmq-cluster-balancer   NodePort    10.107.221.85   <none>        15672:30051/TCP,5672:31892/TCP   1h

 

5、訪問測試

  通過NodePort的埠

  賬號密碼:guest

 

6、存在問題

  上述yaml中有個secret

[[email protected] rabbitmq-cluster]# cat 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:[email protected]
  username: RABBITMQ_USER

  定義了username和password,然後在rabbitmq-cluster-ss.yaml引用作為預設賬號密碼,而且在configmap中也禁用了guest,但是沒有生效。此問題待解決。