tee mysqldb.yaml <<-'EOF'
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql-sz
  namespace: ops
  labels:
    app: mysqlsz
spec:
  selector:
    matchLabels:
      app: mysqlsz
  serviceName: mysqlsz
  replicas: 1
  template:
    metadata:
      labels:
        app: mysqlsz
    spec:
      containers:
      - name: mysqlsz
        image: mysql:5.7.37
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysqlsz
              key: password
        ports:
        - name: mysqlsz
          containerPort: 3306
        volumeMounts:
        - name: timezone
          mountPath: /etc/localtime     
        - name: data
          mountPath: /var/lib/mysql
          subPath: mysql
        - name: config-map
          mountPath: /etc/mysql/conf.d
        resources:
          requests:
            cpu: 600m
            memory: 1Gi
          limits:
            cpu: 4000m
            memory: 4Gi
      volumes:
      - name: config-map
        configMap:
          name: mysqlsz
      - name: timezone
        hostPath: 
          path: /usr/share/zoneinfo/Asia/Shanghai 
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
      - "ReadWriteOnce"
      storageClassName: mynfs
      resources:
        requests:
          storage: 30Gi

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysqlsz
  namespace: ops
  labels:
    app: mysqlsz
data:
  sql.cnf: |
    [mysqld]
    max_connections=1033

---
apiVersion: v1
kind: Secret
metadata:
  name: mysqlsz
  namespace: ops
  labels:
    app: mysqlsz
type: Opaque
data:
  password: YWRtaW5zMTIzCg==
EOF
tee dbs-server.yaml <<-'EOF'
apiVersion: v1
kind: Service
metadata:
  name: mysqlsz
  namespace: test01
  labels:
    app: mysqlsz
spec:
  ports:
  - name: mysqlsz
    port: 3306
  clusterIP: None
  selector:
    app: mysqlsz
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-sz-svc
  namespace: test01
  labels:
    app: mysqlsz
spec:
  type: NodePort
  ports:
  - name: mysqlsz
    port: 3306
    nodePort: 33307
  selector:
    app: mysqlsz
EOF

跳过密码登录my.conf添加

skip-grant-tables

密码修改

update mysql.user set authentication_string=password("admins123") where user="root";
flush privileges;
Logo

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

更多推荐