k8s中創(chuàng)建rabbitmq集群

在k8s中創(chuàng)建一個rabbitmq 需要用到configmap\statefulset\集群相關的svc\管理頁面訪問相關的svc深浮,然后還需要一個serviceaccount提供訪問node節(jié)點上ep的權限岳守。


創(chuàng)建serviceaccount

role\rolebinding\serviceaccount創(chuàng)建
 
kubectl -n default create role endpoint-reader --verb=get --resource=endpoints
 
kubectl -n default create serviceaccount rabbitmq
 
kubectl -n default create rolebinding endpoint-reader --role=endpoint-reader --serviceaccount=default:rabbitmq

sts\configmq\svc創(chuàng)建

#rabbitmq-cluster-svc.yaml
 
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-cluster
  namespace: default
  labels:
    app: rabbitmq-cluster
    type: LoadBalancer
spec:
  ports:
    - name: http
      protocol: TCP
      port: 15672
      targetPort: 15672
    - name: amqp
      protocol: TCP
      port: 5672
      targetPort: 5672
  selector:
    app: rabbitmq
  clusterIP: None
  type: ClusterIP
  sessionAffinity: None
  publishNotReadyAddresses: true
 
---
#rabbitmq-lb-svc.yaml
 
apiVersion: v1
kind: Service
metadata:
  name: rabbitmq-loadbalancer
  namespace: default
  labels:
    app: rabbitmq
spec:
  ports:
    - name: management
      protocol: TCP
      port: 15672
      targetPort: 15672
    - name: mqservice
      protocol: TCP
      port: 5672
      targetPort: 5672
  selector:
    app: rabbitmq
  type: NodePort
  sessionAffinity: None
  externalTrafficPolicy: Cluster
---
#rabbitmq-configmp.yaml
 
apiVersion: v1
kind: ConfigMap
metadata:
  name: rabbitmq-config
  namespace: default
  selfLink: /api/v1/namespaces/default/configmaps/rabbitmq-config
  uid: ac4801c3-2e12-4fc6-b1fb-c0d2b51c6d96
  resourceVersion: '103920685'
  creationTimestamp: '2021-03-29T08:19:53Z'
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"v1","data":{"enabled_plugins":"[rabbitmq_management,rabbitmq_peer_discovery_k8s].\n","rabbitmq.conf":"##
      Cluster formation. See https://www.rabbitmq.com/cluster-formation.html to
      learn more.\ncluster_formation.peer_discovery_backend  =
      rabbit_peer_discovery_k8s\ncluster_formation.k8s.host =
      kubernetes.default.svc.cluster.local\n## Should RabbitMQ node name be
      computed from the pod's hostname or IP address?\n## IP addresses are not
      stable, so using [stable] hostnames is recommended when possible.\n## Set
      to \"hostname\" to use pod hostnames.\n## When this value is changed, so
      should the variable used to set the RABBITMQ_NODENAME\n## environment
      variable.\ncluster_formation.k8s.address_type = hostname\n## How often
      should node cleanup checks run?\ncluster_formation.node_cleanup.interval =
      30\n## Set to false if automatic removal of unknown/absent nodes\n## is
      desired. This can be dangerous, see\n##  *
      https://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup\n##
      *
      https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ\ncluster_formation.node_cleanup.only_log_warning
      = true\ncluster_partition_handling = autoheal\n## See
      https://www.rabbitmq.com/ha.html#master-migration-data-locality\nqueue_master_locator=min-masters\n##
      See
      https://www.rabbitmq.com/access-control.html#loopback-users\nloopback_users.guest
      = false\n\ncluster_formation.randomized_startup_delay_range.min =
      0\ncluster_formation.randomized_startup_delay_range.max = 2\n#
      必須設置service_name,否則Pod無法正常啟動骨稿,這里設置后可以不設置statefulset下env中的K8S_SERVICE_NAME變量\ncluster_formation.k8s.service_name
      = rabbitmq-cluster\n#
      必須設置hostname_suffix,否則節(jié)點不能成為集群,同時保證namespace正確\ncluster_formation.k8s.hostname_suffix
      = .rabbitmq-cluster.default.svc.cluster.local\n#
      內(nèi)存上限\nvm_memory_high_watermark.absolute = 6GB\n#
      硬盤上限\ndisk_free_limit.absolute =
      20GB\n"},"kind":"ConfigMap","metadata":{"annotations":{},"creationTimestamp":"2021-03-29T08:19:53Z","name":"rabbitmq-config","namespace":"default","selfLink":"/api/v1/namespaces/default/configmaps/rabbitmq-config","uid":"ac4801c3-2e12-4fc6-b1fb-c0d2b51c6d96"}}
data:
  enabled_plugins: |
    [rabbitmq_management,rabbitmq_peer_discovery_k8s].
  rabbitmq.conf: >
    ## Cluster formation. See https://www.rabbitmq.com/cluster-formation.html to
    learn more.
 
    cluster_formation.peer_discovery_backend  = rabbit_peer_discovery_k8s
 
    cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
 
    ## Should RabbitMQ node name be computed from the pod's hostname or IP
    address?
 
    ## IP addresses are not stable, so using [stable] hostnames is recommended
    when possible.
 
    ## Set to "hostname" to use pod hostnames.
 
    ## When this value is changed, so should the variable used to set the
    RABBITMQ_NODENAME
 
    ## environment variable.
 
    cluster_formation.k8s.address_type = hostname
 
    ## How often should node cleanup checks run?
 
    cluster_formation.node_cleanup.interval = 30
 
    ## Set to false if automatic removal of unknown/absent nodes
 
    ## is desired. This can be dangerous, see
 
    ##  *
    https://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup
 
    ##  *
    https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ
 
    cluster_formation.node_cleanup.only_log_warning = true
 
    cluster_partition_handling = autoheal
 
    ## See https://www.rabbitmq.com/ha.html#master-migration-data-locality
 
    queue_master_locator=min-masters
 
    ## See https://www.rabbitmq.com/access-control.html#loopback-users
 
    loopback_users.guest = false
 
 
    cluster_formation.randomized_startup_delay_range.min = 0
 
    cluster_formation.randomized_startup_delay_range.max = 2
 
    # 必須設置service_name杂数,否則Pod無法正常啟動奋单,這里設置后可以不設置statefulset下env中的K8S_SERVICE_NAME變量
 
    cluster_formation.k8s.service_name = rabbitmq-cluster
 
    # 必須設置hostname_suffix锉试,否則節(jié)點不能成為集群,同時保證namespace正確
 
    cluster_formation.k8s.hostname_suffix =
    .rabbitmq-cluster.default.svc.cluster.local
 
    # 內(nèi)存上限
 
    vm_memory_high_watermark.absolute = 6GB
 
    # 硬盤上限
 
    disk_free_limit.absolute = 20GB
 
---
#rabbitmq-sts.yaml
 
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbitmq
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rabbitmq
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: rabbitmq
    spec:
      serviceAccountName: rabbitmq
      volumes:
        - name: config-volume
          configMap:
            name: rabbitmq-config
            items:
              - key: rabbitmq.conf
                path: rabbitmq.conf
              - key: enabled_plugins
                path: enabled_plugins
            defaultMode: 420
      containers:
        - name: rabbitmq
          image: '567969457461.dkr.ecr.cn-northwest-1.amazonaws.com.cn/rabbitmq:3.7'
          ports:
            - name: http
              containerPort: 15672
              protocol: TCP
            - name: amqp
              containerPort: 5672
              protocol: TCP
          env:
            - name: HOSTNAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: RABBITMQ_USE_LONGNAME
              value: 'true'
            - name: RABBITMQ_NODENAME
              value: >-
                rabbit@$(HOSTNAME).rabbitmq-cluster-c.$(NAMESPACE).svc.cluster.local
            - name: RABBITMQ_ERLANG_COOKIE
              value: a5mjCA21
          resources: {}
          volumeMounts:
            - name: config-volume
              mountPath: /etc/rabbitmq
            - name: mq-data
              mountPath: /var/lib/rabbitmq
          livenessProbe:
            exec:
              command:
                - rabbitmqctl
                - status
            initialDelaySeconds: 60
            timeoutSeconds: 15
            periodSeconds: 60
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            exec:
              command:
                - rabbitmqctl
                - status
            initialDelaySeconds: 20
            timeoutSeconds: 10
            periodSeconds: 60
            successThreshold: 1
            failureThreshold: 3
  volumeClaimTemplates:
    - kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: mq-data
        creationTimestamp: null
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 100Gi
        storageClassName: ebs-gp2-new
        volumeMode: Filesystem
  serviceName: rabbitmq-cluster
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末览濒,一起剝皮案震驚了整個濱河市呆盖,隨后出現(xiàn)的幾起案子拖云,更是在濱河造成了極大的恐慌,老刑警劉巖应又,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件江兢,死亡現(xiàn)場離奇詭異,居然都是意外死亡丁频,警方通過查閱死者的電腦和手機杉允,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來席里,“玉大人叔磷,你說我怎么就攤上這事〗贝牛” “怎么了改基?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長咖为。 經(jīng)常有香客問我秕狰,道長,這世上最難降的妖魔是什么躁染? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任鸣哀,我火速辦了婚禮,結果婚禮上吞彤,老公的妹妹穿的比我還像新娘我衬。我一直安慰自己,他們只是感情好饰恕,可當我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布挠羔。 她就那樣靜靜地躺著,像睡著了一般埋嵌。 火紅的嫁衣襯著肌膚如雪破加。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天雹嗦,我揣著相機與錄音范舀,去河邊找鬼。 笑死俐银,一個胖子當著我的面吹牛尿背,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播捶惜,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼田藐,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起汽久,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤鹤竭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后景醇,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體臀稚,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年三痰,在試婚紗的時候發(fā)現(xiàn)自己被綠了吧寺。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡散劫,死狀恐怖稚机,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情获搏,我是刑警寧澤赖条,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站常熙,受9級特大地震影響纬乍,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜裸卫,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一仿贬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧彼城,春花似錦诅蝶、人聲如沸退个。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽语盈。三九已至舱馅,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間刀荒,已是汗流浹背代嗤。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留缠借,地道東北人干毅。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像泼返,于是被迫代替她去往敵國和親硝逢。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容