• kubernetes系列:(二)、kubernetes部署mysql(单节点)


    使用kubeadm搭建好kubernetes集群后就可以动手部署自己的应用了。

    本文用例来自官网,如有需要请参看 kubernetes官网

    一、环境说明

    kubernetes 1.13.1

    docker 18.06.1-ce

    mysql  5.7

    一、创建mysql-pv.yaml,用来将mysql存储的数据放到宿主机磁盘

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

    二、创建mysql-deployment.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: mysql
    spec:
      ports:
      - port: 3306
      selector:
        app: mysql
      clusterIP: None
    ---
    apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
    kind: Deployment
    metadata:
      name: mysql
    spec:
      selector:
        matchLabels:
          app: mysql
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: mysql
        spec:
          containers:
          - image: mysql:5.7
            name: mysql
            env:
              # Use secret in real usage
            - name: MYSQL_ROOT_PASSWORD
              value: uwaynemya
            ports:
            - containerPort: 3306
              name: mysql
            volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
          volumes:
          - name: mysql-persistent-storage
            persistentVolumeClaim:
              claimName: mysql-pv-claim

    上述代码均可以在  haoprogrammer  github 上找到

    如果对您有帮助希望可以帮忙点颗星,感谢。

    您的支持是我最大的动力!

  • 相关阅读:
    观察者模式(Observer)
    记负均正
    自守数
    等差数列
    字符统计
    Linux 第四次上机收获
    关于java的类加载(血泪史)
    vi常用操作与命令【持续更新中】
    P3-2017级算法第三次上机 B SkyLee逛漫展
    P3-2017级算法第三次上机 A 水水的二分查找
  • 原文地址:https://www.cnblogs.com/haoprogrammer/p/10827287.html
Copyright © 2020-2023  润新知