在K8s平台内部署 canal-admin 与 直接使用 Docker 方式部署 canal-admin 有所不同;
- 2、
- 3、
编写 K8s 服务部署脚本
在服务器根目录下,创建 canal-admin.yaml
文件,文件内容为:
---
kind: ConfigMap
apiVersion: v1
metadata:
name: canal-admin-cm
annotations:
kubesphere.io/alias-name: Canal 配置
kubesphere.io/creator: admin
kubesphere.io/description: Canal 配置
data:
canal.admin.username: admin
canal.admin.password: 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9
canal.db.address: '192.168.3.81:13306'
canal.db.database: canal_manager
canal.db.username: canal_manager
canal.db.password: Nyy6T76tTm7pAAy3
---
apiVersion: v1
kind: Service
metadata:
name: canal-admin-svc
labels:
app: canal-admin
annotations:
kubesphere.io/alias-name: Canal - 管理服务
kubesphere.io/description: Canal - 管理服务
spec:
ports:
- name: tcp-8089
port: 8089
protocol: TCP
targetPort: 8089
selector:
app: canal-admin
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: canal-admin-deploy
annotations:
kubesphere.io/alias-name: Canal - 管理服务
kubesphere.io/description: Canal - 管理服务
labels:
app: canal-admin
spec:
replicas: 1
selector:
matchLabels:
app: canal-admin
template:
metadata:
labels:
app: canal-admin
spec:
containers:
- name: canal-admin
image: canal/canal-admin:latest
ports:
- name: http-8089
containerPort: 8089
protocol: TCP
env:
- name: SPRING_DATASOURCE_ADDRESS
valueFrom:
configMapKeyRef:
key: canal.db.address
name: canal-admin-cm
- name: SPRING_DATASOURCE_DATABASE
valueFrom:
configMapKeyRef:
key: canal.db.database
name: canal-admin-cm
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
configMapKeyRef:
key: canal.db.username
name: canal-admin-cm
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
configMapKeyRef:
key: canal.db.password
name: canal-admin-cm
- name: CANAL_ADMIN-USER
valueFrom:
configMapKeyRef:
key: canal.admin.username
name: canal-admin-cm
- name: CANAL_ADMIN-PASSWD
valueFrom:
configMapKeyRef:
key: canal.admin.password
name: canal-admin-cm
- name: JAVA_TOOL_OPTIONS
value: >-
-Xms1344M -Xmx1344M -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
-XX:MetaspaceSize=200M -XX:MaxMetaspaceSize=200M
-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:NewRatio=1
-XX:SurvivorRatio=4 -XX:GCLogFileSize=20m
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/logs/heaperror.log
-Xloggc:/logs/gcerror.log
resources: {}
imagePullPolicy: Always
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: canal-admin
topologyKey: kubernetes.io/hostname
使用 kubectl 执行如下命令部署 canal-admin 服务 :
# 示例
# kubectl apply -f canal-admin.yaml --namespace=你的命名空间
# 将 canal-admin 部署到 k8s-ops-prod 空间下
kubectl apply -f canal-admin.yaml --namespace=k8s-ops-prod
canal-server-cluster.yaml
---
kind: ConfigMap
apiVersion: v1
metadata:
name: canal-server-cluster-cm
annotations:
kubesphere.io/alias-name: Canal Server 集群配置
kubesphere.io/creator: admin
kubesphere.io/description: Canal Server 集群配置
data:
canal.admin.manager: '192.168.3.164:30911'
canal.admin.port: '11110'
canal.admin.username: admin
canal.admin.password: 4ACFE3202A5FF5CF467898FC58AAB1D615029441
canal.admin.register.auto: 'true'
canal.admin.register.cluster: canal-cluster
canal.zookeeper.servers: '192.168.3.73:2181,192.168.3.74:2181,192.168.3.75:2181'
canal.zookeeper.flush.period: '1000'
canal.user: 'canal'
canal.passwd: 'E3619321C1A937C46A0D8BD1DAC39F93B27D4458'
canal.instance.global.spring.xml: 'classpath:spring/default-instance.xml'
canal.instance.tsdb.enable: 'true'
canal.instance.tsdb.spring.xml: 'classpath:spring/tsdb/mysql-tsdb.xml'
canal.instance.tsdb.url: 'jdbc:mysql://127.0.0.1:3306/canal_tsdb'
canal.instance.tsdb.dbUsername: 'canal'
canal.instance.tsdb.dbPassword: 'canal'
---
apiVersion: v1
kind: Service
metadata:
name: canal-server-cluster-svc
labels:
app: canal-server-cluster
micrometer-prometheus-discovery: 'true'
annotations:
kubesphere.io/alias-name: Canal Server - MySQL 数据数据订阅服务
kubesphere.io/description: Canal Server - MySQL 数据数据订阅服务
prometheus.io/path: /metrics
prometheus.io/port: '11112'
prometheus.io/scrape: 'true'
spec:
ports:
- name: tcp-11110
port: 11110
protocol: TCP
targetPort: 11110
- name: tcp-11111
port: 11111
protocol: TCP
targetPort: 11111
- name: tcp-11112
port: 11112
protocol: TCP
targetPort: 11112
- name: tcp-9100
port: 9100
protocol: TCP
targetPort: 9100
selector:
app: canal-server-cluster
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: canal-server-cluster-deploy
annotations:
kubesphere.io/alias-name: Canal Server - MySQL 数据数据订阅服务
kubesphere.io/description: Canal Server - MySQL 数据数据订阅服务
labels:
app: canal-server-cluster
spec:
replicas: 1
selector:
matchLabels:
app: canal-server-cluster
template:
metadata:
labels:
app: canal-server-cluster
spec:
containers:
- name: canal-server-cluster
image: canal/canal-server:latest
ports:
- name: tcp-11110
containerPort: 11110
protocol: TCP
- name: tcp-11111
containerPort: 11111
protocol: TCP
- name: tcp-11112
containerPort: 11112
protocol: TCP
- name: tcp-9100
containerPort: 9100
protocol: TCP
env:
- name: canal.admin.manager
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.manager
- name: canal.admin.port
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.port
- name: canal.admin.user
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.username
- name: canal.admin.passwd
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.password
- name: canal.admin.register.auto
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.register.auto
- name: canal.admin.register.cluster
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.admin.register.cluster
- name: canal.admin.register.name
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: canal.zkServers
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.zookeeper.servers
- name: canal.zookeeper.flush.period
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.zookeeper.flush.period
- name: canal.register.ip
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: canal.user
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.user
- name: canal.passwd
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.passwd
- name: canal.instance.global.spring.xml
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.global.spring.xml
- name: canal.instance.tsdb.enable
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.tsdb.enable
- name: canal.instance.tsdb.spring.xml
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.tsdb.spring.xml
- name: canal.instance.tsdb.url
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.tsdb.url
- name: canal.instance.tsdb.dbUsername
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.tsdb.dbUsername
- name: canal.instance.tsdb.dbPassword
valueFrom:
configMapKeyRef:
name: canal-server-cluster-cm
key: canal.instance.tsdb.dbPassword
- name: JAVA_TOOL_OPTIONS
value: >-
-Xms1344M -Xmx1344M -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
-XX:MetaspaceSize=200M -XX:MaxMetaspaceSize=200M
-XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:NewRatio=1
-XX:SurvivorRatio=4 -XX:GCLogFileSize=20m
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/logs/heaperror.log
-Xloggc:/logs/gcerror.log
resources: {}
imagePullPolicy: Always
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: canal-server-cluster
topologyKey: kubernetes.io/hostname
作者:Jeebiz 创建时间:2023-05-29 09:58
最后编辑:Jeebiz 更新时间:2024-07-10 22:56
最后编辑:Jeebiz 更新时间:2024-07-10 22:56