kubesphere 安装mysql

4 篇文章 0 订阅
2 篇文章 0 订阅

1.首先建立密码的秘钥

在配置中心建立秘钥:mysql-secret

key为:MYSQL_ROOT_PASSWORD,值数据库密码

2.建立mysql的配置文件

在配置中心的配置

新建配置:mysqld

key为:mysqld.cnf

值如下:

[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
lower_case_table_names =1
max_connections=2000
max_allowed_packet=40M
log_timestamps = SYSTEM
symbolic-links=0

3.建立mysql挂载data挂载目录

在存储卷建立mysql挂载目录,存放data数据

4.在工作负载进行部署mysql5.7

 

下一步

挂载data目录

选择添加已有存储卷,挂载路径为:/var/lib/mysql

挂载配置文件

选择引用配置中心

其对应的yaml如下:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: mysql
  namespace: base-config
  resourceVersion: '601345'
  labels:
    app: mysql
  annotations:
    deployment.kubernetes.io/revision: '16'
    kubesphere.io/isElasticReplicas: 'false'
    maxSurgePod: '2'
    minAvailablePod: '1'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mysql
    spec:
      volumes:
        - name: volume-daisqd
          persistentVolumeClaim:
            claimName: mysql
        - name: volume-tdb72k
          configMap:
            name: mysqld
            items:
              - key: mysqld.cnf
                path: mysqld.cnf
            defaultMode: 420
      containers:
        - name: container-e8ak1r
          image: 'mysql:5.7'
          ports:
            - name: port
              containerPort: 3306
              protocol: TCP
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: MYSQL_ROOT_PASSWORD
          resources:
            limits:
              cpu: '8'
              memory: 16Gi
            requests:
              cpu: '4'
              memory: 8Gi
          volumeMounts:
            - name: volume-daisqd
              mountPath: /var/lib/mysql
            - name: volume-tdb72k
              mountPath: /etc/mysql/mysql.conf.d
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      serviceAccountName: default
      serviceAccount: default
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0%
      maxSurge: 100%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600

保存后更新后就要配置服务,就是对外围暴露端口

建立服务mysql-service

然后点击保存,点击编辑外网访问,就会生出对外网访问的端口

KubeSphere是一个开源的容器化平台,它提供了一套完整的容器管理解决方案。要在KubeSphere上安装MySQL主从复制,可以按照以下步骤进行操作: 1. 创建MySQL主从复制的配置文件:创建一个名为mysql-replication.yaml的文件,并将以下内容复制到文件中: ```yaml apiVersion: v1 kind: Service metadata: name: mysql-master labels: app: mysql spec: ports: - port: 3306 selector: app: mysql tier: master clusterIP: None --- apiVersion: v1 kind: Service metadata: name: mysql-slave labels: app: mysql spec: ports: - port: 3306 selector: app: mysql tier: slave clusterIP: None --- apiVersion: apps/v1 kind: StatefulSet metadata: name: mysql spec: serviceName: mysql-master replicas: 2 selector: matchLabels: app: mysql tier: master template: metadata: labels: app: mysql tier: master spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "password" ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumeClaimTemplates: - metadata: name: mysql-persistent-storage spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi --- apiVersion: apps/v1 kind: StatefulSet metadata: name: mysql-slave spec: serviceName: mysql-slave replicas: 2 selector: matchLabels: app: mysql tier: slave template: metadata: labels: app: mysql tier: slave spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "password" ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumeClaimTemplates: - metadata: name: mysql-persistent-storage spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 1Gi ``` 2. 使用kubectl命令进行部署:在终端中执行以下命令,将配置文件部署到KubeSphere集群中。 ```shell kubectl apply -f mysql-replication.yaml ``` 3. 验证MySQL主从复制是否成功:可以使用以下命令验证MySQL主从复制是否正常工作。 ```shell kubectl exec -it mysql-0 -- mysql -uroot -ppassword -e "SHOW MASTER STATUS;" kubectl exec -it mysql-2 -- mysql -uroot -ppassword -e "SHOW SLAVE STATUS\G" ``` 以上是在KubeSphere上安装MySQL主从复制的步骤。如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值