zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    android 四大组件
    apk 反编译
    通过 PC 远程控制 Android 的应用 -- 可以将手机屏幕投射显示到电脑上
    vmware 装 puppy
    vmware 装 puppy
    js prototype 添加属性对象
    js 百度云搜索框
    js 秒杀
    秒杀的性能和超卖
    [JOI2012春季合宿]Rotate (链表)
  • 原文地址:https://www.cnblogs.com/pengrj/p/15718931.html
Copyright © 2011-2022 走看看