kubernetes 搭建单节点mysql服务
参考链接:https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/
一、创建service
apiVersion: v1 kind: Service metadata: name: mysql labels: app: mysql namespace: admin-d2069c spec: ports: - name: mysql port: 3306 clusterIP: None selector: app: mysql
二、创建StatefulSet
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: mysql namespace: admin-d2069c spec: serviceName: mysql replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql namespace: admin-d2069c spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "123" ports: - name: mysql containerPort: 3306 volumeMounts: - name: lihaile mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: requests: cpu: 300m memory: 200M livenessProbe: exec: command: ["mysqladmin", "-h", "127.0.0.1", "-uroot", "-p123", "ping"] initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: exec: # Check we can execute queries over TCP (skip-networking is off). command: ["mysql", "-h", "127.0.0.1", "-uroot", "-p123", "-e", "SELECT 1"] initialDelaySeconds: 5 periodSeconds: 2 timeoutSeconds: 1 volumes: - name: conf emptyDir: {} - name: config-map configMap: name: mysql volumeClaimTemplates: - metadata: name: lihaile annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" namespace: admin-d2069c spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 2Gi
三、创建访问Service
apiVersion: v1 kind: Service metadata: name: mysql-access labels: app: mysql namespace: admin-d2069c spec: ports: - name: mysql port: 3306 selector: app: mysql
查看Mysql
root@node4:~# kubectl -n admin-d2069c get pvc,pv,statefulset,pod,service |grep mysql pvc/storage-mysql-0 Bound pvc-a6c63604-c2ee-11e8-b599-0050568eef9f 512M RWX managed-nfs-storage 18s pv/pvc-a6c63604-c2ee-11e8-b599-0050568eef9f 512M RWX Delete Bound admin-d2069c/storage-mysql-0 managed-nfs-storage 18s statefulsets/mysql 1 1 18s po/mysql-0 1/1 Running 0 18s svc/mysql ClusterIP None <none> 3306/TCP 18s svc/mysql-access ClusterIP 10.68.31.80 <none> 3306/TCP 18s ing/mysql-access jekens.com 80 18s
五、测试
1、查看集群详情和状态
root@node4:~# mysql -h 10.68.31.80 -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 124 Server version: 5.7.23 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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 | +--------------------+ 4 rows in set (0.00 sec) mysql>

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
MICROSOFT IGNITE 2018 大会成功举办,Docker 现场揭秘全新版本内容!
出品丨Docker公司(ID:docker-cn)编译丨小东每周一、三、五晚6点10分 与您不见不散! 9月24日,在佛罗里达州奥兰多举行的 Microsoft Ignite 大会上 Docker 向大家展示了最新版本的 Docker Enterprise。会上,我们分享了关于如何将遗留的 Windows 应用程序从 Windows Server 2003/2008 迁移到 Windows Server 2016 和 Azure 的见解。 欢迎来到 Docker#644 号展位,了解更多有关我们如何帮助 IT 组织了解Docker Enterprise 工具的信息,这些工具可帮助您识别以及将遗留的 Windows 应用程序进行容器化改造。我们将有专业的技术专家来为您答疑。 一定要关注关于 Docker 的会议: 从 Ops 到 DevOps,使用 Windows 容器和 Windows Server 2019。我们特别强调了一位联合 Docker Microsoft 的客户 Lindsay,她已经将 Windows 的遗留应用程序迁移到Azure 上。您可以在这里获得关于会话的更多细节...
- 下一篇
kubernetes搭建mysql集群服务
参考链接:https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/ 一、创建ConfigMap apiVersion: v1 kind: ConfigMap metadata: name: mysql labels: app: mysql data: master.cnf: | # Apply this config only on the master. [mysqld] log-bin slave.cnf: | # Apply this config only on slaves. [mysqld] super-read-only 在pod初始化时, pod会根据自身标识(master或slave)从configmap中应用指定配置. 被应用配置将覆盖my.cnf中的配置. 目的是使master向slave提供复制日志服务,并设置slave拒绝非复制写入. 二、创建headless service # Headless service for stable DNS en...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker安装Oracle12C,快速搭建Oracle学习环境
- CentOS7,8上快速安装Gitea,搭建Git服务器
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- 2048小游戏-低调大师作品
- Docker快速安装Oracle11G,搭建oracle11g学习环境