概述
版本:v1.18.0
本地共享类型:emptyDir,hostpath
网络共享类型:nfs,pv、pvc卷
其他:ConfigMap,Secret
一、emptyDir示例:
apiVersion: v1
kind: Pod
metadata:
name: testemp
labels:
app: testemp
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: myweb
mountPath: /usr/share/nginx/html
resources:
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 300m
memory: 128Mi
volumes:
- name: myweb
emptyDir: {}
二、hostPath示例:
apiVersion: v1
kind: Pod
metadata:
name: testhost
labels:
app: testhost
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: myweb
mountPath: /usr/share/nginx/html
resources:
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 300m
memory: 128Mi
volumes:
- name: myweb
hostPath:
path: /tmp/myweb
type: Directory
三、nfs示例:
apiVersion: v1
kind: Pod
metadata:
name: testnfs
labels:
app: testnfs
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: myweb
mountPath: /usr/share/nginx/html
resources:
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 300m
memory: 128Mi
volumes:
- name: myweb
nfs:
server: 192.168.199.120
path: /data
四、利用网络共享存储创建pv卷,手动创建pvc卷应用于挂载
pv卷创建
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
nfs:
path: /mypv/pv0001
server: 192.168.199.120
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0002
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
nfs:
path: /mypv/pv0002
server: 192.168.199.120
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 8Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
nfs:
path: /mypv/pv0003
server: 192.168.199.120
pvc卷创建
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: fornginx
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 4Gi
storageClassName: slow
pod应用pvc卷
apiVersion: v1
kind: Pod
metadata:
name: testpvc
labels:
app: testpvc
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: myweb
mountPath: /usr/share/nginx/html
resources:
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 300m
memory: 128Mi
volumes:
- name: myweb
persistentVolumeClaim:
claimName: fornginx
五、安装nfs-client插件,实现创建pv后,自动创建pvc。
github上下载 nfs-client 插件,里面饱含了三个文件,一个是rbac,一个是deploy,一个是class,分别是授权,部署nfs-client的pod和定义class的。
直接创建pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: autopvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 8Gi
storageClassName: "managed-nfs-storage"
直接创建应用pod,使用该pvc
apiVersion: v1
kind: Pod
metadata:
name: testautopvc
labels:
app: testautopvc
spec:
restartPolicy: Always
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: myweb
mountPath: /usr/share/nginx/html
resources:
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 300m
memory: 128Mi
volumes:
- name: myweb
persistentVolumeClaim:
claimName: autopvc
最后
以上就是花痴中心为你收集整理的Kubernetes本地共享,网络共享,pv,pvc卷挂载示例的全部内容,希望文章能够帮你解决Kubernetes本地共享,网络共享,pv,pvc卷挂载示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复