• K8s--09 编写mysql的持久化deployment


    k8s实战--编写mysql的持久化deployment


    1.实验-编写mysql的持久化deployment
    #先打标签
    [root@node1 ~/volume]# kubectl label nodes node3 disktype=SSD
    #编写资源清单
    [root@node1 ~/volume]# cat mysql-hostpath-ssd.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mysql-dp
      namespace: default
    spec:
      selector:
        matchLabels:
          app: mysql 
      replicas: 1
      template: 
        metadata:
          name: mysql-pod
          namespace: default
          labels:
            app: mysql
        spec:
          containers:
          - name: mysql-pod
            image: mysql:5.7 
            ports:
            - name: mysql-port
              containerPort: 3306
            env:
            - name: MYSQL_ROOT_PASSWORD
              value: "123456" 
            volumeMounts:
            - mountPath: /var/lib/mysql
              name: mysql-volume
          volumes:
          - name: mysql-volume
            hostPath:
              path: /data/mysql
              type: DirectoryOrCreate 
          nodeSelector:
            disktype: SSD
    
    
    2.检查是否生成容器
    [root@node1 ~/volume]# kubectl get pod
    mysql-dp-d9dd6799d-rn4lf           1/1     Running   0          3m56s
    
    3.登录并进入mysql镜像
    [root@node1 ~/volume]# kubectl exec -it mysql-dp-d9dd6799d-rn4lf /bin/bash
    root@mysql-dp-d9dd6799d-rn4lf:/# 
    
    4.在容器里面登录数据库
    root@mysql-dp-d9dd6799d-rn4lf:/# mysql -uroot -p123456
    
    5.创建数据库并查看
    mysql> create database dyc;
    Query OK, 1 row affected (0.01 sec)
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | dyc                |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.00 sec)
    
    
    6.退出并删除mysql容器的资源清单
    [root@node1 ~/volume]# kubectl delete -f  mysql-hostpath-ssd.yaml
    
    7.再次应用资源清单
    [root@node1 ~/volume]# kubectl create -f mysql-hostpath-ssd.yaml
    
    8.登录新生成的数据库容器
    [root@node1 ~/volume]# kubectl exec -it mysql-dp-d9dd6799d-dg6p8 /bin/bash
    root@mysql-dp-d9dd6799d-dg6p8:/# 
    
    9.登录容器中的数据可并查看之前创建的数据库是否存在
    root@mysql-dp-d9dd6799d-dg6p8:/# mysql -uroot -p123456
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | dyc                |         #之前创建的数据库存在,即持久化成功
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    5 rows in set (0.00 sec)
    
    10.查看加点mysql容器是否把数据映射到宿主机
    [root@node3 ~]# ll /data/mysql/
    drwxr-x--- 2 polkitd input       20 3月   2 21:46 dyc
    drwxr-x--- 2 polkitd input     4096 3月   2 21:40 mysql
    
  • 相关阅读:
    A Simple Problem with Integers-POJ3468 区间修改+区间查询
    致橡树
    OJ-Triangle
    Myeclipse+AJAX+Servlet
    opnet学习过程
    yii2在ubuntu下执行定时任务
    php创建文件夹后设置文件夹权限(转)
    “Request Entity Too Large” 上传图片出现大小限制
    慕课网,我的yii2学习笔记(基础篇)
    Yii2高级版本复制新项目出现问题解决(转)
  • 原文地址:https://www.cnblogs.com/gongjingyun123--/p/12543282.html
Copyright © 2020-2023  润新知