k8s资源之pv&pvc&sc

 欢迎关注我的公众号:

k8s资源之pv&pvc&sc_第1张图片

 目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:

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

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

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

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

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

不懂envoyfilter也敢说精通istio系列-http-rbac-不要只会用AuthorizationPolicy配置权限

不懂envoyfilter也敢说精通istio系列-02-http-corsFilter-不要只会vs

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

不懂envoyfilter也敢说精通istio系列http-jwt_authn-不要只会RequestAuthorization

不懂envoyfilter也敢说精通istio系列-05-fault-filter-故障注入不止是vs

不懂envoyfilter也敢说精通istio系列-06-http-match-配置路由不只是vs

不懂envoyfilter也敢说精通istio系列-07-负载均衡配置不止是dr

不懂envoyfilter也敢说精通istio系列-08-连接池和断路器

不懂envoyfilter也敢说精通istio系列-09-http-route filter

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

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

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

 

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

storage:

k8s资源之pv&pvc&sc_第2张图片

pv pvc sc之间的关系

k8s资源之pv&pvc&sc_第3张图片

pv:

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

Volume类型:

Kubernetes提供了众多的volume类型,包括emptyDirhostPathgcePersistentDiskawsElasticBlockStoregitReposecretnfsiscsiglusterfspersistentVolumeClaimrbdflexVolumecindercephfsflockerdownwardAPIfcazureFileconfigMapvsphereVolume

pv类型:

k8s资源之pv&pvc&sc_第4张图片

accessModes:

accessModes:支持三种类型

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

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

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

persistentVolumeReclaimPolicy:

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

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

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

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

pvc:

PVC 的全称是:PersistentVolumeClaim(持久化卷声明),PVC 是用户存储的一种声明,PVC Pod 比较类似,Pod 消耗的是节点,PVC 消耗的是 PV 资源,Pod 可以请求 CPU 和内存,而 PVC 可以请求特定的存储空间和访问模式。对于真正使用存储的用户不需要关心底层的存储实现细节,只需要直接使用 PVC 即可

Pv&pvc绑定:

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

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

PVPVC中的storageClassName字段必须一致

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

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

3.pvpvc的绑定关系是一一对应的.

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

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

storageClass:

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

emptyDir:

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

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

apiVersion: v1
kind: Pod
metadata:
  name: emptydir-pv
spec:
  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: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - image: nginx
    name: mynginx
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: html
  volumes:
  - name: html
    hostPath:
      path: /data
      type: DirectoryOrCreate

Type:

k8s资源之pv&pvc&sc_第5张图片

configmap:

apiVersion: v1
data:
  myapp.conf: |
   server {
    listen       8080;
    server_name  myapp.test;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
   }
kind: ConfigMap
metadata:
  name: nginx-config
---

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: myapp
    tier: frontend
spec:
  containers:
  - name: myapp
    image: nginx
    ports: 
    - name: http
      containerPort: 80
    volumeMounts:
    - name: nginxconf
      mountPath: /etc/nginx/conf.d/
      readOnly: true
  volumes:
  - name: nginxconf
    configMap:
      name: nginx-config

cecret:

apiVersion: v1
kind: Pod
metadata:
  name: secret-pv
spec:
  containers:
  - name: test-container
    image: nginx
    volumeMounts:
    - name: secret-volume
      mountPath: /etc/secret-volume
  volumes:
  - name: secret-volume
    secret:
      secretName: test-secret

local:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: example-pv
  labels:
    pv: mypv
spec:
  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: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce 
  storageClassName: local-storage
  resources:
    requests:
      storage: 1Gi
#  selector:
#    matchLabels:
#      pv: mypv

---
apiVersion: v1
kind: Pod
metadata:
  name: local-pv
spec:
  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-utils
vim /etc/exports
/nfs 192.168.198.0/24(rw,no_root_squash,no_all_squash,sync)
exportfs  -rv
systemctl start rpcbind systemctl start nfs 
mount  -t nfs 192.168.198.156:/nfs /mnt
Chmod 755 /usr/share/nginx/html

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv001
  labels:
    name: nfs-pv001
    storetype: nfs
spec:
  storageClassName: normal
  accessModes:
    - ReadWriteMany
    - ReadWriteOnce
    - ReadOnlyMany
  capacity:
    storage: 500Mi
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /nfs
    server: 192.168.198.156
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteOnce 
  storageClassName: normal
  resources:
    requests:
      storage: 100Mi
---
apiVersion: v1
kind: Pod
metadata:
  name: nfs-pv
spec:
  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: v1
kind: PersistentVolume
metadata:
  name: nfs-pv001
  labels:
    name: nfs-pv001
    storetype: nfs
spec:
  storageClassName: normal
  accessModes:
    - ReadWriteMany
    - ReadWriteOnce
    - ReadOnlyMany
  capacity:
    storage: 500Mi
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /nfs
    server: 192.168.198.156
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteOnce 
  storageClassName: normal
  resources:
    requests:
      storage: 100Mi
---
apiVersion: v1
kind: Pod
metadata:
  name: nfs-pv
spec:
  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

你可能感兴趣的:(kubernetes,运维)