利用k8s安装mysql

1.在以下网页中搜索mysql

kubebiz官方地址
利用k8s安装mysql

2.直接在仪表盘中创建mysql

    1).选择msyql版本和k8s版本(一般选择最新)
利用k8s安装mysql
利用k8s安装mysql

    2).将yaml文件修改

apiVersion: "apps/v1"
kind: Deployment
metadata:
  name: my-mysql
  namespace: default
  labels:
    app: my-mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-mysql
  template:
    metadata:
      labels:
        app: my-mysql
    spec:
      volumes:
        - name: data
          hostPath:
            path: nfs/k8s/hfocean-iot/mysql
      containers:
        - env:
            - name: MYSQL_ROOT_PASSWORD
              value: 123456
            - name: MYSQL_USER
              value: test
            - name: MYSQL_PASSWORD
              value: 123456
          image: 'mysql:5.7.33'
          imagePullPolicy: IfNotPresent
          name: my-mysql
          ports:
            - containerPort: 3306
              protocol: TCP
              name: http
          volumeMounts:
            - name: my-mysql-data
              mountPath: /var/lib/mysql
            - name: mysql-conf
              mountPath: /etc/mysql/mysql.conf.d

    以下是我公司内部实际应用的json配置(关键部分已修改)(下面这个和上面的配置都可以运行)

{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "mysql-test",
    "namespace": "命名空间",
    "labels": {
      "env": "test",
      "name": "mysql"
    }
  },
  "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "env": "test",
        "name": "mysql"
      }
    },
    "template": {
      "metadata": {
        "name": "mysql",
        "labels": {
          "env": "test",
          "name": "mysql"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "mysql",
            "image": "mysql:5.7",
            "env": [
              {
                "name": "MYSQL_ROOT_PASSWORD",
                "value": "123456"
              }
            ],
            "volumeMounts": [
              {
                "name": "data",
                "mountPath": "/var/lib/mysql"
              }
            ]
          }
        ],
        "volumes":[
          {
            "name": "data",
            "hostPath": {
              "path": "/nfs/k8s/hfocean-iot/duixia/mysql"
            }
          }
        ]
      }
    }
  }
}

    3).将文件复制到仪表盘
利用k8s安装mysql
利用k8s安装mysql

3.通过命令创建mysql

    1).选择msyql版本和k8s版本(一般选择最新),复制命令
利用k8s安装mysql

    3).执行命令
    kubectl apply -f https://www.kubebiz.com/raw/KubeBiz/mysql/5.7.33/Deployment.yaml

上一篇:封装及其作用Java


下一篇:ORM(4) 路由层