当前位置:网站首页>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
边栏推荐
- Is flush a stock? Is it safe to open an account online now?
- 如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
- 首个大众可用PyTorch版AlphaFold2复现,哥大开源OpenFold,star量破千
- Tinder security cooperates with Intel vPro platform to build a new pattern of software and hardware collaborative security
- 去 OPPO 面试, 被问麻了。。。
- 【深入理解TcaplusDB技术】 Tmonitor模块架构
- AI talk | data imbalance refinement instance segmentation
- Use xtradiagram Diagramcontrol for drawing and controlling process graphics
- KDD'22「阿里」推荐系统中的通用序列表征学习
- How to ensure long-term stable operation of EDI system
猜你喜欢

vulnhub靶机Os-hackNos-1

如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版

In this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3

DTU上报的数据值无法通过腾讯云规则引擎填入腾讯云数据库中

The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine

连续2年夺冠!Zabbix在2022年多款监控软件排名第一

【深入理解TcaplusDB技术】Tmonitor系统升级

ICML 2022 𞓜 context integrated transformer based auction design neural network

Edge and IOT academic resources
![[Level 2 warranty] which brand of Fortress machine is good for Level 2 warranty?](/img/84/4fa07c54786aaf423ca333ecde62f4.png)
[Level 2 warranty] which brand of Fortress machine is good for Level 2 warranty?
随机推荐
Win the championship for 2 consecutive years! ZABBIX ranked first in a number of monitoring software in 2022
同花顺是股票用的么?现在网上开户安全么?
Ks007 realizes personal blog system based on JSP
Google Earth engine (GEE) -- Comparative Case Analysis of calculating slope with different methods
White paper - Intel and Ashling, a well-known risc-v tool provider, strive to expand multi platform risc-v support
What is the working status of software testing with a monthly salary of 7500
Acquisition of wechat applet JSON for PHP background database transformation
[deeply understand tcapulusdb technology] table management of document acceptance
vulnhub靶机Os-hackNos-1
【深入理解TcaplusDB技术】TcaplusDB构造数据
When pandas met SQL, a powerful tool library was born
ICML 2022 𞓜 context integrated transformer based auction design neural network
Edge and IOT academic resources
Thinking and Practice on Quality Standardization (suitable for product, development, testing and management post learning)
KS003基于JSP和Servlet实现的商城系统
Common methods and descriptions of beanstalk
Tinder security cooperates with Intel vPro platform to build a new pattern of software and hardware collaborative security
Ks003 mall system based on JSP and Servlet
Tencent cloud tdsql-c heavy upgrade, leading the cloud native database market in terms of performance
分布式数据库使用逻辑卷管理存储之扩容