点击蓝色“DevOps架构实战”关注我哟
分享到“朋友圈”,每天上午 07:30,干货推送!
在nfs服务器和其它节点创建共享目录
[root@node2 ~]# docker pull mysql:8.0.22
[root@node1 ~]# docker pull mysql:8.0.22
创建PV
[root@master ~]# kubectl apply -f nfs-pv.yaml
persistentvolume/mysql created
创建pvc
[root@master ~]# kubectl apply -f nfs-pvc.yaml
persistentvolumeclaim/mysql created
创建mysql
[root@master ~]# more mysql.yaml
apiVersion: apps/v1
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:8.0.22
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: 1234
volumeMounts:
- name: mysql-storage
mountPath: var/lib/mysql
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
[root@master ~]# kubectl apply -f mysql.yaml
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mysql-6b8564f498-wd4m4 1/1 Running 0 44s
nginx-offi 1/1 Running 0 2d23h
创建测试数据
[root@master ~]# kubectl exec -it mysql-6b8564f498-wd4m4 -- mysql -uroot -p1234
mysql> create table student(
-> stu_id int auto_increment,
-> name char(29) not null,
-> age int not null,
-> register_date date,
-> primary key (stu_id)
-> );
Query OK, 0 rows affected (0.14 sec)
mysql> insert into student(name,age) values("sfqd",20);
Query OK, 1 row affected (0.01 sec)
mysql> select * from student;
+--------+------+-----+---------------+
| stu_id | name | age | register_date |
+--------+------+-----+---------------+
| 1 | sfqd | 20 | NULL |
+--------+------+-----+---------------+
1 row in set (0.00 sec)
在nfs服务器查看数据:
[root@bogon data]# ll
----------------------end---------------------
推荐阅读:
Kubernetes 部署无状态应用
shell脚本安装mysql8.0
K8s 弹性伸缩&升级回滚
Prometheus+Grafana的安装添加zabbix监控
生产环境仓库-Harbor
Prometheus+Grafana监控k8s集群
如有收获,点个在看,扫码关注,诚挚感谢