【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)
【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(雙主雙從+同步模式)
版權 本文為云錄原創文章,轉載無需和我聯系,但請注明來自云錄 https://www.yunzhuan.site
rocketMQ高可用有很多種方式,比如:單機部署,多主集群,雙主雙從同步部署,雙主雙從異步部署,以及多主多從部署。部署集群可按照自己公司的實際情況進行部署。
單機部署:只啟動一個rocketMQ實例就可以了,一般常用來本機測試使用。原因:一旦rocketMQ因某些原因掛掉,導致mq無法使用,則我們服務器無法接受信息與消費信息等。
多主集群:只部署mq主節點,無部署從節點。優點:配置簡單,單個Master宕機或重啟維護對應用無影響,即使機器宕機不可恢復情況下,也有其他主節點進行寫入操作,
消息也不會丟(異步刷盤丟失少量消息,同步刷盤一條不丟),性能最高;
雙主雙從同步:部署四個節點,每個主節點都有一個從節點,主與從節點的信息通過同步的方式進行保存。優點:消息不會丟失,即:主節點掛了后,從節點的消息也不會造成丟失,只不過沒法接受新消息,只能消費,但是能保證我消費的消息一定是準確的。缺點:客戶端接受服務器響應時間長。可用于消息安全高的場景。
雙主雙從異步:與雙主雙從一致,只不過在主從數據傳輸是通過異步的方式,優點:客戶端能快速的接收到服務器的消息,缺點:主節點掛的情況,從節點會丟失一部分消息。可用于允許消息丟失,吞吐量高的情景。
?? 創建存儲
這里我用ceph,需要自己準備存儲
?? 需要準備的材料 自行下載
apache-maven-3.6.3-bin.tar.gz
rocketmq-all-4.9.4-bin-release.zip
rocketmq-dashboard-master.zip
yarn-v1.22.10.tar.gz https://github.com/yarnpkg/yarn/releases/download/v1.22.10/yarn-v1.22.10.tar.gz
?? 創建RocketMQ集群(雙主雙從同步模式)
制作rocketmq鏡像
[root rocketmqimage]# ll
total 32200
-rw-r--r--. 1 root root 319 May 15 13:38 Dockerfile
drwxr-xr-x. 6 root root 103 May 15 13:37 rocketmq-all-4.9.4-bin-release
-rw-rw-r--. 1 root root 32967749 May 15 13:31 rocketmq-all-4.9.4-bin-release.zip
1:解壓rocketmq-all-4.9.4-bin-release.zip 將runbroker.sh腳本文件里的內存設置調整小點
unzip rocketmq-all-4.9.4-bin-release.zip
vim rocketmq-all-4.9.4-bin-release/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g"
2:準備dockerfile
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release /usr/local/rocketmq-all-4.9.4-bin-release
RUN mkdir -p /data/rocketmq/store
CMD ["/bin/bash"]
3:制作鏡像并上傳到Harbor倉庫
docker build -t 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0 .
docker push 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
制作nameserver的image鏡像
將上面rocketmq_image目錄下的包rocketmq-all-4.9.4-bin-release 拷貝過來
[root nameserver_image]# ll
total 8
-rw-r--r-- 1 root root 525 Aug 23 2022 Dockerfile
-rw-r--r-- 1 root root 17 Aug 23 2022 namesrv.properties
drwxr-xr-x 6 root root 103 May 15 13:56 rocketmq-all-4.9.4-bin-release
1:準備 namesrv.properties 自定義nameserver的端口號
[root nameserver_image]# cat namesrv.properties
listenPort=20801
2:準備dockerfile
[root nameserver_image]# cat Dockerfile
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
COPY rocketmq-all-4.9.4-bin-release /usr/local/rocketmq-all-4.9.4-bin-release
COPY namesrv.properties /usr/local/rocketmq-all-4.9.4-bin-release/conf/
WORKDIR /usr/local/rocketmq-all-4.9.4-bin-release
CMD ["/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqnamesrv","-c","/usr/local/rocketmq-all-4.9.4-bin-release/conf/namesrv.properties"]
3: 制作鏡像并上傳到Harbor倉庫
docker build -t 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1 .
docker push 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1
制作rocketmq的web可視化界面的image鏡像
[root rockermq_web]# ll
total 14320
drwxr-xr-x 6 root root 99 Aug 23 2022 apache-maven-3.6.3
-rw-rw-r-- 1 dotnet dotnet 9506321 Aug 23 2022 apache-maven-3.6.3-bin.tar.gz
-rw-r--r-- 1 root root 674 May 15 15:26 Dockerfile
drwxr-xr-x 7 root root 213 Apr 11 2022 rocketmq-dashboard-master
-rw-rw-r-- 1 dotnet dotnet 3906355 Aug 23 2022 rocketmq-dashboard-master.zip
-rw-rw-r-- 1 dotnet dotnet 1244965 May 15 15:21 yarn-v1.22.10.tar.gz
1:下載rocketmq-dashboard-master.zip和apache-maven-3.6.3-bin.tar.gz 并解壓 2:修改 dashboard配置
vim rocketmq-dashboard-master/src/main/resources/application.yml
修改內容:
namesrvAddrs:
- mq-namesrv.romq.svc.cluster.local:20801
loginRequired: true
accessKey: rocketmq2
secretKey: 12345678
server:
port: 8080
servlet:
encoding:
charset: UTF-8
enabled: true
force: true
## SSL setting
# ssl:
# key-store: classpath:rmqcngkeystore.jks
# key-store-password: rocketmq
# key-store-type: PKCS12
# key-alias: rmqcngkey
spring:
application:
name: rocketmq-dashboard
logging:
config: classpath:logback.xml
rocketmq:
config:
# if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, default localhost:9876
# configure multiple namesrv addresses to manage multiple different clusters
namesrvAddrs:
- mq-namesrv.romq.svc.cluster.local:20801
# if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
isVIPChannel: false
# timeout for mqadminExt, default 5000ms
timeoutMillis:
# rocketmq-console's data path:dashboard/monitor
dataPath: /tmp/rocketmq-console/data
# set it false if you don't want use dashboard.default true
enableDashBoardCollect: true
# set the message track trace topic if you don't want use the default one
msgTrackTopicName:
ticketKey: ticket
# must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
loginRequired: true
useTLS: false
# set the accessKey and secretKey if you used acl設置acl權限
accessKey: rocketmq2 # if version > 4.4.0
secretKey: 12345678 # if version > 4.4.0
threadpool:
config:
coreSize: 10
maxSize: 10
keepAliveTime: 3000
queueSize: 5000
3:準備dockerfile
[root rockermq_web]# cat Dockerfile
FROM openjdk:8
RUN rm -f /etc/localtime \
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
ENV LANG en_US.UTF-8
ENV MAVEN_HOME /usr/local/maven
ENV PATH $PATH:$MAVEN_HOME/bin
COPY rocketmq-dashboard-master /usr/local/rocketmq-dashboard-master
COPY yarn-v1.22.10.tar.gz /root/.m2/repository/com/github/eirslett/yarn/1.22.10/
COPY apache-maven-3.6.3 /usr/local/maven
WORKDIR /usr/local/rocketmq-dashboard-master
RUN mvn clean package -Dmaven.test.skip=true
WORKDIR /usr/local/rocketmq-dashboard-master/target
EXPOSE 8080
CMD ["nohup","java","-jar","rocketmq-dashboard-1.0.1-SNAPSHOT.jar","&"]
4:制作鏡像并上傳到Harbor倉庫
docker build -t 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1 .
docker push 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1
準備配置文件 configmap
1:我的broker配置文件
[root config]# ll
total 16
-rw-rw-r--. 1 dotnet dotnet 638 May 15 15:53 broker-a.properties
-rw-rw-r--. 1 dotnet dotnet 630 May 15 15:53 broker-a-s.properties
-rw-rw-r--. 1 dotnet dotnet 636 May 15 15:53 broker-b.properties
-rw-rw-r--. 1 dotnet dotnet 632 May 15 15:53 broker-b-s.properties
[root config]# cat broker-a.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公網ip或是負載ip
listenPort=30811
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
#Broker 的角色
#- ASYNC_MASTER 異步復制Master
#- SYNC_MASTER 同步雙寫Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盤方式
#- ASYNC_FLUSH 異步刷盤
#- SYNC_FLUSH 同步刷盤
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-a-s.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公網ip或是負載ip
listenPort=30812
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b.properties
brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=0
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公網ip或是負載ip
listenPort=30813
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
aclEnable=true
[root config]# cat broker-b-s.properties
brokerClusterName = rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=mq-namesrv.romq.svc.cluster.local:20801
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
brokerIP1=公網ip或是負載ip
listenPort=30814
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
storePathRootDir=/data/rocketmq/store
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=SYNC_FLUSH
aclEnable=true
2:創建CM
kubectl create configmap rocketmq-config --from-file=broker-a.properties --from-file=broker-b.properties --from-file=broker-a-s.properties --from-file=broker-b-s.properties -n romq
準備Deploy
1:我的deploy
[root rocketmqDeploy]# ll
total 24
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-a-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-a-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 2908 May 15 16:50 broker-b-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 3041 May 15 16:50 broker-b-s-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1811 May 15 15:50 namesrv-deployment.yaml
-rw-rw-r--. 1 dotnet dotnet 1735 May 15 17:27 rocketmq-externals-deployment.yaml
[root rocketmqDeploy]# cat broker-a-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: broker-a
name: broker-a
spec:
type: NodePort
ports:
- port: 30811
targetPort: 30811
name: broker-port
nodePort: 30811
selector:
app: broker-a
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: broker-a
spec:
serviceName: broker-a
replicas: 1
selector:
matchLabels:
app: broker-a
template:
metadata:
labels:
app: broker-a
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- broker-a
topologyKey: "kubernetes.io/hostname"
containers:
- name: broker-a
image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
imagePullPolicy: Always
command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties"]
volumeMounts:
- mountPath: /root/logs
name: rocketmq-data-cluster
subPath: mq-brokeroptlogs
- mountPath: /data/rocketmq
name: rocketmq-data-cluster
subPath: mq-brokeroptstore
- name: broker-config
mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a.properties
subPath: broker-a.properties
- name: time
mountPath: /etc/localtime
env:
- name: JAVA_OPT_EXT
value: '-Xmx4096m -Xms4096m -Xmn1048m'
resources:
requests:
memory: 2024Mi
cpu: 1024m
limits:
memory: 6024Mi
cpu: 6000m
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 30811
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
volumes:
- name: broker-config
configMap:
name: rocketmq-config
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
volumeClaimTemplates:
- metadata:
name: rocketmq-data-cluster
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
[root rocketmqDeploy]# cat broker-a-s-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: broker-a-s
name: broker-a-s
spec:
type: NodePort
ports:
- port: 30812
targetPort: 30812
name: broker-port
nodePort: 30812
selector:
app: broker-a-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: broker-a-s
spec:
serviceName: broker-a-s
replicas: 1
selector:
matchLabels:
app: broker-a-s
template:
metadata:
labels:
app: broker-a-s
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- broker-a-s
topologyKey: "kubernetes.io/hostname"
containers:
- name: broker-a-s
image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
imagePullPolicy: Always
command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties"]
volumeMounts:
- mountPath: /root/logs
name: rocketmq-data-cluster
subPath: mq-brokeroptlogs
- mountPath: /data/rocketmq
name: rocketmq-data-cluster
subPath: mq-brokeroptstore
- name: broker-config
mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-a-s.properties
subPath: broker-a-s.properties
- name: time
mountPath: /etc/localtime
env:
- name: JAVA_OPT_EXT
value: '-Xmx4096m -Xms4096m -Xmn1048m'
resources:
requests:
memory: 2024Mi
cpu: 1024m
limits:
memory: 6024Mi
cpu: 6000m
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 30812
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
volumes:
- name: broker-config
configMap:
name: rocketmq-config
items:
- key: broker-a-s.properties
path: broker-a-s.properties
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
volumeClaimTemplates:
- metadata:
name: rocketmq-data-cluster
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
[root rocketmqDeploy]# cat broker-b-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: broker-b
name: broker-b
spec:
type: NodePort
ports:
- port: 30813
targetPort: 30813
name: broker-port
nodePort: 30813
selector:
app: broker-b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: broker-b
spec:
serviceName: broker-b
replicas: 1
selector:
matchLabels:
app: broker-b
template:
metadata:
labels:
app: broker-b
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- broker-b
topologyKey: "kubernetes.io/hostname"
containers:
- name: broker-b
image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
imagePullPolicy: Always
command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties"]
volumeMounts:
- mountPath: /root/logs
name: rocketmq-data-cluster
subPath: mq-brokeroptlogs
- mountPath: /data/rocketmq
name: rocketmq-data-cluster
subPath: mq-brokeroptstore
- name: broker-config
mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b.properties
subPath: broker-b.properties
- name: time
mountPath: /etc/localtime
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 30813
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
env:
- name: JAVA_OPT_EXT
value: '-Xmx4096m -Xms4096m -Xmn1048m'
resources:
requests:
memory: 2024Mi
cpu: 1024m
limits:
memory: 6024Mi
cpu: 6000m
volumes:
- name: broker-config
configMap:
name: rocketmq-config
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
volumeClaimTemplates:
- metadata:
name: rocketmq-data-cluster
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
[root rocketmqDeploy]# cat broker-b-s-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: broker-b-s
name: broker-b-s
spec:
type: NodePort
ports:
- port: 30814
targetPort: 30814
name: broker-port
nodePort: 30814
selector:
app: broker-b-s
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: broker-b-s
spec:
serviceName: broker-b-s
replicas: 1
selector:
matchLabels:
app: broker-b-s
template:
metadata:
labels:
app: broker-b-s
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- broker-b-s
topologyKey: "kubernetes.io/hostname"
containers:
- name: broker-b-s
image: 127.0.0.1/rocketmq/rocketmq-4.9.3:1.0
imagePullPolicy: Always
command: ["sh","-c","/usr/local/rocketmq-all-4.9.4-bin-release/bin/mqbroker -c /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties"]
volumeMounts:
- mountPath: /root/logs
name: rocketmq-data-cluster
subPath: mq-brokeroptlogs
- mountPath: /data/rocketmq
name: rocketmq-data-cluster
subPath: mq-brokeroptstore
- name: broker-config
mountPath: /usr/local/rocketmq-all-4.9.4-bin-release/conf/broker-b-s.properties
subPath: broker-b-s.properties
- name: time
mountPath: /etc/localtime
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 30814
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
env:
- name: JAVA_OPT_EXT
value: '-Xmx4096m -Xms4096m -Xmn1048m'
resources:
requests:
memory: 2024Mi
cpu: 1024m
limits:
memory: 6024Mi
cpu: 6000m
volumes:
- name: broker-config
configMap:
name: rocketmq-config
items:
- key: broker-b-s.properties
path: broker-b-s.properties
- name: time
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
volumeClaimTemplates:
- metadata:
name: rocketmq-data-cluster
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
[root rocketmqDeploy]# cat namesrv-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: mq-namesrv
name: mq-namesrv
spec:
type: NodePort
ports:
- port: 20801
targetPort: 20801
name: namesrv-port
nodePort: 30815
selector:
app: mq-namesrv
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mq-namesrv
spec:
serviceName: mq-namesrv
replicas: 1
selector:
matchLabels:
app: mq-namesrv
template:
metadata:
labels:
app: mq-namesrv
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- mq-namesrv
topologyKey: "kubernetes.io/hostname"
containers:
- name: mq-namesrv
image: 127.0.0.1/rocketmq/rocketmq_namesrv:4.9.3.1
imagePullPolicy: Always
env:
- name: JAVA_OPT_EXT
value: '-Xmx2048m -Xms2048m -Xmn512m'
resources:
requests:
memory: 2024Mi
cpu: 1024m
limits:
memory: 4096Mi
cpu: 3000m
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 20801
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
[root rocketmqDeploy]# cat rocketmq-externals-deployment.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: mq-externals
name: mq-externals
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
name: console-port
nodePort: 30816
selector:
app: mq-externals
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mq-externals
spec:
replicas: 1
selector:
matchLabels:
app: mq-externals
template:
metadata:
labels:
app: mq-externals
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- mq-externals
topologyKey: "kubernetes.io/hostname"
containers:
- name: mq-externals
image: 127.0.0.1/rocketmq/rocketmq-dashboard:v4.9.3.1
imagePullPolicy: Always
lifecycle:
postStart:
exec:
command: ["/bin/sh","-c","touch /tmp/health"]
livenessProbe:
exec:
command: ["test","-e","/tmp/health"]
initialDelaySeconds: 5
timeoutSeconds: 5
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
env:
- name: JAVA_OPT_EXT
value: '-Xmx1024m -Xms1024m -Xmn512m'
resources:
requests:
memory: 1024Mi
cpu: 1024m
limits:
memory: 4096Mi
cpu: 3000m
2: 部署deploy
kubectl apply -f ./ -n romq
[root rocketmqDeploy]# kubectl get po -n romq
NAME READY STATUS RESTARTS AGE
broker-a-0 1/1 Running 0 65m
broker-a-s-0 1/1 Running 0 65m
broker-b-0 1/1 Running 0 65m
broker-b-s-0 1/1 Running 0 65m
mq-externals-6cfc5d9bc-w4cmp 1/1 Running 0 45s
mq-namesrv-0 1/1 Running 0 65m
[root rocketmqDeploy]# kubectl get svc -n romq
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
broker-a NodePort 10.99.180.11 <none> 30811:30811/TCP 67m
broker-a-s NodePort 10.105.248.30 <none> 30812:30812/TCP 66m
broker-b NodePort 10.102.87.207 <none> 30813:30813/TCP 66m
broker-b-s NodePort 10.103.106.247 <none> 30814:30814/TCP 66m
mq-externals NodePort 10.96.128.101 <none> 8080:30816/TCP 66m
mq-namesrv NodePort 10.105.103.115 <none> 20801:30815/TCP 66m
3:訪問dashboard: http://$NODE_IP:30816/
版權 本文為云錄原創文章,轉載無需和我聯系,但請注明來自云錄 https://www.yunzhuan.site
總結
以上是生活随笔為你收集整理的【云原生 | Kubernetes 系列】—K8S部署RocketMQ集群(双主双从+同步模式)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2023年终总结:为何我们总想把时间填满
- 下一篇: Go 语言为什么很少使用数组?