首页 > 解决方案 > 如何识别 PVC 中剩余的存储空间?

问题描述

我有一个 PVC 请求为 10Gi 的 pod,并成功绑定到 PV(以下两个定义)

我遇到了类似问题的公认答案,它建议运行kubectl -n <namespace> exec <pod-name> df 在做同样的事情后,我得到了以下结果 -

pavan@p1: kubectl exec mysql-deployment-95f7dd544-mmjv9 df
Filesystem     1K-blocks    Used Available Use% Mounted on
overlay         51572172 5797112  43640736  12% /
tmpfs              65536       0     65536   0% /dev
tmpfs            1021680       0   1021680   0% /sys/fs/cgroup
/dev/vda1       51572172 5797112  43640736  12% /etc/hosts
shm                65536       0     65536   0% /dev/shm
tmpfs            1021680      12   1021668   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs            1021680       0   1021680   0% /proc/acpi
tmpfs            1021680       0   1021680   0% /sys/firmware
pavan@p1: kubectl exec mysql-deployment-95f7dd544-mmjv9 -- df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          50G  5.6G   42G  12% /
tmpfs            64M     0   64M   0% /dev
tmpfs           998M     0  998M   0% /sys/fs/cgroup
/dev/vda1        50G  5.6G   42G  12% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs           998M   12K  998M   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs           998M     0  998M   0% /proc/acpi
tmpfs           998M     0  998M   0% /sys/firmware

我不太了解 o/p,我要求 10Gi,但我没有看到任何总容量为 10gi 的挂载?

光伏定义:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/mysql"

PVC定义:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

部署定义:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: mysql-pod
  template:
    metadata:
      labels:
        app: mysql-pod
    spec:
      containers:
      - name: mysql-container
        image: mysql:5.7
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim

ps:节点容量50G

编辑1:

光伏描述:

pavan@p1: kubectl describe pv/mysql-pv-volume
Name:            mysql-pv-volume
Labels:          type=local
Annotations:     kubectl.kubernetes.io/last-applied-configuration:
                   {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"type":"local"},"name":"mysql-pv-volume"},"spec":{"acc...
                 pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    manual
Status:          Bound
Claim:           default/mysql-pv-claim
Reclaim Policy:  Retain
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   <none>
Message:         
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /mnt/mysql
    HostPathType:  
Events:            <none>

PVC描述:

pavan@p1: kubectl describe pvc/mysql-pv-claim
Name:          mysql-pv-claim
Namespace:     default
StorageClass:  manual
Status:        Bound
Volume:        mysql-pv-volume
Labels:        <none>
Annotations:   kubectl.kubernetes.io/last-applied-configuration:
                 {"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"mysql-pv-claim","namespace":"default"},"spec":{"acc...
               pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      10Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Mounted By:    mysql-deployment-95f7dd544-mmjv9
Events:        <none>

豆荚描述:

pavan@p1: kubectl describe pod/mysql-deployment-95f7dd544-mmjv9
Name:           mysql-deployment-95f7dd544-mmjv9
Namespace:      default
Priority:       0
Node:           pay0k-k8-dev-bytq/10.130.219.196
Start Time:     Mon, 09 Sep 2019 18:14:17 +0800
Labels:         app=mysql-pod
                pod-template-hash=95f7dd544
Annotations:    <none>
Status:         Running
IP:             10.244.0.123
Controlled By:  ReplicaSet/mysql-deployment-95f7dd544
Containers:
  mysql-container:
    Container ID:   docker://83f4730892fd6908ef3dfae3b9125d25cb7467d24df89323c43d3ab136376147
    Image:          mysql:5.7
    Image ID:       docker-pullable://mysql@sha256:1a121f2e7590f949b9ede7809395f209dd9910e331e8372e6682ba4bebcc020b
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 09 Sep 2019 18:14:19 +0800
    Ready:          True
    Restart Count:  0
    Environment:
      MYSQL_DATABASE:       <set to the key 'mysql-database' of config map 'mysqldb'>          Optional: false
      MYSQL_ROOT_PASSWORD:  <set to the key 'mysql-root-password' in secret 'db-credentials'>  Optional: false
      MYSQL_USER:           <set to the key 'mysql-user' in secret 'db-credentials'>           Optional: false
      MYSQL_PASSWORD:       <set to the key 'mysql-password' in secret 'db-credentials'>       Optional: false
    Mounts:
      /var/lib/mysql from mysql-persistent-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-gbpxc (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  mysql-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-claim
    ReadOnly:   false
  default-token-gbpxc:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-gbpxc
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From                        Message
  ----    ------     ----  ----                        -------
  Normal  Scheduled  41m   default-scheduler           Successfully assigned default/mysql-deployment-95f7dd544-mmjv9 to pay0k-k8-dev-bytq
  Normal  Pulled     41m   kubelet, pay0k-k8-dev-bytq  Container image "mysql:5.7" already present on machine
  Normal  Created    41m   kubelet, pay0k-k8-dev-bytq  Created container mysql-container
  Normal  Started    41m   kubelet, pay0k-k8-dev-bytq  Started container mysql-container

标签: kubernetesdigital-ocean

解决方案


In your PV definition your specify hostPath, so your data is stored directly on worker - this is why you see 50GB and you are skipping this additional layer provided by cloud provider which create pv directly from pvc.

Keeping data directly on a node isn't good approach because node could be removed/replaced at any time.

You should use digital ocean pvs instead of you're manually defined, if you spin new pod on digital ocean's pv output from df should show 10GB.


推荐阅读