如何识别 PVC 中剩余的存储 space?
How to identify the storage space left in a 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 的挂载?
PV定义:
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
P.s:节点容量为50G
编辑 1:
PV描述:
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
在您的 PV 定义中,您指定 hostPath
,因此您的数据直接存储在 worker 上 - 这就是为什么您看到 50GB 并且您正在跳过云提供商提供的这个附加层,它直接从 pvc 创建 pv。
将数据直接保存在节点上不是好方法,因为节点随时可能 removed/replaced。
您应该使用数字海洋 pv 而不是手动定义,如果您在数字海洋上旋转新 pod,df
的 pv 输出应该显示 10GB。
我有一个 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 的挂载?
PV定义:
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
P.s:节点容量为50G
编辑 1:
PV描述:
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
在您的 PV 定义中,您指定 hostPath
,因此您的数据直接存储在 worker 上 - 这就是为什么您看到 50GB 并且您正在跳过云提供商提供的这个附加层,它直接从 pvc 创建 pv。
将数据直接保存在节点上不是好方法,因为节点随时可能 removed/replaced。
您应该使用数字海洋 pv 而不是手动定义,如果您在数字海洋上旋转新 pod,df
的 pv 输出应该显示 10GB。