自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

基于K8S的StatefulSet部署MySQL集群

運(yùn)維 系統(tǒng)運(yùn)維
展示如何使用 StatefulSet 控制器運(yùn)行一個(gè)有狀態(tài)的應(yīng)用程序。此例是多副本的 MySQL 數(shù)據(jù)庫(kù)。 示例應(yīng)用的拓?fù)浣Y(jié)構(gòu)有一個(gè)主服務(wù)器和多個(gè)副本,使用異步的基于行(Row-Based) 的數(shù)據(jù)復(fù)制。

[[433184]]

環(huán)境:

# 采用NFS存儲(chǔ)卷的方式 持久化存儲(chǔ)mysql數(shù)據(jù)目錄

需求:

展示如何使用 StatefulSet 控制器運(yùn)行一個(gè)有狀態(tài)的應(yīng)用程序。此例是多副本的 MySQL 數(shù)據(jù)庫(kù)。 示例應(yīng)用的拓?fù)浣Y(jié)構(gòu)有一個(gè)主服務(wù)器和多個(gè)副本,使用異步的基于行(Row-Based) 的數(shù)據(jù)復(fù)制。

基于K8S的StatefulSet部署MySQL集群
  • 搭建一個(gè)“主從復(fù)制”(Maser-Slave Replication)的 MySQL 集群
  • 存在一個(gè)主節(jié)點(diǎn)【master】,有多個(gè)從節(jié)點(diǎn)【slave】
  • 從節(jié)點(diǎn)可以水平拓展
  • 所有的寫(xiě)操作,只能在主節(jié)點(diǎn)上執(zhí)行
  • 讀操作可以在所有節(jié)點(diǎn)上執(zhí)行

一、部署NFS服務(wù)器

  1. #服務(wù)器安裝nfs服務(wù),提供nfs存儲(chǔ)功能 
  2. 1、安裝nfs-utils 
  3. yum install nfs-utils (centos) 
  4. 或者  apt-get install nfs-kernel-server (ubuntu) 
  5.  
  6. 2、啟動(dòng)服務(wù) 
  7. systemctl enable nfs-server 
  8. systemctl start nfs-server 
  9.  
  10. 3、創(chuàng)建共享目錄完成共享配置 
  11. mkdir /home/nfs   #創(chuàng)建共享目錄 
  12.  
  13. 4、編輯共享配置 
  14. vim /etc/exports                                            
  15. #語(yǔ)法格式:    共享文件路徑     客戶(hù)機(jī)地址(權(quán)限)     #這里的客戶(hù)機(jī)地址可以是IP,網(wǎng)段,域名,也可以是任意* 
  16. /home/nfs  *(rw,async,no_root_squash) 
  1. #服務(wù)器安裝nfs服務(wù),提供nfs存儲(chǔ)功能 
  2. 1、安裝nfs-utils 
  3. yum install nfs-utils (centos) 
  4. 或者  apt-get install nfs-kernel-server (ubuntu) 
  5.  
  6. 2、啟動(dòng)服務(wù) 
  7. systemctl enable nfs-server 
  8. systemctl start nfs-server 
  9.  
  10. 3、創(chuàng)建共享目錄完成共享配置 
  11. mkdir /home/nfs   #創(chuàng)建共享目錄 
  12.  
  13. 4、編輯共享配置 
  14. vim /etc/exports                                            
  15. #語(yǔ)法格式:    共享文件路徑     客戶(hù)機(jī)地址(權(quán)限)     #這里的客戶(hù)機(jī)地址可以是IP,網(wǎng)段,域名,也可以是任意* 
  16. /home/nfs  *(rw,async,no_root_squash) 
  1. 服務(wù)自檢命令  
  2. exportfs -arv 
  3.  
  4.  
  5. 5、重啟服務(wù) 
  6. systemctl restart nfs-server 
  7.  
  8.  
  9. 6、本機(jī)查看nfs 共享目錄 
  10. #showmount -e 服務(wù)器IP地址 (如果提示命令不存在,則需要yum install showmount) 
  11.  
  12. showmount -e 127.0.0.1 
  13. /home/nfs * 
  14.  
  15.  
  16.  
  17. 7、客戶(hù)端模擬掛載[所有k8s的節(jié)點(diǎn)都需要安裝客戶(hù)端] 
  18. [root@master-1 ~]# yum install nfs-utils (centos) 
  19. 或者  apt-get install nfs-common (ubuntu) 
  20. [root@master-1 ~]# mkdir /test 
  21. [root@master-1 ~]# mount -t nfs 172.16.201.209:/home/nfs /test 
  22.  
  23. #取消掛載 
  24. [root@master-1 ~]# umount /test 

二、配置PV 動(dòng)態(tài)供給(NFS StorageClass),創(chuàng)建pvc

部署NFS實(shí)現(xiàn)自動(dòng)創(chuàng)建PV插件: 一共設(shè)計(jì)到4個(gè)yaml 文件 ,官方的文檔有詳細(xì)的說(shuō)明

https://github.com/kubernetes-incubator/external-storage

基于K8S的StatefulSet部署MySQL集群
基于K8S的StatefulSet部署MySQL集群
  1. root@k8s-master1:~ # mkdir  /root/pvc 
  2. root@k8s-master1:~ # cd   /root/pvc 

創(chuàng)建rbac.yaml 文件

  1. root@k8s-master1:pvc # cat rbac.yaml  
  2. kind: ServiceAccount 
  3. apiVersion: v1 
  4. metadata: 
  5.   name: nfs-client-provisioner 
  6. --- 
  7. kind: ClusterRole 
  8. apiVersion: rbac.authorization.k8s.io/v1 
  9. metadata: 
  10.   name: nfs-client-provisioner-runner 
  11. rules: 
  12.   - apiGroups: [""
  13.     resources: ["persistentvolumes"
  14.     verbs: ["get""list""watch""create""delete"
  15.   - apiGroups: [""
  16.     resources: ["persistentvolumeclaims"
  17.     verbs: ["get""list""watch""update"
  18.   - apiGroups: ["storage.k8s.io"
  19.     resources: ["storageclasses"
  20.     verbs: ["get""list""watch"
  21.   - apiGroups: [""
  22.     resources: ["events"
  23.     verbs: ["create""update""patch"
  24. --- 
  25. kind: ClusterRoleBinding 
  26. apiVersion: rbac.authorization.k8s.io/v1 
  27. metadata: 
  28.   name: run-nfs-client-provisioner 
  29. subjects: 
  30.   - kind: ServiceAccount 
  31.     name: nfs-client-provisioner 
  32.     namespace: default 
  33. roleRef: 
  34.   kind: ClusterRole 
  35.   name: nfs-client-provisioner-runner 
  36.   apiGroup: rbac.authorization.k8s.io 
  37. --- 
  38. kind: Role 
  39. apiVersion: rbac.authorization.k8s.io/v1 
  40. metadata: 
  41.   name: leader-locking-nfs-client-provisioner 
  42. rules: 
  43.   - apiGroups: [""
  44.     resources: ["endpoints"
  45.     verbs: ["get""list""watch""create""update""patch"
  46. --- 
  47. kind: RoleBinding 
  48. apiVersion: rbac.authorization.k8s.io/v1 
  49. metadata: 
  50.   name: leader-locking-nfs-client-provisioner 
  51. subjects: 
  52.   - kind: ServiceAccount 
  53.     name: nfs-client-provisioner 
  54.     # replace with namespace where provisioner is deployed 
  55.     namespace: default 
  56. roleRef: 
  57.   kind: Role 
  58.   name: leader-locking-nfs-client-provisioner 
  59.   apiGroup: rbac.authorization.k8s.io 

創(chuàng)建deployment.yaml 文件

官方默認(rèn)的鏡像地址,國(guó)內(nèi)可能無(wú)法下載,可以使用 image:

fxkjnj/nfs-client-provisioner:latest

#定義NFS 服務(wù)器的地址,共享目錄名稱(chēng)

  1. root@k8s-master1:pvc # cat deployment.yaml  
  2. apiVersion: v1 
  3. kind: ServiceAccount 
  4. metadata: 
  5.   name: nfs-client-provisioner 
  6. --- 
  7. kind: Deployment 
  8. apiVersion: apps/v1  
  9. metadata: 
  10.   name: nfs-client-provisioner 
  11. spec: 
  12.   replicas: 1 
  13.   strategy: 
  14.     type: Recreate 
  15.   selector: 
  16.     matchLabels: 
  17.       app: nfs-client-provisioner 
  18.   template: 
  19.     metadata: 
  20.       labels: 
  21.         app: nfs-client-provisioner 
  22.     spec: 
  23.       serviceAccountName: nfs-client-provisioner 
  24.       containers: 
  25.         - name: nfs-client-provisioner 
  26.           image: fxkjnj/nfs-client-provisioner:latest 
  27.           volumeMounts: 
  28.             - name: nfs-client-root 
  29.               mountPath: /persistentvolumes 
  30.           env: 
  31.             - name: PROVISIONER_NAME 
  32.               value: fuseim.pri/ifs 
  33.             - name: NFS_SERVER 
  34.               value: 172.16.201.209  
  35.             - name: NFS_PATH 
  36.               value: /home/nfs 
  37.       volumes: 
  38.         - name: nfs-client-root 
  39.           nfs: 
  40.             server: 172.16.201.209 
  41.             path: /home/nfs 

 創(chuàng)建class.yaml

  1. root@k8s-master1:pvc # cat class.yaml  
  2. apiVersion: storage.k8s.io/v1 
  3. kind: StorageClass 
  4. metadata: 
  5.   name: managed-nfs-storage 
  6. provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME' 
  7. parameters: 
  8.   archiveOnDelete: "true" 

 部署

  1. root@k8s-master1:pvc # kubectl apply -f . 
  2.  
  3.  
  4. #查看存儲(chǔ)卷 
  5. root@k8s-master1:pvc # kubectl  get sc 
  6. NAME                  PROVISIONER      RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE 
  7. managed-nfs-storage   fuseim.pri/ifs   Delete          Immediate           false                  25h 

三、編寫(xiě)mysql 相關(guān)yaml文件

MySQL 示例部署包含一個(gè) ConfigMap、兩個(gè) Service 與一個(gè) StatefulSet。

ConfigMap:

vim mysql-configmap.yaml

  1. apiVersion: v1 
  2. kind: ConfigMap 
  3. metadata: 
  4.   name: mysql 
  5.   labels: 
  6.     app: mysql 
  7. data: 
  8.   master.cnf: | 
  9.     # Apply this config only on the master. 
  10.     [mysqld] 
  11.     log-bin     
  12.   slave.cnf: | 
  13.     # Apply this config only on slaves. 
  14.     [mysqld] 
  15.     super-read-only 

 說(shuō)明:

在這里,我們定義了 master.cnf 和 slave.cnf 兩個(gè) MySQL 的配置文件

  • master.cnf 開(kāi)啟了log-bin,可以使用二進(jìn)制日志文件的方式進(jìn)行主從復(fù)制.
  • slave.cnf 開(kāi)啟了 super-read-only ,表示從節(jié)點(diǎn)只接受主節(jié)點(diǎn)的數(shù)據(jù)同步的所有寫(xiě)的操作,拒絕其他的寫(xiě)入操作,對(duì)于用戶(hù)來(lái)說(shuō)就是只讀的
  • master.cnf 和 slave.cnf 已配置文件的形式掛載到容器的目錄中

Service:

vim mysql-services.yaml

  1. # Headless service for stable DNS entries of StatefulSet members. 
  2. apiVersion: v1 
  3. kind: Service 
  4. metadata: 
  5.   name: mysql 
  6.   labels: 
  7.     app: mysql 
  8. spec: 
  9.   ports: 
  10.   - name: mysql 
  11.     port: 3306 
  12.   clusterIP: None 
  13.   selector: 
  14.     app: mysql 
  15. --- 
  16. # Client service for connecting to any MySQL instance for reads. 
  17. For writes, you must instead connect to the master: mysql-0.mysql. 
  18. apiVersion: v1 
  19. kind: Service 
  20. metadata: 
  21.   name: mysql-read 
  22.   labels: 
  23.     app: mysql 
  24. spec: 
  25.   ports: 
  26.   - name: mysql 
  27.     port: 3306 
  28.   selector: 
  29.     app: mysql 

 說(shuō)明:

clusterIP: None,使用無(wú)頭服務(wù) Headless Service(相比普通Service只是將spec.clusterIP定義為None,也就是沒(méi)有clusterIP,直接使用endport 來(lái)通信)來(lái)維護(hù)Pod網(wǎng)絡(luò)身份,會(huì)為每個(gè)Pod分配一個(gè)數(shù)字編號(hào)并且按照編號(hào)順序部署。還需要在StatefulSet添加serviceName: “mysql”字段指定StatefulSet控制器

另外statefulset控制器網(wǎng)絡(luò)標(biāo)識(shí),體現(xiàn)在主機(jī)名和Pod A記錄:

• 主機(jī)名:<statefulset名稱(chēng)>-<編號(hào)>

例如: mysql-0

• Pod DNS A記錄:<statefulset名稱(chēng)-編號(hào)>.<service-name> .<namespace>.svc.cluster.local (POD 之間通過(guò)DNS A 記錄互相通信)

例如:

mysql-0.mysql.default.svc.cluster.local

StatefulSet:

vim mysql-statefulset.yaml

  1. apiVersion: apps/v1 
  2. kind: StatefulSet 
  3. metadata: 
  4.   name: mysql 
  5. spec: 
  6.   selector: 
  7.     matchLabels: 
  8.       app: mysql 
  9.   serviceName: mysql 
  10.   replicas: 3 
  11.   template: 
  12.     metadata: 
  13.       labels: 
  14.         app: mysql 
  15.     spec: 
  16.       initContainers: 
  17.       - name: init-mysql 
  18.         image: mysql:5.7 
  19.         command: 
  20.         - bash 
  21.         - "-c" 
  22.         - | 
  23.           set -ex 
  24.           # Generate mysql server-id from pod ordinal index
  25.           [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 
  26.           ordinal=${BASH_REMATCH[1]} 
  27.           echo [mysqld] > /mnt/conf.d/server-id.cnf 
  28.           # Add an offset to avoid reserved server-id=0 value. 
  29.           echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf 
  30.           # Copy appropriate conf.d files from config-map to emptyDir. 
  31.           if [[ $ordinal -eq 0 ]]; then 
  32.             cp /mnt/config-map/master.cnf /mnt/conf.d/ 
  33.           else 
  34.             cp /mnt/config-map/slave.cnf /mnt/conf.d/ 
  35.           fi           
  36.         volumeMounts: 
  37.         - name: conf 
  38.           mountPath: /mnt/conf.d 
  39.         - name: config-map 
  40.           mountPath: /mnt/config-map 
  41.       - name: clone-mysql 
  42.         image: fxkjnj/xtrabackup:1.0 
  43.         command: 
  44.         - bash 
  45.         - "-c" 
  46.         - | 
  47.           set -ex 
  48.           # Skip the clone if data already exists. 
  49.           [[ -d /var/lib/mysql/mysql ]] && exit 0 
  50.           # Skip the clone on master (ordinal index 0). 
  51.           [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 
  52.           ordinal=${BASH_REMATCH[1]} 
  53.           [[ $ordinal -eq 0 ]] && exit 0 
  54.           # Clone data from previous peer. 
  55.           ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql 
  56.           # Prepare the backup. 
  57.           xtrabackup --prepare --target-dir=/var/lib/mysql           
  58.         volumeMounts: 
  59.         - name: data 
  60.           mountPath: /var/lib/mysql 
  61.           subPath: mysql 
  62.         - name: conf 
  63.           mountPath: /etc/mysql/conf.d 
  64.       containers: 
  65.       - name: mysql 
  66.         image: mysql:5.7 
  67.         env: 
  68.         - name: MYSQL_ALLOW_EMPTY_PASSWORD 
  69.           value: "1" 
  70.         ports: 
  71.         - name: mysql 
  72.           containerPort: 3306 
  73.         volumeMounts: 
  74.         - name: data 
  75.           mountPath: /var/lib/mysql 
  76.           subPath: mysql 
  77.         - name: conf 
  78.           mountPath: /etc/mysql/conf.d 
  79.         resources: 
  80.           requests: 
  81.             cpu: 500m 
  82.             memory: 1Gi 
  83.         livenessProbe: 
  84.           exec
  85.             command: ["mysqladmin""ping"
  86.           initialDelaySeconds: 30 
  87.           periodSeconds: 10 
  88.           timeoutSeconds: 5 
  89.         readinessProbe: 
  90.           exec
  91.             # Check we can execute queries over TCP (skip-networking is off). 
  92.             command: ["mysql""-h""127.0.0.1""-e""SELECT 1"
  93.           initialDelaySeconds: 5 
  94.           periodSeconds: 2 
  95.           timeoutSeconds: 1 
  96.       - name: xtrabackup 
  97.         image: fxkjnj/xtrabackup:1.0 
  98.         ports: 
  99.         - name: xtrabackup 
  100.           containerPort: 3307 
  101.         command: 
  102.         - bash 
  103.         - "-c" 
  104.         - | 
  105.           set -ex 
  106.           cd /var/lib/mysql 
  107.  
  108.           # Determine binlog position of cloned data, if any
  109.           if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then 
  110.             # XtraBackup already generated a partial "CHANGE MASTER TO" query 
  111.             # because we're cloning from an existing slave. (Need to remove the tailing semicolon!) 
  112.             cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in 
  113.             # Ignore xtrabackup_binlog_info in this case (it's useless). 
  114.             rm -f xtrabackup_slave_info xtrabackup_binlog_info 
  115.           elif [[ -f xtrabackup_binlog_info ]]; then 
  116.             # We're cloning directly from master. Parse binlog position. 
  117.             [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1 
  118.             rm -f xtrabackup_binlog_info xtrabackup_slave_info 
  119.             echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\ 
  120.                   MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in 
  121.           fi 
  122.  
  123.           # Check if we need to complete a clone by starting replication. 
  124.           if [[ -f change_master_to.sql.in ]]; then 
  125.             echo "Waiting for mysqld to be ready (accepting connections)" 
  126.             until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done 
  127.  
  128.             echo "Initializing replication from clone position" 
  129.             mysql -h 127.0.0.1 \ 
  130.                   -e "$(<change_master_to.sql.in), \ 
  131.                           MASTER_HOST='mysql-0.mysql', \ 
  132.                           MASTER_USER='root', \ 
  133.                           MASTER_PASSWORD='', \ 
  134.                           MASTER_CONNECT_RETRY=10; \ 
  135.                         START SLAVE;" || exit 1 
  136.             # In case of container restart, attempt this at-most-once. 
  137.             mv change_master_to.sql.in change_master_to.sql.orig 
  138.           fi 
  139.  
  140.           # Start a server to send backups when requested by peers. 
  141.           exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \ 
  142.             "xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root"           
  143.         volumeMounts: 
  144.         - name: data 
  145.           mountPath: /var/lib/mysql 
  146.           subPath: mysql 
  147.         - name: conf 
  148.           mountPath: /etc/mysql/conf.d 
  149.         resources: 
  150.           requests: 
  151.             cpu: 100m 
  152.             memory: 100Mi 
  153.       volumes: 
  154.       - name: conf 
  155.         emptyDir: {} 
  156.       - name: config-map 
  157.         configMap: 
  158.           name: mysql 
  159.   volumeClaimTemplates: 
  160.   - metadata: 
  161.       name: data 
  162.     spec: 
  163.       storageClassName: "managed-nfs-storage" 
  164.       accessModes: ["ReadWriteOnce"
  165.       resources: 
  166.         requests: 
  167.           storage: 0.5Gi 

說(shuō)明:

  • 使用xtrbackup 工具進(jìn)行容器初始化數(shù)據(jù)的備份,https://www.toutiao.com/i6999565563710292484
  • 使用linux 自帶的ncat 工具進(jìn)行容器初始化數(shù)據(jù)的拷貝[使用ncat指令,遠(yuǎn)程地從前一個(gè)節(jié)點(diǎn)拷貝數(shù)據(jù)到本地] https://www.cnblogs.com/chengd/p/7565280.html
  • 使用mysql的binlog 主從復(fù)制 來(lái)保證主從之間的數(shù)據(jù)一致
  • 利用pod的主機(jī)名的序號(hào)來(lái)判斷當(dāng)前節(jié)點(diǎn)為主節(jié)點(diǎn)還是從節(jié)點(diǎn),再根據(jù)對(duì)于節(jié)點(diǎn)拷貝不同的配置文件到指定位置
  • 使用mysqladmin的ping 作為數(shù)據(jù)庫(kù)的健康檢測(cè)方式
  • 使用nfs存儲(chǔ)的 PV 動(dòng)態(tài)供給(StorageClass),持久化mysql的數(shù)據(jù)文件

四、部署并測(cè)試

  1. root@k8s-master1:~/kubernetes/mysql# ll 
  2. total 24 
  3. drwxr-xr-x 2 root root 4096 Nov  3 16:42 ./ 
  4. drwxr-xr-x 8 root root 4096 Nov  3 13:33 ../ 
  5. -rw-r--r-- 1 root root  278 Nov  2 22:15 mysql-configmap.yaml 
  6. -rw-r--r-- 1 root root  556 Nov  2 22:08 mysql-services.yaml 
  7. -rw-r--r-- 1 root root 5917 Nov  3 14:22 mysql-statefulset.yaml 
  8.  
  9. root@k8s-master1:~/kubernetes/mysql# kubectl apply -f . 
  10. configmap/mysql create 
  11. service/mysql create 
  12. service/mysql-read create 
  13. statefulset.apps/mysql create 
  14.  
  15.  
  16. #動(dòng)態(tài)追蹤查看Pod的狀態(tài): 
  17. root@k8s-master1:~/kubernetes/mysql# kubectl get pods -l app=mysql --watch 
  18. NAME      READY   STATUS    RESTARTS   AGE 
  19. mysql-0   2/2     Running   0          3h12m 
  20. mysql-1   2/2     Running   0          3h11m 
  21. mysql-2   2/2     Running   0          3h10m 

 可以看到,StatefulSet 啟動(dòng)成功后,將會(huì)有三個(gè) Pod 運(yùn)行。

接下來(lái),我們可以嘗試向這個(gè) MySQL 集群發(fā)起請(qǐng)求,執(zhí)行一些 SQL 操作來(lái)驗(yàn)證它是否正常:

  1. kubectl run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\ 
  2. mysql -h mysql-0.mysql <<EOF 
  3. CREATE DATABASE test; 
  4. CREATE TABLE test.messages (message VARCHAR(250)); 
  5. INSERT INTO test.messages VALUES ('hello'); 
  6. EOF 

 如上所示,我們通過(guò)啟動(dòng)一個(gè)容器,使用 MySQL client 執(zhí)行了創(chuàng)建數(shù)據(jù)庫(kù)和表、以及插入數(shù)據(jù)的操作。需要注意的是,我們連接的 MySQL 的地址必須是 mysql-0.mysql(即:Master 節(jié)點(diǎn)的 DNS A 記錄, 因?yàn)镻OD 之間通過(guò)DNS A 記錄互相通信)只有 Master 節(jié)點(diǎn)才能處理寫(xiě)操作。

而通過(guò)連接 mysql-read 這個(gè) Service,我們就可以用 SQL 進(jìn)行讀操作,如下所示:

  1. kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\ 
  2.   mysql -h mysql-read -e "SELECT * FROM test.messages" 
  3.    
  4.    
  5. #你應(yīng)該獲得如下輸出: 
  6. Waiting for pod default/mysql-client to be running, status is Pending, pod ready: false 
  7. +---------+ 
  8. | message | 
  9. +---------+ 
  10. | hello   | 
  11. +---------+ 
  12. pod "mysql-client" deleted 

 或者:

  1. root@k8s-master1:~/kubernetes/mysql# kubectl run -it --rm --image=mysql:5.7 --restart=Never mysql-client -- mysql -h mysql-read 
  2. If you don't see a command prompt, try pressing enter. 
  3. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  4. Your MySQL connection id is 7251 
  5. Server version: 5.7.36 MySQL Community Server (GPL) 
  6.  
  7. Copyright (c) 2000, 2021, Oracle and/or its affiliates. 
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its 
  10. affiliates. Other names may be trademarks of their respective 
  11. owners. 
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  14.  
  15. mysql> SELECT * FROM test.messages; 
  16. +---------+ 
  17. | message | 
  18. +---------+ 
  19. | hello   | 
  20. +---------+ 
  21. 1 row in set (0.00 sec) 
  22.  
  23. mysql>  
責(zé)任編輯:姜華 來(lái)源: 今日頭條
相關(guān)推薦

2025-03-19 08:01:10

Kubernetes集群源碼

2023-09-06 08:12:04

k8s云原生

2023-03-05 21:50:46

K8s集群容量

2023-09-03 23:58:23

k8s集群容量

2021-04-22 09:46:35

K8SCluster Aut集群

2022-04-22 13:32:01

K8s容器引擎架構(gòu)

2024-02-01 09:48:17

2023-11-06 07:16:22

WasmK8s模塊

2022-12-28 10:52:34

Etcd備份

2024-05-27 00:00:10

KubernetesK8s云原生

2023-09-07 08:58:36

K8s多集群

2021-03-24 06:26:00

kubeadmK8Scontainerd

2021-11-08 07:48:48

K8SKubernetes 集群

2023-11-07 08:23:05

2023-07-11 07:12:21

Hadoop部署mysql

2023-07-10 07:22:16

2024-08-30 09:21:28

2022-01-02 08:42:50

架構(gòu)部署容器

2023-02-27 07:40:00

2022-04-07 10:17:18

云原生服務(wù)器優(yōu)化
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)