1. Docker 创建mysql8

创建存储(或直接挂载路径)

docker volume create mysql8

启动

docker rm -f mysql8;\
docker run -d \
--restart unless-stopped \
--name mysql8 \
-p 3306:3306 \
-v mysql8:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=QWERT!@#$% \
-e TZ=Asia/Shanghai \
mysql:8 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci \
--default-authentication-plugin=mysql_native_password \
--lower_case_table_names=1 \
--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

查看

mysql -uroot -pQWER!@#$%
select @@global.sql_mode

2.K8s创建mysql8

此处未挂载,可能数据丢失,需执行挂载主机路径或pvc

创建service

apiVersion: v1
kind: Service
metadata:
  name: mysql-svc
  labels: 
    name: mysql-svc
spec:
  type: NodePort
  ports:
  - port: 3306
    protocol: TCP
    targetPort: 3306
    name: http
    nodePort: 30306
  selector:
    name: mysql-pod

创建rc

apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql-rc
  labels:
    name: mysql-rc
spec:
  replicas: 1
  selector:
    name: mysql-pod
  template:
    metadata:
      labels: 
        name: mysql-pod
    spec:
      containers:
      - args:
          - --lower_case_table_names=1
          - --character-set-server=utf8mb4
          - --collation-server=utf8mb4_unicode_ci
          - --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
      - name: mysql
        image: mysql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "QWERT!@#$%"
        - name: TZ
          value: "Asia/Shanghai"
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐