当前位置:网站首页>K8s-- deploy stand-alone MySQL and persist it
K8s-- deploy stand-alone MySQL and persist it
2022-06-23 14:42:00 【It artist rookie】
Write it at the front
This deployment uses pv,pvc,deployment,service Four resource objects .
pv It uses local Type of ,localStorage It should be the default .
PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv1
namespace: test-for-test
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain # Delete manually
storageClassName: local-storage # Indicates that the pv Of storageClass
local:
path: /k8sVolume/mysqlVolume/mypv1 # The full path of the volume on the node .( Must be an existing path , Otherwise, the container cannot be created ,deployment Will report a mistake ) It can be a directory or a block device ( disk 、 Partition …).
nodeAffinity: # Node affinity configuration , Restrict which nodes can access this volume from
required:
nodeSelectorTerms: # An array type
- matchExpressions: # An array type
- key: kubernetes.io/hostname # String type . Applied by the tag selector label key
operator: In # String type . Represents the relationship between a key and a set of values . The effective operators are In, NotIn, Exists, DoesNotExist.Gt, Lt.
values: # An array of strings , If the operator is In or NotIn, be values Array must be non empty . If the operator is Exists or DoesNotExist, values Array must be empty . If the operator is Gt or Lt, be values Array must have only one element , This element will be interpreted as an integer .
- roy-ubuntu # The host name of the node
pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvclocal
namespace: test-for-test
spec:
accessModes: # Access pattern Claim when requesting storage with a specific access mode , Use the same access mode Convention as the volume .
- ReadWriteMany
volumeMode: Filesystem # Volume mode
resources:
requests:
storage: 4Gi
storageClassName: local-storage # An empty string or a specified value must be explicitly set here , Otherwise, it will be set as the default StorageClass
deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment # Appoint deployment Name
namespace: test-for-test
labels:
app: mysql-labels-app
spec: # Statute
replicas: 3 #pod Number of copies of , Is how many you want to create pod Copy of . Optional fields . Its default value is 1.
selector: #selector Field definition Deployment How to find the Pods. Must match .spec.template.metadata.labels, Otherwise the request will be API Refuse .
matchLabels:
app: mysql-pod
template: #Deployment Pod Templates ; It and Pod The rules of grammar are exactly the same . It's just that it's nested here , So you don't need apiVersion or kind.
metadata:
labels:
app: mysql-pod
spec: #pod Template conventions
containers: # Containers
- name: mysql # Name of the container
image: mysql:5.7 # The image used by the container
ports:
- containerPort: 3306
volumeMounts:
- name: mypv1 #pv Of name
mountPath: /var/lib/mysqlMount# The corresponding path in the container , The path here is wrong , Should be /var/lib/mysql.MySQL All the data are in this , What needs to be persisted is the content under this path
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
volumes:
- name: mypv1#pv Of name
persistentVolumeClaim:
claimName: mypvclocal
restartPolicy: Always #Deployment Medium Pod The template must specify the appropriate label and the appropriate restart policy . Only .spec.template.spec.restartPolicy be equal to Always That's what's allowed , This is also the default setting when it is not specified
service
apiVersion: v1
kind: Service
metadata:
name: mysql-service
namespace: test-for-test
spec:
ports:
- port: 3306
nodePort: 30060
selector:
app: mysql-pod # The Service All with tags will be app: mysql-labels-app Exposed to an abstract Service On port (targetPort: The port on which the container receives traffic ;port: Abstract that can take any value Service port , other Pod Access... Through this port Service
type: NodePort
Connect... Using visualization tools MySQL

The host address is the address of the node
Into the container
kubectl exec -it pod Of name -c stay deployment File specifies the container for 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
边栏推荐
- 微信小程序之在wx:for中绑定事件
- Ks003 mall system based on JSP and Servlet
- Unity realizes the function of playing Ogg format video
- 一款自动生成单元测试的 IDEA 插件
- 【深入理解TcaplusDB技术】TcaplusDB构造数据
- Win10 64位系统如何安装SQL server2008r2的DTS组件?
- 物流贸易相关
- 2022 soft science university professional ranking released! Xi'an electric AI ranked higher than Qingbei, and Nantah ranked first in the country!
- Hot Recruitment! The second Tencent light · public welfare innovation challenge is waiting for you to participate
- 中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
猜你喜欢

5分钟快速上线Web应用和API(Vercel)

去 OPPO 面试, 被问麻了。。。

阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题

微信小程序之下拉菜单场景

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

As a software testing practitioner, do you understand your development direction?

建議自查!MySQL驅動Bug引發的事務不回滾問題,也許你正面臨該風險!

【深入理解TcaplusDB技术】一键安装Tmonitor后台

Helm 基础入门 Helm介绍与安装

巴比特 | 元宇宙每日必读:Meta、微软等科技巨头成立元宇宙标准论坛组织,华为、阿里加入,英伟达高管称欢迎来自加密世界的参与者...
随机推荐
Quick view of wechat applet development process
JSP_ SSM Wanfu cinema ticket sales management system, including paper [demonstration video]
Ks008 SSM based press release system
What do you mean by waiting for insurance records? Where should I go for filing?
[deeply understand tcapulusdb technology] table management of document acceptance
[digital signal processing] linear time invariant system LTI (judge whether a system is a "non time variant" system | case 2)
去 OPPO 面试, 被问麻了。。。
ICML 2022 | 上下文集成的基于transformer的拍卖设计神经网络
【二级等保】过二级等保用哪个堡垒机品牌好?
Add Icon before input of wechat applet
Common methods and descriptions of beanstalk
TS encapsulation request
The company has only one test, but the leader asked me to operate 1000 mobile numbers at the same time
【DataHub】LinkedIn DataHub学习笔记
2021-06-03
图解OneFlow的学习率调整策略
How to install the DTS component of SQL server2008r2 on win10 64 bit systems?
An idea plug-in for automatically generating unit tests
谷歌&HuggingFace| 零样本能力最强的语言模型结构
Test article