• K8S部署单实例mysql


    mkdir –p /root/mysqldanji

    1.创建PV

    vim mysql-pv.yaml

    apiVersion: v1
    kind: PersistentVolume
    metadata:
       name: mysql-pv-volume
       labels:
         type: local
    spec:
       storageClassName: manual
       capacity:
         storage: 4Gi
       accessModes:
         - ReadWriteOnce
       hostPath:
         path: "/mnt/data"
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
       name: mysql-pv-claim
    spec:
       storageClassName: manual
       accessModes:
         - ReadWriteOnce
       resources:
         requests:
           storage: 4Gi

    kubectl apply –f  mysql-pv.yaml

    2.创建mysql

    vim mysql-deployment.yaml

    apiVersion: v1
    kind: Service
    metadata:
       name: mysql
    spec:
       ports:
       - port: 3306
       selector:
         app: mysql
       clusterIP: None
    ---
    apiVersion: v1
    kind: Service
    metadata:
       name: mysqldanji
    spec:
       ports:
       - port: 3303
         protocol: TCP
         targetPort: 3306
         nodePort:  3306
       selector:
         app: mysql
       type: NodePort
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
       name: mysql
    spec:
       selector:
         matchLabels:
           app: mysql
       strategy:
         type: Recreate
       template:
         metadata:
           labels:
             app: mysql

    spec:
       containers:
       - image: mysql:5.6
         name: mysql
         env:
           # Use secret in real usage
         - name: MYSQL_ROOT_PASSWORD
           value: password
         ports:
         - containerPort: 3306
           name: mysql
         volumeMounts:
         - name: mysql-persistent-storage
           mountPath: /var/lib/mysql
       volumes:
       - name: mysql-persistent-storage
         persistentVolumeClaim:
           claimName: mysql-pv-claim


    kubectl apply  -f   mysql-deployment.yaml

    kubectl get pods,svc

    image

    集群内随便运行 MySQL 客户端以连接到服务器:

    kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword

    mysql> create database prj;

    mysql> show databases;

    image

    3.用wind客户端连接验证

    默认mysql账号密码:  root    password

    image

    image

  • 相关阅读:
    [C++][编程风格]C++命名规则
    [Android]搜索关键字飞入飞出效果 (转)
    android,性能优化,内存优化管理,高级缓存 (转)
    Java内存泄露原因详解
    Java之线程(2) 调时器
    Java之线程(1) 传统线程机制的回顾
    Hibernate(1) 阻抗不匹配
    No4.传统线程同步通信技术
    Android内存溢出
    MAT Memory Analyzer Tool 插件装配(图解)(转)
  • 原文地址:https://www.cnblogs.com/pengrj/p/15718931.html
Copyright © 2020-2023  润新知