麻豆成人91精品二区三区,国产91在线播放,加勒比无码专区中文字幕,欧美黑人XXXX高潮猛交

×

Kubernetes 使用StatefulSet部署MySQL高可用集群

分類:互聯(lián)網(wǎng)熱點(diǎn) 編輯:聊聊云計(jì)算 瀏覽量:76
2020-07-13 16:55:23

MySQL簡(jiǎn)介

MySQL是一個(gè)關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),由瑞典MySQL AB公司開發(fā),屬于 Oracle 旗下產(chǎn)品。MySQL 是最流行的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng)之一,在 WEB 應(yīng)用方面,MySQL是最好的 RDBMS (Relational Database Management System,關(guān)系數(shù)據(jù)庫(kù)管理系統(tǒng)) 應(yīng)用軟件之一。MySQL是一種關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),關(guān)系數(shù)據(jù)庫(kù)將數(shù)據(jù)保存在不同的表中,而不是將所有數(shù)據(jù)放在一個(gè)大倉(cāng)庫(kù)內(nèi),這樣就增加了速度并提高了靈活性。MySQL所使用的 SQL 語(yǔ)言是用于訪問(wèn)數(shù)據(jù)庫(kù)的最常用標(biāo)準(zhǔn)化語(yǔ)言。MySQL 軟件采用了雙授權(quán)政策,分為社區(qū)版和商業(yè)版,由于其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點(diǎn),一般中小型網(wǎng)站的開發(fā)都選擇 MySQL 作為網(wǎng)站數(shù)據(jù)庫(kù)。

MySQL高可用方案

下文介紹的MySQL高可用方案采用“主從復(fù)制+讀寫分離”,即由單一的master和多個(gè)slave所構(gòu)成。其中,客戶端通過(guò)master對(duì)數(shù)據(jù)庫(kù)進(jìn)行寫操作,通過(guò)slave端進(jìn)行讀操作。master出現(xiàn)問(wèn)題后,可以將應(yīng)用切換到slave端。 此方案是MySQL官方提供的一種高可用解決方案,節(jié)點(diǎn)間的數(shù)據(jù)同步采用MySQL Replication技術(shù)。MySQL Replication從一個(gè)MySQL數(shù)據(jù)庫(kù)服務(wù)器(master)的數(shù)據(jù)復(fù)制到一個(gè)或多個(gè)MySQL數(shù)據(jù)庫(kù)服務(wù)器(slave)。在默認(rèn)情況下,復(fù)制是異步的;slave不需要一直接收來(lái)自主機(jī)的更新。根據(jù)配置,可以復(fù)制數(shù)據(jù)庫(kù)中的所有數(shù)據(jù)庫(kù)、選定的數(shù)據(jù)庫(kù),或者特定的表。

預(yù)配置storageclass,實(shí)現(xiàn)nfs做存儲(chǔ)類的動(dòng)態(tài)供給pv

1、安裝NFS服務(wù)器

#安裝NFS服務(wù)端,選擇k8s集群的master1節(jié)點(diǎn)(192.168.56.10)[root@k8s-master01 ~]# yum install nfs-utils -y (在所有節(jié)點(diǎn)安裝nfs-utils,并在node節(jié)點(diǎn)測(cè)試掛載)[root@k8s-master01 ~]# systemctl start nfs[root@k8s-master01 ~]# systemctl enable nfs#在master1上創(chuàng)建nfs共享目錄[root@k8s-master01 ~]# mkdir -p /data/v1[root@k8s-master01 ~]# chown -R 1000:1000 /data/v1[root@k8s-master01 ~]# vim /etc/exports/data/v1 192.168.56.0/24(rw,no_root_squash)[root@k8s-master01 ~]# exportfs -arv 使配置文件生效[root@k8s-master01 ~]# systemctl restart nfs[root@k8s-master01 data]# showmount -eExport list for k8s-master01:/data/v1 192.168.56.0/24#在node01和node02節(jié)點(diǎn)上安裝nfs-utils,并測(cè)試掛載[root@k8s-node01 ~]# yum install -y nfs-utils[root@k8s-node02 ~]# yum install -y nfs-utils[root@k8s-node01 ~]# mount -t nfs 192.168.56.10:/data/v1 /mnt[root@k8s-node01 ~]# mount......192.168.56.10:/data/v1 on /mnt type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.56.11,local_lock=none,addr=192.168.56.10)[root@k8s-node01 ~]# umount /mnt/

2、實(shí)現(xiàn)nfs做storageclass存儲(chǔ)類的動(dòng)態(tài)供給pv

創(chuàng)建運(yùn)行nfs-provisioner的sa賬號(hào)

[root@k8s-master01 ~]# mkdir mysql && cd mysql/[root@k8s-master01 mysql]# vim serviceaccount.yamlapiVersion: v1kind: ServiceAccountmetadata: name: nfs-provisioner通過(guò)kubectl更新yaml文件 [root@k8s-master01 mysql]# kubectl apply -f serviceaccount.yamlserviceaccount/nfs-provisioner created[root@k8s-master01 mysql]# kubectl get saNAME SECRETS AGEdefault 1 4d18hnfs-provisioner 1 33s

對(duì)nfs-provisioner這個(gè)sa賬號(hào)做rbac授權(quán)

[root@k8s-master01 mysql]# vim rbac.yamlkind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: nfs-provisioner-runnerrules: - 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"] - apiGroups: [""] resources: ["services", "endpoints"] verbs: ["get"] - apiGroups: ["extensions"] resources: ["podsecuritypolicies"] resourceNames: ["nfs-provisioner"] verbs: ["use"]---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: run-nfs-provisionersubjects: - kind: ServiceAccount name: nfs-provisioner namespace: defaultroleRef: kind: ClusterRole name: nfs-provisioner-runner apiGroup: rbac.authorization.k8s.io---kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: leader-locking-nfs-provisionerrules: - apiGroups: [""] resources: ["endpoints"] verbs: ["get", "list", "watch", "create", "update", "patch"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: leader-locking-nfs-provisionersubjects: - kind: ServiceAccount name: nfs-provisioner namespace: defaultroleRef: kind: Role name: leader-locking-nfs-provisioner apiGroup: rbac.authorization.k8s.io通過(guò)kubectl更新yaml文件 [root@k8s-master01 mysql]# kubectl apply -f rbac.yamlclusterrole.rbac.authorization.k8s.io/nfs-provisioner-runner createdclusterrolebinding.rbac.authorization.k8s.io/run-nfs-provisioner createdrole.rbac.authorization.k8s.io/leader-locking-nfs-provisioner createdrolebinding.rbac.authorization.k8s.io/leader-locking-nfs-provisioner created[root@k8s-master01 mysql]# kubectl get rolebindingsNAME ROLE AGEleader-locking-nfs-provisioner Role/leader-locking-nfs-provisioner 36s

通過(guò)deployment創(chuàng)建pod用來(lái)運(yùn)行nfs-provisioner

[root@k8s-master01 mysql]# vim deployment.yamlkind: DeploymentapiVersion: apps/v1metadata: name: nfs-provisionerspec: selector: matchLabels: app: nfs-provisioner replicas: 1 strategy: type: Recreate template: metadata: labels: app: nfs-provisioner spec: serviceAccount: nfs-provisioner containers: - name: nfs-provisioner image: registry.cn-hangzhou.aliyuncs.com/open-ali/nfs-client-provisioner:latest imagePullPolicy: IfNotPresent volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: example.com/nfs - name: NFS_SERVER value: 192.168.56.10 - name: NFS_PATH value: /data/v1 volumes: - name: nfs-client-root nfs: server: 192.168.56.10 path: /data/v1通過(guò)kubectl更新yaml文件 [root@k8s-master01 mysql]# kubectl apply -f deployment.yamldeployment.apps/nfs-provisioner created[root@k8s-master01 mysql]# kubectl get podsNAME READY STATUS RESTARTS AGEnfs-provisioner-6dccbfd48f-p4cc4 1/1 Running 0 19s
注:上面yaml文件說(shuō)明: - name: PROVISIONER_NAME value: example.com/nfs#PROVISIONER_NAME是example.com/nfs#example.com/nfs需要跟后面的storageclass的provisinoer保持一致 - name: NFS_SERVER value: 192.168.56.10 #這個(gè)需要寫nfs服務(wù)端所在的ip地址,大家需要寫自己的nfs地址 - name: NFS_PATH value: /data/v1 #這個(gè)是nfs服務(wù)端共享的目錄 volumes: - name: nfs-client-root nfs: server: 192.168.56.10 #nfs服務(wù)端ip path:/data/v1 #nfs服務(wù)端共享目錄
kubectl describe pod nfs-provisioner-6dccbfd48f-p4cc4 查看pod詳情kubectl logs -f nfs-provisioner-6dccbfd48f-p4cc4 查看pod日志、排錯(cuò)

創(chuàng)建storageclass存儲(chǔ)類

[root@k8s-master01 mysql]# vim storageclass.yamlapiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: nfsprovisioner: example.com/nfs注意:provisioner:example.com/nfs #該值需要和provisioner配置的保持一致通過(guò)kubectl更新yaml文件[root@k8s-master01 mysql]# kubectl apply -f storageclass.yaml storageclass.storage.k8s.io/nfs created[root@k8s-master01 mysql]# kubectl get scNAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGEnfs example.com/nfs Delete Immediate false 6s

MySQL高可用集群部署

1、創(chuàng)建ConfigMap

通過(guò)yaml文件創(chuàng)建名為mysql的ConfigMap

[root@k8s-master01 mysql]# vim mysql-configmap.yamlapiVersion: v1kind: ConfigMapmetadata: name: mysql labels: app: mysqldata: master.cnf: | log-bin log_bin_trust_function_creators=1 lower_case_table_names=1 slave.cnf: | super-read-only log_bin_trust_function_creators=1 通過(guò)kubectl更新yaml文件[root@k8s-master01 mysql]# kubectl apply -f mysql-configmap.yaml -n kube-publicconfigmap/mysql created[root@k8s-master01 mysql]# kubectl get configmap -n kube-publicNAME DATA AGEcluster-info 2 4d18hmysql 2 11s

2、創(chuàng)建Services

通過(guò)yaml文件創(chuàng)建兩個(gè)service,分別是 mysql 和 mysql-read

[root@k8s-master01 mysql]# vim mysql-service.yamlapiVersion: v1kind: Servicemetadata: name: mysql labels: app: mysqlspec: ports: - name: mysql port: 3306 clusterIP: None selector: app: mysql---apiVersion: v1kind: Servicemetadata: name: mysql-read labels: app: mysqlspec: ports: - name: mysql port: 3306 selector: app: mysql通過(guò)kubectl更新yaml文件[root@k8s-master01 mysql]# kubectl apply -f mysql-service.yaml -n kube-publicservice/mysql createdservice/mysql-read created[root@k8s-master01 mysql]# kubectl get svc -n kube-publicNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEmysql ClusterIP None 3306/TCP 6smysql-read ClusterIP 10.96.89.246 3306/TCP 6s
master、node節(jié)點(diǎn)下載測(cè)試的image鏡像docker pull registry.cn-hangzhou.aliyuncs.com/yangb/mysql5.7:latestdocker pull registry.cn-hangzhou.aliyuncs.com/test_k8s/xtrabackup:1.0docker tag registry.cn-hangzhou.aliyuncs.com/yangb/mysql5.7:latest mysql:5.7docker tag registry.cn-hangzhou.aliyuncs.com/test_k8s/xtrabackup:1.0 gcr.io/google-samples/xtrabackup:1.0

3、創(chuàng)建StatefulSet

通過(guò)yaml文件創(chuàng)建名為mysql的StatefulSet

[root@k8s-master01 mysql]# vim mysql-statefulset.yamlapiVersion: apps/v1kind: StatefulSetmetadata: name: mysqlspec: selector: matchLabels: app: mysql serviceName: mysql replicas: 3 volumeClaimTemplates: - metadata: name: data annotations: volume.beta.kubernetes.io/storage-class: "nfs" spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 10Gi template: metadata: labels: app: mysql spec: initContainers: - name: init-mysql image: mysql:5.7 command: - bash - "-c" - | set -ex [[ `hostname` =~ -(+)$ ]] || exit 1 ordinal=${BASH_REMATCH} echo > /mnt/conf.d/server-id.cnf echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf if [[ $ordinal -eq 0 ]]; then cp /mnt/config-map/master.cnf /mnt/conf.d/ else cp /mnt/config-map/slave.cnf /mnt/conf.d/ fi volumeMounts: - name: conf mountPath: /mnt/conf.d - name: config-map mountPath: /mnt/config-map - name: clone-mysql image: gcr.io/google-samples/xtrabackup:1.0 command: - bash - "-c" - | set -ex [[ -d /var/lib/mysql/mysql ]] && exit 0 [[ `hostname` =~ -(+)$ ]] || exit 1 ordinal=${BASH_REMATCH} [[ $ordinal -eq 0 ]] && exit 0 ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql xtrabackup --prepare --target-dir=/var/lib/mysql volumeMounts: - name: data mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ALLOW_EMPTY_PASSWORD value: "1" ports: - name: mysql containerPort: 3306 volumeMounts: - name: data mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: requests: cpu: 500m memory: 1Gi livenessProbe: exec: command: ["mysqladmin", "ping"] initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: exec: command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"] initialDelaySeconds: 5 periodSeconds: 2 timeoutSeconds: 1 - name: xtrabackup image: gcr.io/google-samples/xtrabackup:1.0 ports: - name: xtrabackup containerPort: 3307 command: - bash - "-c" - | set -ex cd /var/lib/mysql if [[ -f xtrabackup_slave_info ]]; then mv xtrabackup_slave_info change_master_to.sql.in rm -f xtrabackup_binlog_info elif [[ -f xtrabackup_binlog_info ]]; then [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[ ]]+(.*?)$ ]] || exit 1 rm xtrabackup_binlog_info echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH}',\ MASTER_LOG_POS=${BASH_REMATCH}" > change_master_to.sql.in fi if [[ -f change_master_to.sql.in ]]; then echo "Waiting for mysqld to be ready (accepting connections)" until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done echo "Initializing replication from clone position" mv change_master_to.sql.in change_master_to.sql.orig mysql -h 127.0.0.1 <
在啟動(dòng)后,應(yīng)該能夠看到如下的信息:[root@k8s-master01 mysql]# kubectl get pods -lapp=mysql --watch -n kube-publicNAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 16mmysql-1 2/2 Running 1 15mmysql-2 2/2 Running 1 15m[root@k8s-master01 mysql]# kubectl get pod -o wide -n kube-publicNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESmysql-0 2/2 Running 0 16m 10.244.2.12 k8s-node02 mysql-1 2/2 Running 1 15m 10.244.1.13 k8s-node01 mysql-2 2/2 Running 1 15m 10.244.1.14 k8s-node01

MySQL部署環(huán)境驗(yàn)證

1)通過(guò)運(yùn)行一個(gè)臨時(shí)的容器(使用mysql:5.7鏡像),使用 MySQL 客戶端發(fā)送測(cè)試請(qǐng)求給 mysql master 節(jié)點(diǎn)( 主機(jī)名為 mysql-0.mysql;跨命名空間的話,主機(jī)名請(qǐng)使用 mysql-0.mysql.kube-public )

[root@k8s-master01 mysql]# kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never -- mysql -h mysql-0.mysql.kube-publicIf you don't see a command prompt, try pressing enter.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 625Server version: 5.7.16-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.在master節(jié)點(diǎn)上創(chuàng)建demo數(shù)據(jù)庫(kù),并創(chuàng)建一個(gè)只有message字段的demo.messages的表,并為message字段插入hello值。mysql> CREATE DATABASE demo;Query OK, 1 row affected (0.02 sec)mysql> CREATE TABLE demo.messages (message VARCHAR(250));Query OK, 0 rows affected (0.10 sec)mysql> INSERT INTO demo.messages VALUES ('hello');Query OK, 1 row affected (0.02 sec)

2)使用主機(jī)名為mysql-read來(lái)發(fā)送測(cè)試請(qǐng)求給服務(wù)器 (另開窗口)

[root@k8s-master01 mysql]# kubectl run mysql-client1 --image=mysql:5.7 -i -t --rm --restart=Never -- mysql -h mysql-read.kube-publicIf you don't see a command prompt, try pressing enter.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 608Server version: 5.7.16 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+------------------------+| Database |+------------------------+| information_schema || demo || mysql || performance_schema || sys || xtrabackup_backupfiles |+------------------------+6 rows in set (0.02 sec)mysql> select * from demo.messages;+---------+| message |+---------+| hello |+---------+1 row in set (0.00 sec)

滾動(dòng)更新、擴(kuò)展伸縮、更新策略、版本升級(jí)

RollingUpdate 更新策略在 StatefulSet 中實(shí)現(xiàn) Pod 的自動(dòng)滾動(dòng)更新。當(dāng)StatefulSet的 .spec.updateStrategy.type 設(shè)置為 RollingUpdate 時(shí),默認(rèn)為:RollingUpdate。StatefulSet 控制器將在 StatefulSet 中刪除并重新創(chuàng)建每個(gè) Pod。它將以與 Pod 終止相同的順序進(jìn)行(從最大的序數(shù)到最小的序數(shù)),每次更新一個(gè) Pod。在更新其前身之前,它將等待正在更新的 Pod 狀態(tài)變成正在運(yùn)行并就緒。

如下操作的滾動(dòng)更新是有 mysql 2-0的順序更新。

master、node節(jié)點(diǎn)下載測(cè)試的image鏡像docker pull registry.cn-hangzhou.aliyuncs.com/chad/mysql-5.7.19:latestdocker tag registry.cn-hangzhou.aliyuncs.com/chad/mysql-5.7.19:latest mysql:5.7.19修改mysql image版本mysql:5.7.19[root@k8s-master01 mysql]# cp mysql-statefulset.yaml mysql-5.7.19-statefulset.yaml[root@k8s-master01 mysql]# vim mysql-5.7.19-statefulset.yamlo-v2.yaml..... image: mysql:5.7.19 image: mysql:5.7.19....通過(guò)kubectl更新yaml文件[root@k8s-master01 mysql]# kubectl apply -f mysql-5.7.19-statefulset.yaml -n kube-publicstatefulset.apps/mysql configured查看滾動(dòng)更新的過(guò)程[root@k8s-master01 ~]# kubectl get pods -w -n kube-publicNAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 64mmysql-1 2/2 Running 1 64mmysql-2 2/2 Running 1 63mmysql-2 2/2 Terminating 1 63mmysql-2 0/2 Terminating 1 64mmysql-2 0/2 Terminating 1 64mmysql-2 0/2 Terminating 1 64mmysql-2 0/2 Pending 0 0smysql-2 0/2 Pending 0 0smysql-2 0/2 Init:0/2 0 0smysql-2 0/2 Init:0/2 0 1smysql-2 0/2 Init:1/2 0 3smysql-2 0/2 PodInitializing 0 4smysql-2 1/2 Running 0 5smysql-2 2/2 Running 0 9smysql-1 2/2 Terminating 1 65mmysql-1 0/2 Terminating 1 65mmysql-1 0/2 Terminating 1 65mmysql-1 0/2 Terminating 1 65mmysql-1 0/2 Pending 0 0smysql-1 0/2 Pending 0 0smysql-1 0/2 Init:0/2 0 0smysql-1 0/2 Init:0/2 0 1smysql-1 0/2 Init:1/2 0 2smysql-1 0/2 PodInitializing 0 3smysql-1 1/2 Running 0 6smysql-1 2/2 Running 0 11smysql-0 2/2 Terminating 0 66mmysql-0 1/2 Terminating 0 66mmysql-0 0/2 Terminating 0 66mmysql-0 0/2 Terminating 0 67mmysql-0 0/2 Terminating 0 67mmysql-0 0/2 Pending 0 0smysql-0 0/2 Pending 0 0smysql-0 0/2 Init:0/2 0 0smysql-0 0/2 Init:0/2 0 1smysql-0 0/2 Init:1/2 0 3smysql-0 0/2 PodInitializing 0 7smysql-0 1/2 Running 0 9smysql-0 2/2 Running 0 13s
[root@k8s-master01 mysql]# kubectl get sts -o wide -n kube-public NAME READY AGE CONTAINERS IMAGESmysql 3/3 77m mysql,xtrabackup mysql:5.7.19,gcr.io/google-samples/xtrabackup:1.0擴(kuò)容方法1:命令行,進(jìn)行擴(kuò)容[root@k8s-master01 mysql]# kubectl scale sts mysql --replicas=4 -n kube-publicstatefulset.apps/mysql scaled方法2:聲明式命令方式,直接修改stateful-demo-v2.yaml文件,進(jìn)行擴(kuò)容(推薦)[root@k8s-master01 mysql]# vim mysql-5.7.19-statefulset.yaml修改.spec.replicas的值spec: replicas: 4 [root@k8s-master01 mysql]# kubectl apply -f mysql-5.7.19-statefulset.yaml 方法3:補(bǔ)丁式命令方式,直接編輯運(yùn)行中sts,進(jìn)行擴(kuò)容[root@k8s-master01 mysql]# kubectl edit sts mysql -n kube-public修改.spec.replicas的值spec: replicas: 4 方法4:補(bǔ)丁式命令方式,通過(guò)打補(bǔ)丁的方式,進(jìn)行擴(kuò)容[root@k8s-master01 mysql]# kubectl patch sts mysql -p '{"spec":{"replicas":4}}' -n kube-public 查看mysql pod動(dòng)態(tài)擴(kuò)容[root@k8s-master01 ~]# kubectl get pods -w -n kube-publicNAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 16mmysql-1 2/2 Running 0 17mmysql-2 2/2 Running 0 17mmysql-3 0/2 Pending 0 0smysql-3 0/2 Pending 0 0smysql-3 0/2 Pending 0 2smysql-3 0/2 Init:0/2 0 2smysql-3 0/2 Init:0/2 0 4smysql-3 0/2 Init:1/2 0 5smysql-3 0/2 Init:1/2 0 6smysql-3 0/2 PodInitializing 0 27smysql-3 1/2 Error 0 28smysql-3 1/2 Running 1 29smysql-3 2/2 Running 1 34s查看mysql pod信息[root@k8s-master01 mysql]# kubectl get pod -n kube-public NAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 16mmysql-1 2/2 Running 0 17mmysql-2 2/2 Running 0 17mmyapp-3 1/1 Running 0 102s查看pvc[root@k8s-master01 mysql]# kubectl get pvc -n kube-publicNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEdata-mysql-0 Bound pvc-fba11f83-cf29-4b76-b66a-3a58f91738a9 10Gi RWO nfs 93mdata-mysql-1 Bound pvc-6c434fb2-1076-4912-80fb-eee6c0e3b957 10Gi RWO nfs 93mdata-mysql-2 Bound pvc-d33d34dd-a80f-41bd-82d0-58f7126fed13 10Gi RWO nfs 92mdata-mysql-3 Bound pvc-202370f2-a2aa-456c-8cb0-81686a4ea39e 10Gi RWO nfs 11m查看pv[root@k8s-master01 mysql]# kubectl get pvNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpvc-202370f2-a2aa-456c-8cb0-81686a4ea39e 10Gi RWO Delete Bound kube-public/data-mysql-3 nfs 11mpvc-6c434fb2-1076-4912-80fb-eee6c0e3b957 10Gi RWO Delete Bound kube-public/data-mysql-1 nfs 92mpvc-d33d34dd-a80f-41bd-82d0-58f7126fed13 10Gi RWO Delete Bound kube-public/data-mysql-2 nfs 92mpvc-fba11f83-cf29-4b76-b66a-3a58f91738a9 10Gi RWO Delete Bound kube-public/data-mysql-0 nfs 93m縮容方法1:命令行,進(jìn)行縮容[root@k8s-master01 mysql]# kubectl scale sts mysql --replicas=3 -n kube-publicstatefulset.apps/mysql scaled查看mysql pod動(dòng)態(tài)縮容[root@k8s-master01 ~]# kubectl get pods -w -n kube-publicNAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 31mmysql-1 2/2 Running 0 32mmysql-2 2/2 Running 0 32mmysql-3 2/2 Running 1 16mmysql-3 2/2 Terminating 1 16mmysql-3 0/2 Terminating 1 16mmysql-3 0/2 Terminating 1 16mmysql-3 0/2 Terminating 1 16m查看mysql pod信息[root@k8s-master01 mysql]# kubectl get pod -n kube-publicNAME READY STATUS RESTARTS AGEmysql-0 2/2 Running 0 33mmysql-1 2/2 Running 0 34mmysql-2 2/2 Running 0 34m查看pvc (pod刪除,pv和pvc 關(guān)聯(lián)還在,方便后續(xù)動(dòng)態(tài)擴(kuò)容,自動(dòng)掛載原pvc和pv)[root@k8s-master01 mysql]# kubectl get pvc -n kube-publicNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEdata-mysql-0 Bound pvc-fba11f83-cf29-4b76-b66a-3a58f91738a9 10Gi RWO nfs 100mdata-mysql-1 Bound pvc-6c434fb2-1076-4912-80fb-eee6c0e3b957 10Gi RWO nfs 100mdata-mysql-2 Bound pvc-d33d34dd-a80f-41bd-82d0-58f7126fed13 10Gi RWO nfs 99mdata-mysql-3 Bound pvc-202370f2-a2aa-456c-8cb0-81686a4ea39e 10Gi RWO nfs 18m查看pv (pod刪除,pv和pvc 關(guān)聯(lián)還在,方便后續(xù)動(dòng)態(tài)擴(kuò)容,自動(dòng)掛載原pvc和pv)[root@k8s-master01 mysql]# kubectl get pvNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEpvc-202370f2-a2aa-456c-8cb0-81686a4ea39e 10Gi RWO Delete Bound kube-public/data-mysql-3 nfs 18mpvc-6c434fb2-1076-4912-80fb-eee6c0e3b957 10Gi RWO Delete Bound kube-public/data-mysql-1 nfs 100mpvc-d33d34dd-a80f-41bd-82d0-58f7126fed13 10Gi RWO Delete Bound kube-public/data-mysql-2 nfs 99mpvc-fba11f83-cf29-4b76-b66a-3a58f91738a9 10Gi RWO Delete Bound kube-public/data-mysql-0 nfs 100m查看nfs存儲(chǔ)目錄/data/v1 (pod刪除,數(shù)據(jù)還在)[root@k8s-master01 mysql]# ll /data/v1/total 0drwxrwxrwx 3 root root 19 Jul 8 11:00 kube-public-data-mysql-0-pvc-fba11f83-cf29-4b76-b66a-3a58f91738a9drwxrwxrwx 3 root root 19 Jul 8 11:00 kube-public-data-mysql-1-pvc-6c434fb2-1076-4912-80fb-eee6c0e3b957drwxrwxrwx 3 root root 19 Jul 8 11:01 kube-public-data-mysql-2-pvc-d33d34dd-a80f-41bd-82d0-58f7126fed13drwxrwxrwx 3 root root 19 Jul 8 12:22 kube-public-data-mysql-3-pvc-202370f2-a2aa-456c-8cb0-81686a4ea39e

往期文章

Kubernetes 是什么?

Kubernetes 組件

Kubernetes 基礎(chǔ)概念

Kubernetes 1.18.2集群部署 (單Master)+docker

Kubernetes 1.18.2集群部署 (多Master)+docker

Kubernetes Harbor v2.0.0私有鏡像倉(cāng)庫(kù)部署-更新

Kubernetes kubectx/kubens切換context和namespace

Kubernetes 刪除namespace時(shí)卡在Terminating狀態(tài)

Kubernetes kubeadm初始化kubernetes集群延長(zhǎng)證書過(guò)期時(shí)間

Kubernetes kubectl命令

Kubernetes 創(chuàng)建、更新應(yīng)用

Kubernetes 資源清單

Kubernetes Pod狀態(tài)和生命周期管理

Kubernetes Pod控制器

Kubernetes ReplicaSet控制器

Kubernetes Deployment控制器

Kubernetes DamonSet控制器

Kubernetes 服務(wù)發(fā)現(xiàn)Service

Kubernetes Nginx Ingress Controller

Kubernetes 存儲(chǔ)卷

Kubernetes 特殊存儲(chǔ)卷—Secret和ConfigMap

Kubernetes StatefulSet控制器

Kubernetes 認(rèn)證、授權(quán)和準(zhǔn)入控制

Kubernetes dashboard認(rèn)證訪問(wèn)

Kubernetes 網(wǎng)絡(luò)模型和網(wǎng)絡(luò)策略

Kubernetes 網(wǎng)絡(luò)原理解析

Kubernetes 網(wǎng)絡(luò)插件-flannel

Kubernetes 網(wǎng)絡(luò)插件-calico

Kubernetes Pod資源調(diào)度

Kubernetes 資源指標(biāo)和集群監(jiān)控

Kubernetes 集群中部署Prometheus+Grafana+Alertmanager監(jiān)控告警系統(tǒng)

Kubernetes Prometheus監(jiān)控Nginx

Kubernetes Prometheus監(jiān)控MySQL

Kubernetes Prometheus監(jiān)控tomcat


聲明:免責(zé)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn)自行上傳,本網(wǎng)站不擁有所有權(quán),也不承認(rèn)相關(guān)法律責(zé)任。如果您發(fā)現(xiàn)本社區(qū)中有涉嫌抄襲的內(nèi)容,請(qǐng)發(fā)

送郵件至:operations@xinnet.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),本站將立刻刪除涉嫌侵權(quán)內(nèi)容。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)

需注明出處:新網(wǎng)idc知識(shí)百科

免費(fèi)咨詢獲取折扣

Loading
成人精品免费视频在线| 亚洲AV永久精品无码| 啪啪天堂| 国产一区久久镜品二区| 精品香蕉一区二区三区| 久久人妻无码一区二区三区AV| 国产另类 hd| 色五月欧美色图| 日本美女插逼| 在线观看视频AAA| 国产麻豆剧传媒免费观看| 亚洲自拍日韩欧美| 国产馆| 国产精品无码一区二区在线观一| 亚洲欧美日韩在线二区| 久久乐午夜| 中文字幕久荜日韩| 后入 在线| 日韩欧美激情久久| 后入美女逼视频| 久久午夜不卡| 人妻网址| 色婷婷一区二区三区四区成人网 | 少妇太爽了一区| 免费综合亚洲色图网| 色叉叉综合| 熟女91| 国产精品 视频一区 二区三区| 精品在线视频伊人| 亚洲巨奶无码| 久久久久线上观看| 亚洲日产一线二线三线精华液| 精品国产一区二区三区av 性色 | 秋霞精品一区二区| 日本色黄免费| 亚洲中文在线播放| 久久精品秘 一区| 六月桃花婷婷网| 污黄啪啪视频免费看| 亚洲AV无码一区二区二三区| 国产精品卡一卡二|