在K8s平台内部署 canal-server 与 直接使用 Docker 方式部署 canal-server 有所不同;
编写 K8s 服务部署脚本
在服务器根目录下,创建 canal-server-single.yaml
文件,文件内容为:
---
kind: ConfigMap
apiVersion: v1
metadata:
name: canal-server-single-cm
annotations:
kubesphere.io/alias-name: Canal Server 单机配置
kubesphere.io/creator: admin
kubesphere.io/description: Canal Server 单机配置
data:
canal.destinations: 'test'
canal.user: 'canal'
canal.passwd: 'E3619321C1A937C46A0D8BD1DAC39F93B27D4458'
canal.instance.master.address: '127.0.0.1:3306'
canal.instance.master.journal.name: 'mysql-bin.00001'
canal.instance.master.position: '612712523'
canal.instance.dbUsername: 'canal'
canal.instance.dbPassword: 'canal'
canal.instance.connectionCharset: 'UTF-8'
canal.instance.gtidon: 'false'
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'
canal.server.mode: 'tcp'
canal.instance.filter.druid.ddl: 'false'
canal.instance.filter.query.dcl: 'false'
canal.instance.filter.query.dml: 'false'
canal.instance.filter.query.ddl: 'false'
canal.instance.filter.table.error: 'false'
canal.instance.filter.rows: 'false'
canal.instance.filter.transaction.entry: 'false'
canal.instance.filter.dml.insert: 'false'
canal.instance.filter.dml.update: 'false'
canal.instance.filter.dml.delete: 'false'
canal.instance.filter.regex: ''
canal.instance.filter.black.regex: 'mysql\\.slave_.*'
---
apiVersion: v1
kind: Service
metadata:
name: canal-server-single-svc
labels:
app: canal-server-single
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-single
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: canal-server-single-deploy
annotations:
kubesphere.io/alias-name: Canal Server - MySQL 数据数据订阅服务
kubesphere.io/description: Canal Server - MySQL 数据数据订阅服务
labels:
app: canal-server-single
spec:
replicas: 1
selector:
matchLabels:
app: canal-server-single
template:
metadata:
labels:
app: canal-server-single
spec:
containers:
- name: canal-server-single
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.destinations
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.destinations
- name: canal.user
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.user
- name: canal.passwd
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.passwd
- name: canal.register.ip
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: canal.instance.master.address
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.master.address
- name: canal.instance.master.journal.name
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.master.journal.name
- name: canal.instance.master.position
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.master.position
- name: canal.instance.dbUsername
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.dbUsername
- name: canal.instance.dbPassword
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.dbPassword
- name: canal.instance.connectionCharset
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.connectionCharset
- name: canal.instance.gtidon
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.gtidon
- name: canal.instance.tsdb.enable
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.tsdb.enable
- name: canal.instance.tsdb.spring.xml
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.tsdb.spring.xml
- name: canal.instance.tsdb.url
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.tsdb.url
- name: canal.instance.tsdb.dbUsername
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.tsdb.dbUsername
- name: canal.instance.tsdb.dbPassword
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.tsdb.dbPassword
- name: canal.serverMode
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.server.mode
- name: canal.instance.filter.druid.ddl
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.druid.ddl
- name: canal.instance.filter.query.dcl
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.query.dcl
- name: canal.instance.filter.query.dml
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.query.dml
- name: canal.instance.filter.query.ddl
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.query.ddl
- name: canal.instance.filter.table.error
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.table.error
- name: canal.instance.filter.rows
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.rows
- name: canal.instance.filter.transaction.entry
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.transaction.entry
- name: canal.instance.filter.dml.insert
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.dml.insert
- name: canal.instance.filter.dml.update
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.dml.update
- name: canal.instance.filter.dml.delete
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.dml.delete
- name: canal.instance.filter.regex
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.regex
- name: canal.instance.filter.black.regex
valueFrom:
configMapKeyRef:
name: canal-server-single-cm
key: canal.instance.filter.black.regex
- 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-single
topologyKey: kubernetes.io/hostname
使用 kubectl 执行如下命令部署 canal-server 服务 :
# 示例
# kubectl apply -f canal-server.yaml --namespace=你的命名空间
# 将 canal-server 部署到 k8s-ops-prod 空间下
kubectl apply -f canal-server-single.yaml --namespace=ops-prod
作者:Jeebiz 创建时间:2023-05-29 09:52
最后编辑:Jeebiz 更新时间:2024-07-10 22:56
最后编辑:Jeebiz 更新时间:2024-07-10 22:56