k8s上安装Presslabs MySQL Operator

Operator-mysql安装

1、helm添加库

helm安装不做说明

helm repo add presslabs https://presslabs.github.io/charts
helm repo update
helm pull presslabs/mysql-operator

创建rabc.yaml

# 唯一需要修改的地方只有namespace,根据实际情况定义
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: zhanghsn        #根据实际环境设定namespace,下面类同
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
  namespace: zhanghsn
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: zhanghsn
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
    # replace with namespace where provisioner is deployed
  namespace: zhanghsn
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    # replace with namespace where provisioner is deployed
    namespace: zhanghsn
roleRef:
  kind: Role
  name: leader-locking-nfs-client-provisioner
  apiGroup: rbac.authorization.k8s.io

2、创建StorageClass

说明:我这里使用的是CCE,插件装好nfs,这里不需要操作

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: presslabs-managed-nfs-storage
  namespace: operator
provisioner: presslabs-mysql-nfs-storage #这里的名称要和provisioner配置文件中的环境变量PROVISIONER_NAME保持一致parameters:  archiveOnDelete: "false"

3、安装operator

[root@cce-master1 mysql-rabc]# kubectl apply -f ./rabc.yaml

helm install presslabs-mysql-operator -name mysql-operator  -f mysql-operator/values.yaml --namespace zhanghsn --set rbac.enabled=true
[root@cce-master1 mysql-rabc]# kubectl get ServiceAccount,ClusterRole,ClusterRoleBinding,Role,RoleBinding -n zhanghsn
[root@cce-master1 soft]# kubectl get pod,svc,ing,cm -n zhanghsn
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
NAME                             READY   STATUS    RESTARTS   AGE
pod/presslabs-mysql-operator-0   2/2     Running   0          4m23s

NAME                                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)            AGE
service/presslabs-mysql-operator         ClusterIP   10.247.178.253   <none>        80/TCP             4m23s
service/presslabs-mysql-operator-0-svc   ClusterIP   10.247.3.195     <none>        80/TCP,10008/TCP   4m23s

NAME                                       DATA   AGE
configmap/mysql-operator-leader-election   0      4m3s
configmap/presslabs-mysql-operator-orc     2      4m23s

#更新values.yaml,可以将副本修改
[root@cce-master1 soft]# helm upgrade presslabs-mysql-operator --values mysql-operator/values.yaml mysql-operator --namespace zhanghsn --set rbac.enabled=true
[root@cce-master1 mysql-rabc]# kubectl get pod -n zhanghsn -o wide|grep operator
presslabs-mysql-operator-0           2/2     Running    0          7m      172.16.169.72    10.11.95.235   <none>           <none>
presslabs-mysql-operator-1           2/2     Running    0          7m5s    172.16.169.109   10.11.95.235   <none>           <none>
presslabs-mysql-operator-2           2/2     Running    0          7m20s   172.16.169.86    10.11.95.235   <none>           <none>
[root@cce-master1 mysql-rabc]#

4版本镜像起不来,换位3版本镜像
里面的operator容器和orchestrator容器都会有选主的过程,这里对应的应该是presslabs-mysql-operator-2, Operator POD在起来之后,其中给一个会成为leader leader的ip是svc的ip 会出现如下字样

2020/09/30 01:37:59 [INFO] raft: Election won. Tally: 2
2020/09/30 01:37:59 [INFO] raft: Node at 10.109.138.165:10008 [Leader] entering Leader state

4、查看

kubectl log -f presslabs-mysql-operator-2 -c orchestrator -n operator

#骚操作,如果pod起不来,可以先把健康检查关闭mysql-cluster是依赖他

4、安装mysql集群

[root@cce-master1 soft]# helm pull presslabs/mysql-cluster

vim values.yaml  #修改副本数和mysql的用户密码
replicas: 3

helm install presslabs-mysql-cluster --name mysql-cluster  -f values.yaml --namespace zhanghsn --set rbac.enabled=true
helm delete my-cluster  --purge
helm uninstall my-cluster

[root@cce-master1 mysql-rabc]# kubectl get pod -n zhanghsn -o wide
NAME                                 READY   STATUS    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
presslabs-mysql-cluster-db-mysql-0   4/4     Running   0          53s     172.16.76.138    10.11.95.236   <none>           <none>
presslabs-mysql-cluster-db-mysql-1   4/4     Running   0          2m42s   172.16.169.89    10.11.95.235   <none>           <none>
presslabs-mysql-cluster-db-mysql-2   4/4     Running   0          12m     172.16.75.232    10.11.95.237   <none>           <none>
presslabs-mysql-operator-0           2/2     Running   0          14m     172.16.169.72    10.11.95.235   <none>           <none>
presslabs-mysql-operator-1           2/2     Running   0          14m     172.16.169.109   10.11.95.235   <none>           <none>
presslabs-mysql-operator-2           2/2     Running   0          15m     172.16.169.86    10.11.95.235   <none>           <none>
[root@cce-master1 mysql-rabc]#

k8s上安装Presslabs MySQL Operator

上一篇:【Python爬虫】糗事百科数据段子采集


下一篇:爬虫初步探索