官方文档:通用 Kubernetes 安装 - Percona Operator for MySQL — Generic Kubernetes installation - Percona Operator for MySQL

安装Operator

1
2
git clone -b v1.14.0 https://github.com/percona/percona-xtradb-cluster-operator
cd percona-xtradb-cluster-operator

方式一:分步安装

1
kubectl apply -f deploy/crd.yaml
1
kubectl apply -f deploy/cw-operator.yaml -n kube-system
1
2
sed -i "s/pxc-operator/kube-system/g" deploy/cw-rbac.yaml
sed -i "s/imagePullPolicy: Always/imagePullPolicy: IfNotPresent/g" deploy/cw-operator.yaml
1
kubectl apply -f deploy/cw-rbac.yaml -n kube-system
1
kubectl apply -f deploy/secrets.yaml -n kube-system

方式二:简易安装

1
2
sed -i "s/pxc-operator/kube-system/g" deploy/cw-bundle.yaml
sed -i "s/imagePullPolicy: Always/imagePullPolicy: IfNotPresent/g" deploy/cw-bundle.yaml
1
2
kubectl apply -f deploy/crd.yaml
kubectl apply -f deploy/cw-bundle.yaml -n kube-system

安装pxc集群

1
vim deploy/cr.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBCluster
metadata:
name: cluster1
finalizers:
  - delete-pxc-pods-in-order
spec:
crVersion: 1.14.0
allowUnsafeConfigurations: false
updateStrategy: SmartUpdate
upgradeOptions:
  versionServiceEndpoint: https://check.percona.com
  apply: disabled
  schedule: "0 4 * * *"
pxc:
  size: 3
  image: percona/percona-xtradb-cluster:8.0.35-27.1
imagePullPolicy: IfNotPresent
  autoRecovery: true
  resources:
    requests:
      memory: 1G
      cpu: 600m
  affinity:
    antiAffinityTopologyKey: "kubernetes.io/hostname"
  podDisruptionBudget:
    maxUnavailable: 1
  volumeSpec:
    persistentVolumeClaim:
      storageClassName: nfs-storage # 改为实际storageclass
      resources:
        requests:
          storage: 6G
  gracePeriod: 600
haproxy:
  enabled: true
  size: 3
  image: percona/percona-xtradb-cluster-operator:1.14.0-haproxy
imagePullPolicy: IfNotPresent
  resources:
    requests:
      memory: 1G
      cpu: 600m
  affinity:
    antiAffinityTopologyKey: "kubernetes.io/hostname"
  podDisruptionBudget:
    maxUnavailable: 1
  gracePeriod: 30
proxysql:
  enabled: false
  size: 3
  image: percona/percona-xtradb-cluster-operator:1.14.0-proxysql
imagePullPolicy: IfNotPresent
  resources:
    requests:
      memory: 1G
      cpu: 600m
  affinity:
    antiAffinityTopologyKey: "kubernetes.io/hostname"
  volumeSpec:
    persistentVolumeClaim:
      resources:
        requests:
          storage: 2G
  podDisruptionBudget:
    maxUnavailable: 1
  gracePeriod: 30
logcollector:
  enabled: true
  image: percona/percona-xtradb-cluster-operator:1.14.0-logcollector
imagePullPolicy: IfNotPresent
  resources:
    requests:
      memory: 100M
      cpu: 200m
pmm:
  enabled: false
  image: percona/pmm-client:2.41.1
  serverHost: monitoring-service
  resources:
    requests:
      memory: 150M
      cpu: 300m
backup:
  image: percona/percona-xtradb-cluster-operator:1.14.0-pxc8.0-backup-pxb8.0.35
  pitr:
    enabled: false
    storageName: STORAGE-NAME-HERE
    timeBetweenUploads: 60
    timeoutSeconds: 60
  storages:
    s3-us-west:
      type: s3
      verifyTLS: true
      s3:
        bucket: S3-BACKUP-BUCKET-NAME-HERE
        credentialsSecret: my-cluster-name-backup-s3
        region: us-west-2
    azure-blob:
      type: azure
      azure:
        credentialsSecret: azure-secret
        container: test
    fs-pvc:
      type: filesystem
      volume:
        persistentVolumeClaim:
          storageClassName: nfs-storage # 改为实际storageclass
          accessModes: [ "ReadWriteOnce" ]
          resources:
            requests:
              storage: 6G
  schedule:
    - name: "daily-backup"
      schedule: "0 0 * * *"
      keep: 5
      storageName: fs-pvc
1
2
kubectl create ns pxc
kubectl apply -f cr.yaml -n pxc

最小化pxc集群

1
vim cr-minimal.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBCluster
metadata:
name: minimal-cluster
spec:
crVersion: 1.14.0
secretsName: minimal-cluster-secrets
allowUnsafeConfigurations: true
upgradeOptions:
apply: disabled
schedule: "0 4 * * *"
pxc:
size: 1
image: percona/percona-xtradb-cluster:8.0.35-27.1
imagePullPolicy: IfNotPresent
volumeSpec:
persistentVolumeClaim:
storageClassName: nfs-storage
resources:
requests:
storage: 6G
haproxy:
enabled: true
size: 1
image: percona/percona-xtradb-cluster-operator:1.14.0-haproxy
imagePullPolicy: IfNotPresent
logcollector:
enabled: true
image: percona/percona-xtradb-cluster-operator:1.14.0-logcollector
imagePullPolicy: IfNotPresent
1
kubectl apply -f cr-minimal.yaml

卸载

1
kubectl delete pxc <pxc集群名称>
1
2
3
kubectl delete -f deploy/cw-bundle.yaml
kubectl delete -f deploy/crd.yaml
kubectl delete validatingwebhookconfigurations percona-xtradbcluster-webhook