k8s快速部署MySQL单机

1.创建PV/PVC

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-data
  namespace: t1-zdbl
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 30G

2.创建MySQL配置文件

kind: ConfigMap
apiVersion: v1
metadata:
  name: mysql-config
  namespace: t1-zdbl
data:
  my.cnf: |-
    [mysqld]

    skip-host-cache
    skip-name-resolve
    datadir=/var/lib/mysql
    socket=/var/run/mysqld/mysqld.sock
    secure-file-priv=/var/lib/mysql-files
    user=mysql
    symbolic-links=0
    pid-file=/var/run/mysqld/mysqld.pid
    default_authentication_plugin=mysql_native_password
    [client]
    socket=/var/run/mysqld/mysqld.sock

3.创建MySQL deploy文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: t1-zdbl-mysql
  namespace: t1-zdbl
spec:
  selector:
    matchLabels:
      app: mysql-8.0
  template:
    metadata:
      labels:
        app: mysql-8.0
    spec:
      containers:
      - name: mysql
        image: mysql:8.0
        env:                        
        - name: MYSQL_ROOT_PASSWORD
          value: "System@123"  #设置root登录密码
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: mysql-data
          mountPath: /var/lib/mysql         
          subPath: mysql
        - name: config
          mountPath:  /etc/mysql/conf.d/my.cnf
          subPath: my.cnf
      volumes:
      - name: mysql-data
        persistentVolumeClaim:
          claimName: mysql-data
      - name: config
        configMap:
          name: mysql-config

4.MySQL svc文件

apiVersion: v1
kind: Service
metadata:
  labels:
    app: t1-zdbl-mysql
  name: t1-zdbl-mysql
  namespace: t1-zdbl
spec:
  ports:
  - name: tcp-mysql-3306
    nodePort: 30306
    port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    app: mysql-8.0
  type: NodePort

MySQL访问

内部:t1-zdbl-mysql.t1-zdbl.svc.cluster.local:3306 
外部:SLB转发到节点30306端口,根据实际情况进行访问

 

posted @ 2023-05-19 11:22  百衲本  阅读(392)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码