使用Kubernetes集群环境部署MySQL数据库的实战记录
更新时间:2022年05月27日 11:33:01 作者:Redrose2100
这篇文章主要介绍了使用Kubernetes集群环境部署MySQL数据库,主要包括编写 mysql.yaml文件,执行如下命令创建,通过相关命令查看创建结果,对Kubernetes部署MySQL数据库的过程感兴趣的朋友一起看看吧
1 编写 mysql.yaml文件
编写yaml如下
apiVersion: v1
kind: Namespace
metadata:
name: devops # Namespace 的名称
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: devops-mysql # deployment控制器名称
namespace: devops
spec:
replicas: 1
revisionHistoryLimit: 5
strategy:
type: RollingUpdate
selector:
matchLabels:
app: devops-mysql
template:
metadata:
labels:
app: devops-mysql
spec:
volumes:
- name: devops-mysql
nfs:
server: xx.xx.xx.xx # 修改为挂载存储的服务器ip
path: /root/data/nfs/mysql/devops # 修改为存储服务器的存储挂载路径
containers:
- name: devops-mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
value: xxxxxxxx # 设置MySQL数据库登录密码
imagePullPolicy: Always
ports:
- containerPort: 3306
volumeMounts:
- name: devops-mysql
mountPath: /var/lib/mysql
---
apiVersion: v1
kind: Service
metadata:
name: devops-mysql # 数据库服务的名称
namespace: devops
spec:
ports:
- port: 3306
protocol: TCP
targetPort: 3306
nodePort: 30001 # 对外访问的端口
selector:
app: devops-mysql
type: NodePort
sessionAffinity: ClientIP 2 执行如下命令创建
kubectl apply -f mysql.yaml
3 通过如下命令查看创建结果
使用如下命令查看
kubectl get pod -n devops | grep mysql
如:
[root@master ~]# kubectl get pod -n devops | grep mysql devops-mysql-59b68c47d4-ttbng 1/1 Running 0 23h [root@master ~]#
4 命令行进入Pod并登录mysql
如下;
[root@master ~]# kubectl exec -it devops-mysql-59b68c47d4-ttbng bash -n devops kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead. root@devops-mysql-59b68c47d4-ttbng:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.01 sec) mysql>
5 至此,数据库已经安装完成,然后即可通过ip+端口,这里是30001,进行数据库链接了
到此这篇关于使用Kubernetes集群环境部署MySQL数据库的文章就介绍到这了,更多相关Kubernetes部署MySQL内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
CentOS下编写shell脚本来监控MySQL主从复制的教程
这篇文章主要介绍了在CentOS系统下编写shell脚本来监控主从复制的教程,文中举了两个发现故障后再次执行复制命令的例子,需要的朋友可以参考下2015-12-12
mybatis-plus分页传入参数后sql where条件没有limit分页信息操作
这篇文章主要介绍了mybatis-plus分页传入参数后sql where条件没有limit分页信息操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-11-11
MySQL提示:The server quit without updating
今天网站web页面提交内容到数据库,发现出错了,一直提交不了,数找了下原因,发现数据写不进去!第一反应,重启mysql数据库,一直执行中,停止不了也启动不了,直觉告诉我磁盘满了 !2014-04-04
Mysql报错too many connections的原因及解决方案
这篇文章主要给大家介绍了关于Mysql报错too many connections原因及解决方案,文中通过实例代码以及图文介绍的非常详细,需要的朋友可以参考下2023-09-09
MySQL中REPLACE INTO和INSERT INTO的区别分析
REPLACE的运行与INSERT很相似。只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有相同的值,则在新记录被插入之前,旧记录被删除。2011-07-07


最新评论