在K8S集群部署MySQL服务
1.推送镜像到本地仓库
先在harbor 上建一个项目 参考: 连接
docker pull mysql:5.7 # 网速快线上拉取即可,网速慢使用我给的镜像使用"docker load -i"导入即可。
docker tag mysql:5.7 harbor.baimei.com/baimei-db/mysql:5.7
docker push harbor.baimei.com/baimei-db/mysql:5.7
docker pull wordpress # 网速快线上拉取即可,网速慢使用我给的镜像使用"docker load -i"导入即可。
docker tag wordpress harbor.baimei.com/baimei-wordpress/wordpress
docker push harbor.baimei.com/baimei-wordpress/wordpress
2.编写资源清单
[root@master231 pod]# cat 03-pods-wordpress.yaml
apiVersion: v1
kind: Pod
metadata:
name: baimei-wp
spec:
containers:
- name: db
image: harbor.baimei.com/baimei-db/mysql:5.7
# 向容器传递环境变量
env:
# 变量的名称
- name: MYSQL_ALLOW_EMPTY_PASSWORD
# 指定变量的值
value: "yes"
- name: MYSQL_DATABASE
value: "wordpress"
- name: MYSQL_USER
value: "admin"
- name: MYSQL_PASSWORD
value: "baimei"
3.创建资源
kubectl apply -f 03-pods-wordpress.yaml
4.查看资源
kubectl get pods
5.验证Pod
kubectl exec -it baimei-wp -- mysql
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
mysql>
mysql> SELECT user,host FROM mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| admin | % |
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
5 rows in set (0.00 sec)