欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > K8S部署MySQL

K8S部署MySQL

2024/11/30 14:49:10 来源:https://blog.csdn.net/weimeilayer/article/details/139586665  浏览:    关键词:K8S部署MySQL

创建mysql-deployment.yaml
先拉取镜像

docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
apiVersion: apps/v1
kind: Deployment
metadata:name: mysql-deployment
spec:replicas: 1selector:matchLabels:app: mysqltemplate:metadata:labels:app: mysqlspec:containers:- name: mysqlimage: registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7ports:- containerPort: 3306  # MySQL 默认端口env:- name: MYSQL_ROOT_PASSWORDvalue: "123456"  # 设置 MySQL root 密码

创建mysql-service.yaml

apiVersion: v1
kind: Service
metadata:name: mysql-service
spec:selector:app: mysqlports:- port: 3306targetPort: 3306nodePort: 30306  # 这里指定暴露对外的NodePorttype: NodePort
kubectl apply -f mysql-deployment.yaml
kubectl apply -f mysql-service.yaml

查看

kubectl get pods --namespace default
kubectl get services --namespace default

然后进入容器
kubectl get pods -o wide -A
kubectl exec -it mysql-deployment-6674c97b46-hm64c /bin/bash

mysql -u root -p
输入密码,文字的yaml密码是123456
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
GRANT SELECT,DELETE,UPDATE,CREATE,DROP ON *.* to root@"%" IDENTIFIED BY "123456";
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost.localdomain' IDENTIFIED BY '123456' WITH GRANT OPTION;
别忘了加上如下的语句
flush privileges;

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com