当前位置: 首页 > news >正文

kubernetes deploy standalone mysql demo

kubernetes 集群内部署 单节点 mysql

ansible all -m shell -a "mkdir -p /mnt/mysql/data"

cat mysql-pv-pvc.yaml

apiVersion: v1
kind: PersistentVolume
metadata:name: mysql-pv-volumelabels:type: local
spec:storageClassName: manualcapacity:storage: 5GiaccessModes:- ReadWriteOncehostPath:path: "/mnt/mysql/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: mysql-pv-claim
spec:storageClassName: manualaccessModes:- ReadWriteOnceresources:requests:storage: 5Gi

cat mysql-deploy.yaml

apiVersion: v1
kind: Service
metadata:name: mysql
spec:type: NodePortports:- port: 3306nodePort: 30006targetPort: 3306protocol: TCPselector:app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:name: mysql
spec:selector:matchLabels:app: mysqlstrategy:type: Recreatetemplate:metadata:labels:app: mysqlspec:containers:- image: mysql:5.7name: mysqlenv:# Use secret in real usage- name: MYSQL_ROOT_PASSWORDvalue: passwordports:- containerPort: 3306name: mysqlvolumeMounts:- name: mysql-persistent-storagemountPath: /var/lib/mysqlvolumes:- name: mysql-persistent-storagepersistentVolumeClaim:claimName: mysql-pv-claim

start:

kubectl apply -f mysql-pv-pvc.yaml
kubectl apply -f mysql-deploy.yaml

check

[root@kube-master01 mysql]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
mysql-794c6d56c6-xnfhb   1/1     Running   0          10h
[root@kube-master01 mysql]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.43.0.1      <none>        443/TCP          23d
mysql        NodePort    10.43.17.172   <none>        3306:30006/TCP   10h
mysql        NodePort    10.43.17.172   <none>        3306:30006/TCP   10h
[root@kube-master01 mysql]# mysql -h 192.168.23.31 -P 30006 -u root -p'password'
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 15
Server version: 5.7.43 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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 |
| clusterpedia       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.05 sec)mysql>

参考:

  • Run a Single-Instance Stateful Application
http://www.lryc.cn/news/148001.html

相关文章:

  • 【Map】Map集合有序与无序测试案例:HashMap,TreeMap,LinkedHashMap(121)
  • TiDB Serverless Branching:通过数据库分支简化应用开发流程
  • 运用亚马逊云科技Amazon Kendra,快速部署企业智能搜索应用
  • C# 使用 OleDbConnection 连接读取Excel的方法
  • 【LeetCode-中等题】98. 验证二叉搜索树
  • Leetcode-每日一题【剑指 Offer 37. 序列化二叉树】
  • 删除无点击数据offer数据分析使用
  • 【Apollo学习笔记】——规划模块TASK之SPEED_BOUNDS_PRIORI_DECIDER
  • 物理机ping不通windows server 2012
  • 誉天HCIE-Datacom丨为什么选择誉天数通HCIE课程学习
  • Python文本终端GUI框架详解
  • 01_lwip_raw_udp_test
  • 学习ts(十一)本地存储与发布订阅模式
  • MySQL对NULL值处理
  • Vector 动态数组(迭代器)
  • 多组背包恰好装满方案数
  • Oracle查询语句中做日期加减运算
  • Unity贝塞尔曲线的落地应用-驱动飞行特效
  • VTK——设置交互样式上的鼠标回调函数
  • Flutter实现动画列表AnimateListView
  • 【LeetCode-中等题】236. 二叉树的最近公共祖先
  • 如何拼接两个视频在一起?
  • Programming abstractions in C阅读笔记:p130-p131
  • 如何在Windows本地快速搭建SFTP文件服务器,并通过端口映射实现公网远程访问
  • C#---第二十:不同类型方法的执行顺序(new / virtual / common / override)
  • lnmp架构-PHP
  • 【javascript实操记录】
  • Mysql--技术文档--悲观锁、乐观锁-《控制并发机制简单认知、深度理解》
  • 【GO】LGTM_Grafana_Tempo(2)_官方用例改后实操
  • git 口令