当前位置:网站首页>k8s--部署单机版MySQL,并持久化
k8s--部署单机版MySQL,并持久化
2022-06-23 13:53:00 【IT艺术家-rookie】
写在前面
这次部署使用到了pv,pvc,deployment,service四种资源对象。
pv使用的是local类型的,localStorage应该是默认的。
PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv1
namespace: test-for-test
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain # 手动删除
storageClassName: local-storage #表明这个pv所属的storageClass
local:
path: /k8sVolume/mysqlVolume/mypv1 #节点上卷的完整路径。(必须是存在的路径,不然容器无法创建,deployment会报错)可以是目录或块设备(磁盘、分区…)。
nodeAffinity: #节点亲和性配置,限制从哪些节点上可以访问此卷
required:
nodeSelectorTerms: #数组类型
- matchExpressions: #数组类型
- key: kubernetes.io/hostname #字符串类型。被标签选择器应用的label key
operator: In #字符串类型。表示键与一组值的关系。有效的操作符有In, NotIn, Exists, DoesNotExist。Gt, Lt。
values: #一个字符串数组,如果操作符为In或NotIn,则values数组必须非空。如果操作符是Exists或DoesNotExist, values数组必须为空。如果操作符为Gt或Lt,则values数组必须只有一个元素,该元素将被解释为整数。
- roy-ubuntu #所在节点的主机名
pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvclocal
namespace: test-for-test
spec:
accessModes: #访问模式 申领在请求具有特定访问模式的存储时,使用与卷相同的访问模式约定。
- ReadWriteMany
volumeMode: Filesystem #卷模式
resources:
requests:
storage: 4Gi
storageClassName: local-storage # 此处须显式设置空字符串或指定值,否则会被设置为默认的 StorageClass
deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment #指定deployment的名字
namespace: test-for-test
labels:
app: mysql-labels-app
spec: #规约
replicas: 3 #pod的副本数量,就是希望创建多少个pod的副本.可选字段。它的默认值是1。
selector: #selector 字段定义 Deployment 如何查找要管理的 Pods。必须匹配 .spec.template.metadata.labels,否则请求会被 API 拒绝。
matchLabels:
app: mysql-pod
template: #Deployment Pod 模板;它和 Pod 的语法规则完全相同。 只是这里它是嵌套的,因此不需要 apiVersion 或 kind。
metadata:
labels:
app: mysql-pod
spec: #pod模板规约
containers: #容器
- name: mysql #容器的名称
image: mysql:5.7 #容器使用的镜像
ports:
- containerPort: 3306
volumeMounts:
- name: mypv1 #pv的name
mountPath: /var/lib/mysqlMount#容器内对应的路径,这里这个路径不对,应该是/var/lib/mysql。MySQL的数据都在这个里面,需要持久化的也就是这个路径下的内容
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
volumes:
- name: mypv1#pv的name
persistentVolumeClaim:
claimName: mypvclocal
restartPolicy: Always #Deployment 中的 Pod 模板必须指定适当的标签和适当的重新启动策略。只有 .spec.template.spec.restartPolicy 等于 Always 才是被允许的,这也是在没有指定时的默认设置
service
apiVersion: v1
kind: Service
metadata:
name: mysql-service
namespace: test-for-test
spec:
ports:
- port: 3306
nodePort: 30060
selector:
app: mysql-pod # 该 Service 会将所有具有标签 app: mysql-labels-app暴露到一个抽象的 Service 端口上(targetPort:容器接收流量的端口;port:可任意取值的抽象的 Service 端口,其他 Pod 通过该端口访问 Service
type: NodePort
使用可视化工具连接MySQL

主机地址就是节点的地址
进入容器
kubectl exec -it pod的name -c 在deployment文件指定了的容器name -n test-for-test – bash
[email protected]:/k8sVolume/mysqlVolume/mypv1# kubectl exec -it mysql-deployment-59f68f87cd-d4bt8 -c mysql -n test-for-test -- bash
[email protected]:/# ls
bin boot dev docker-entrypoint-initdb.d entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
边栏推荐
- How to merge tables when exporting excel tables with xlsx
- The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine
- Cause analysis and intelligent solution of information system row lock waiting
- How to install the DTS component of SQL server2008r2 on win10 64 bit systems?
- What does it mean for AI developers after 2022
- Edge and IOT academic resources
- 微信小程序之从底部弹出可选菜单
- Error 1079 when starting a service: the account of this service is different from that of other services running on the same process
- [compréhension approfondie de la technologie tcaplusdb] données de construction tcaplusdb
- Xmake v2.6.8 release, compilation cache improvement
猜你喜欢
![[in depth understanding of tcapulusdb technology] tcapulusdb construction data](/img/0c/33d9387cd7733a0c6706a73f9535f7.png)
[in depth understanding of tcapulusdb technology] tcapulusdb construction data

Oracle进入sqlplus 报错

Binding events of wechat applet in wx:for

ICML 2022 𞓜 context integrated transformer based auction design neural network

用OBS做直播推流简易教程

KS007基于JSP实现人个人博客系统

ICML 2022 | 上下文集成的基于transformer的拍卖设计神经网络

微信小程序之从底部弹出可选菜单

Low grain prices hurt farmers, low wages hurt farmers!

Error when Oracle enters sqlplus
随机推荐
系统设计与分析-技术报告-定时清理验证码的一种解决方案
今年英语高考,CMU用重构预训练交出134高分,大幅超越GPT3
2021-04-15
一款自动生成单元测试的 IDEA 插件
Use xtradiagram Diagramcontrol for drawing and controlling process graphics
Technology sharing | do you understand the requirements of the tested project?
等保備案是什麼意思?應該去哪裏辦理備案?
Ks007 realizes personal blog system based on JSP
【深入理解TcaplusDB技术】Tmonitor系统升级
KDD'22「阿里」推荐系统中的通用序列表征学习
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
Flex attribute of wechat applet
Common methods and descriptions of beanstalk
Wechat applet pop up the optional menu from the bottom
How to merge tables when exporting excel tables with xlsx
SAP inventory gain / loss movement type 701 & 702 vs 711 & 712
Test article
[deeply understand tcapulusdb technology] tmonitor background one click installation
图解OneFlow的学习率调整策略
分布式数据库使用逻辑卷管理存储之扩容