k8s资源之pv&pvc&sc

网友投稿 350 2022-09-08

k8s资源之pv&pvc&sc

​​istio多集群探秘,部署了50次多集群后我得出的结论​​

​​istio多集群链路追踪,附实操视频​​

​​istio防故障利器,你知道几个,istio新手不要读,太难!​​

​​istio业务权限控制,原来可以这么玩​​

​​istio实现非侵入压缩,微服务之间如何实现压缩​​

​​不懂envoyfilter也敢说精通istio系列-filter-再也不用再代码里写csrf逻辑了​​

​​不懂envoyfilter也敢说精通istio系列filter​​

​​不懂envoyfilter也敢说精通istio系列-network filter-redis proxy​​

​​不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager​​

​​不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册​​

————————————————

storage:

pv pvc sc之间的关系

pv:

•PV全称叫做Persistent Volume,持久化存储卷。它是用来描述或者说用来定义一个存储卷的,这个通常都是有运维或者数据存储工程师来定义。

Volume类型:

•Kubernetes提供了众多的volume类型,包括emptyDir、hostPath、gcePersistentDisk、awsElasticBlockStore、gitRepo、secret、nfs、iscsi、glusterfs、persistentVolumeClaim、rbd、flexVolume、cinder、cephfs、flocker、downwardAPI、fc、azureFile、configMap、vsphereVolume等

pv类型:

accessModes:

accessModes:支持三种类型

•ReadWriteMany 多路读写,卷能被集群多个节点挂载并读写

•ReadWriteOnce 单路读写,卷只能被单一集群节点挂载读写

•ReadOnlyMany 多路只读,卷能被多个集群节点挂载且只能读

persistentVolumeReclaimPolicy:

也有三种策略,这个策略是当与之关联的PVC被删除以后,这个PV中的数据如何被处理

•Retain 当删除与之绑定的PVC时候,这个PV被标记为released(PVC与PV解绑但还没有执行回收策略)且之前的数据依然保存在该PV上,但是该PV不可用,需要手动来处理这些数据并删除该PV。

•Delete 当删除与之绑定的PVC时候

•Recycle 这个在1.14版本中以及被废弃,取而代之的是推荐使用动态存储供给策略,它的功能是当删除与该PV关联的PVC时,自动删除该PV中的所有数据

pvc:

Pv&pvc绑定:

这个PVC就会和上面的PV进行绑定,为什么呢?它有一些原则:

•PV和PVC中的spec关键字段要匹配,比如存储(storage)大小。

•PV和PVC中的storageClassName字段必须一致

•1.当pv的容量大于pvc的需求时,pvc可以成功自动绑定pv;

•2.当pv的容量小于pvc的需求时,pvc无法绑定该pv;

•3.pv和pvc的绑定关系是一一对应的.

•4.pv/pvc的创建顺序是:pv -> pvc -> pod

•5.pv/pvc的销毁顺序是:pod -> pvc -> pv,顺序一定不要错

storageClass:

Kubernetes集群管理员通过提供不同的存储类,可以满足用户不同的服务质量级别、备份策略和任意策略要求的存储需求。动态存储卷供应使用StorageClass进行实现,其允许存储卷按需被创建。如果没有动态存储供应,Kubernetes集群的管理员将不得不通过手工的方式类创建新的存储卷。通过动态存储卷,Kubernetes将能够按照用户的需要,自动创建其需要的存储。

emptyDir:

•emptyDir类型的volume在pod分配到node上时被创建,kubernetes会在node上自动分配 一个目录,因此无需指定宿主机node上对应的目录文件。这个目录的初始内容为空,当Pod从node上移除时,emptyDir中的数据会被永久删除。

•emptyDir Volume主要用于某些应用程序无需永久保存的临时目录,多个容器的共享目录等。

apiVersion: v1kind: Podmetadata: name: emptydir-pvspec: containers: - name: tomcat image: tomcat:9 imagePullPolicy: IfNotPresent ports: - containerPort: 8080 volumeMounts: - name: app-logs mountPath: /usr/local/tomcat/logs - name: busybox image: busybox:latest imagePullPolicy: IfNotPresent command: ["sh", "-c", "tail -f /logs/catalina*.log"] volumeMounts: - name: app-logs mountPath: /logs volumes: - name: app-logs emptyDir: {}

hostPath:

apiVersion: v1kind: Podmetadata: name: mypodspec: containers: - image: nginx name: mynginx volumeMounts: - mountPath: /usr/share/nginx/html name: html volumes: - name: html hostPath: path: /data type: DirectoryOrCreate

Type:

configmap:

apiVersion: v1data: myapp.conf: | server { listen 8080; server_name myapp.test; location / { root /usr/share/nginx/html; index index.html index.htm; } }kind: ConfigMapmetadata: name: nginx-config---apiVersion: v1kind: Podmetadata: name: nginx labels: app: myapp tier: frontendspec: containers: - name: myapp image: nginx ports: - name: containerPort: 80 volumeMounts: - name: nginxconf mountPath: /etc/nginx/conf.d/ readOnly: true volumes: - name: nginxconf configMap: name: nginx-config

cecret:

apiVersion: v1kind: Podmetadata: name: secret-pvspec: containers: - name: test-container image: nginx volumeMounts: - name: secret-volume mountPath: /etc/secret-volume volumes: - name: secret-volume secret: secretName: test-secret

local:

kind: StorageClassapiVersion: storage.k8s.io/v1metadata: name: local-storageprovisioner: kubernetes.io/no-provisionervolumeBindingMode: WaitForFirstConsumer---apiVersion: v1kind: PersistentVolumemetadata: name: example-pv labels: pv: mypvspec: capacity: storage: 2Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /data/vol1 nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - 192.168.198.155---kind: PersistentVolumeClaimapiVersion: v1metadata: name: my-pvcspec: accessModes: - ReadWriteOnce storageClassName: local-storage resources: requests: storage: 1Gi# selector:# matchLabels:# pv: mypv---apiVersion: v1kind: Podmetadata: name: local-pvspec: containers: - name: test-container image: nginx volumeMounts: - name: local-volume mountPath: /usr/share/nginx/html volumes: - name: local-volume persistentVolumeClaim: claimName: my-pvc

nfs:

yum -y install rpcbind nfs-utilsvim /etc/exports/nfs 192.168.198.0/24(rw,no_root_squash,no_all_squash,sync)exportfs -rvsystemctl start rpcbind systemctl start nfs mount -t nfs 192.168.198.156:/nfs /mntChmod 755 /usr/share/nginx/htmlapiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv001 labels: name: nfs-pv001 storetype: nfsspec: storageClassName: normal accessModes: - ReadWriteMany - ReadWriteOnce - ReadOnlyMany capacity: storage: 500Mi persistentVolumeReclaimPolicy: Retain nfs: path: /nfs server: 192.168.198.156---kind: PersistentVolumeClaimapiVersion: v1metadata: name: nfs-pvcspec: accessModes: - ReadWriteOnce storageClassName: normal resources: requests: storage: 100Mi---apiVersion: v1kind: Podmetadata: name: nfs-pvspec: containers: - name: test-container image: nginx volumeMounts: - name: nfs-volume mountPath: /usr/share/nginx/html volumes: - name: nfs-volume persistentVolumeClaim: claimName: nfs-pvc

subPath:

apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv001 labels: name: nfs-pv001 storetype: nfsspec: storageClassName: normal accessModes: - ReadWriteMany - ReadWriteOnce - ReadOnlyMany capacity: storage: 500Mi persistentVolumeReclaimPolicy: Retain nfs: path: /nfs server: 192.168.198.156---kind: PersistentVolumeClaimapiVersion: v1metadata: name: nfs-pvcspec: accessModes: - ReadWriteOnce storageClassName: normal resources: requests: storage: 100Mi---apiVersion: v1kind: Podmetadata: name: nfs-pvspec: containers: - name: test-container image: nginx volumeMounts: - name: nfs-volume subPath: test mountPath: /usr/share/nginx/html volumes: - name: nfs-volume persistentVolumeClaim: claimName: nfs-pvc

Sc provisioner:

•​​Storage Classes | Kubernetes​​

allowVolumeExpansion:

•是否允许调整大小

gcePersistentDisk

awsElasticBlockStore

Cinder

glusterfs

rbd

Azure File

Azure Disk

Portworx

FlexVolumes

CSI

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:kubernetes资源之daemonset和ingress
下一篇:PR人:【6000字干货】如何提升小红书内容“获量”能力!
相关文章

 发表评论

暂时没有评论,来抢沙发吧~