二进制部署k8s集群v1.23.9版本-18-安装MySQL8.0.30

18.1、准备镜像

192.168.1.200操作
docker pull mysql:8.0.30
docker images|grep mysql
docker tag ff3b5098b416 harbor.qgutech.com/middleware/mysql:v8.0.30
docker push harbor.qgutech.com/middleware/mysql:v8.0.30

18.2、准备资源配置清单

192.168.1.200操作

mkdir -p /data/k8s-yaml/mysql/
cd /data/k8s-yaml/mysql/
vim dp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: middleware
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
nodeName: hfqg1-201.host.com
containers:
- name: mysql
image: harbor.qgutech.com/middleware/mysql:v8.0.30
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
value: qgutech123!@#
- name: MYSQL_USER
value: qixiao
- name: MYSQL_PASSWORD
value: qixiao123!@#
ports:
- containerPort: 3306
hostPort: 60808
protocol: TCP
name: http
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
- name: mysql-conf
mountPath: /etc/mysql/mysql.conf.d
imagePullSecrets:
- name: harbor
volumes:
- nfs:
server: hfqg1-200
path: /data/nfs-volume/mysql/conf
name: mysql-conf
- nfs:
server: hfqg1-200
path: /data/nfs-volume/mysql/data
name: mysql-data

vim svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: middleware
spec:
ports:
- name: http
port: 60808
targetPort: 3306
protocol: TCP
selector:
app: mysql

18.3、创建名称空间

192.168.1.201操作
名称空间在上一篇文章中已经创建过了,此处不再重复创建,只将命令贴出来
kubectl create ns middleware
kubectl create secret docker-registry harbor --docker-server=harbor.qgutech.com --docker-username=admin --docker-password=1qaz2wsx#EDC -n middleware

18.3、创建存储路径

192.168.1.200操作
mkdir -p /data/nfs-volume/mysql/data/

18.4、应用资源配置清单

192.168.1.201操作
kubectl apply -f http://k8s-yaml.qgutech.com/mysql/dp.yaml
kubectl apply -f http://k8s-yaml.qgutech.com/mysql/svc.yaml
kubectl get pods -n middleware

宿主机监听端口,可以工具访问MySQL
netstat -lntp|grep 60808

至此,MySQL安装完成,感谢观看。

posted @ 2022-09-07 13:56  霸都运维  阅读(159)  评论(0编辑  收藏  举报