kubernetes安装mysql

半兽人 发表于: 2020-05-11   最后更新时间: 2020-06-09  

创建mysql-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: my-mysql
  name: my-mysql
  namespace: mysql-space
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-mysql
  template:
    metadata:
      labels:
        app: my-mysql
    spec:
      volumes:
      - name: my-mysql-data
        persistentVolumeClaim:
          claimName: my-mysql-data
      containers:
      - env:
        - name: MYSQL_ROOT_PASSWORD
          value: "root"
        - name: MYSQL_USER
          value: "test"
        - name: MYSQL_PASSWORD
          value: "test"
        image: "mysql:5.7"
        imagePullPolicy: IfNotPresent
        name: my-mysql
        ports:
        - containerPort: 3306
          protocol: TCP
          name: http
        volumeMounts:
        - name: my-mysql-data
          mountPath: /var/lib/mysql

创建mysql-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: my-mysql-data
  namespace: mysql-space
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: sc-test

创建configmap

当你需要替换my.cnf的时候,可以使用config替换mysql镜像中里的my.cnf,例子如下。

apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-conf
  namespace: mysql-space
data:
  mysql.cnf: |
    [mysqld]

     pid-file        = /var/run/mysqld/mysqld.pid
     socket          = /var/run/mysqld/mysqld.sock
     datadir         = /var/lib/mysql

     #log-error      = /var/log/mysql/error.log

     # By default we only accept connections from localhost
     # bind-address   = 127.0.0.1
     # Disabling symbolic-links is recommended to prevent assorted security risks

     symbolic-links=0

     sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION


您需要解锁本帖隐藏内容请: 点击这里
本帖隐藏的内容




上一条: Kubernetes imagePullPolicy拉取策略
下一条: kubernetes publishNotReadyAddresses介绍