1.创建PV/PVC
略
2.创建MySQL配置文件
kind: ConfigMap apiVersion: v1 metadata: name: mysql-config namespace: ops-share 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 [client] socket=/var/run/mysqld/mysqld.sock !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
3.创建MySQL deploy文件
apiVersion: apps/v1 kind: Deployment metadata: name: t1-mysql namespace: ops-share spec: selector: matchLabels: app: mysql-5.7 template: metadata: labels: app: mysql-5.7 spec: containers: - name: mysql image: mysql:5.7.42 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/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-mysql-svc name: t1-mysql-svc namespace: ops-share spec: ports: - name: tcp-mysql-3306 nodePort: 30117 port: 3306 protocol: TCP targetPort: 3306 selector: app: mysql-5.7 type: NodePort
MySQL访问
内部:t1-mysql-svc.ops-share.svc.cluster.local:3306 外部:SLB转发到节点30117端口,根据实际情况进行访问
标签:name,单机,MySQL,3306,mysqld,mysql,var,k8s From: https://www.cnblogs.com/panwenbin-logs/p/17414389.html