这篇文章主要讲解了“如何使用Kubernetes集群环境部署MySQL数据库”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何使用Kubernetes集群环境部署MySQL数据库”吧!
编写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
kubectl apply -f mysql.yaml
使用如下命令查看
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 ~]#
如下;
[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>
感谢各位的阅读,以上就是“如何使用Kubernetes集群环境部署MySQL数据库”的内容了,经过本文的学习后,相信大家对如何使用Kubernetes集群环境部署MySQL数据库这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。