目录
一.设备条件介绍
二.我的目的
三.问题所在
1.在用以下pod进行测试的时候出现问题
2.报错
3.解决
4.解决完成
一.设备条件介绍
[root@k8s-master pv]# containerd --version
containerd containerd.io 1.6.25 d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
[root@k8s-master pv]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"28", GitVersion:"v1.28.2", GitCommit:"89a4ea3e1e4ddd7f7572286090359983e0387b2f", GitTreeState:"clean", BuildDate:"2023-09-13T09:34:32Z", GoVersion:"go1.20.8", Compiler:"gc", Platform:"linux/amd64"}
二.我的目的
1.创建pv、nfs,再创建pvc,并且通过pvc和nfs去存储pod产生的信息(以nginx的访问日志为例的)。在myns命名空间里创建好了my-pv1、my-pv2,并且创建好了my-pvc1、my-pvc2,都绑定好了。
[root@k8s-master pv]# cat /etc/exports
/root/pv/pv1 192.168.2.0/24(rw,no_root_squash)
/root/pv/pv2 192.168.2.0/24(rw,no_root_squash)[root@k8s-master pv]# kubectl get pv,pvc -n myns
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/my-pv1 1G RWX Retain Bound myns/my-pvc1 4m22s
persistentvolume/my-pv2 1G RWX Retain Bound myns/my-pvc2 4m22s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/my-pvc1 Bound my-pv1 1G RWX 4m14s
persistentvolumeclaim/my-pvc2 Bound my-pv2 1G RWX 4m14s
2.这是我的pv,pvc文件
[root@k8s-master pv]# cat pv.yaml
apiVersion: v1
kind: Namespace
metadata:name: myns---apiVersion: v1
kind: PersistentVolume
metadata:name: my-pv1namespace: myns
spec:capacity:storage: 1GaccessModes:- ReadWriteManypersistentVolumeReclaimPolicy: Retainnfs:path: /root/pv/pv1server: 192.168.2.150---apiVersion: v1
kind: PersistentVolume
metadata:name: my-pv2namespace: myns
spec:capacity: storage: 1GaccessModes:- ReadWriteManypersistentVolumeReclaimPolicy: Retainnfs:path: /root/pv/pv2server: 192.168.2.150
这些内容能绑定应该都是正确的
[root@k8s-master pv]# cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: my-pvc1namespace: myns
spec:accessModes:- ReadWriteManyresources:requests:storage: 500M---apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: my-pvc2namespace: myns
spec:accessModes:- ReadWriteManyresources:requests:storage: 600M
三.问题所在
1.在用以下pod进行测试的时候出现问题
[root@k8s-master pv]# cat pod.yaml
apiVersion: v1
kind: Pod
metadata: name: my-pod1namespace: myns
spec:containers:- name: my-nginx1image: nginxports:- name: nginx-port1containerPort: 80volumeMounts:- name: my-volumemountPath: /var/log/nginx- name: my-busybox1image: busyboxcommand: ["/bin/sh","-c","tail -f /access.log"]volumeMounts:- name: my-volumemountPath: /volumes:- name: my-volumepersistentVolumeClaim:claimName: my-pvc1---apiVersion: v1
kind: Pod
metadata:name: my-pod2namespace: myns
spec:containers:- name: my-nginx2image: nginxports:- name: nginx-port2containerPort: 80volumeMounts:- name: my-volumemountPath: /var/log/nginx- name: my-busybox2image: busyboxcommand: ["/bin/sh","-c","tail -f /access.log"]volumeMounts:- name: my-volumemountPath: /volumes:- name: my-volumepersistentVolumeClaim:claimName: my-pvc2
2.报错
Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error closing exec fds: open /proc/self/fd: no such file or directory: unknown
[root@k8s-master pv]# kubectl describe pod my-pod1 -n myns
Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error closing exec fds: open /proc/self/fd: no such file or directory: unknown
3.解决
将上文pod的yaml中mountPath改来尽量不使用“/”
原因:在 BusyBox 容器中使用 /
作为 volume 的 mountPath
通常会失败,因为该路径本身不存在。如果你想要在 BusyBox 容器中使用 volume,可以考虑使用非根目录作为 mountPath
,比如 /root
、/mnt
等等,这些目录一般存在于 BusyBox 的文件系统结构中,可以正常使用。所以在精简的镜像中尽量不要使用“/”作为挂载目录。
[root@k8s-master pv]# cat pod.yaml
apiVersion: v1
kind: Pod
metadata: name: my-pod1namespace: myns
spec:containers:- name: my-nginx1image: nginxports:- name: nginx-port1containerPort: 80volumeMounts:- name: my-volumemountPath: /var/log/nginx- name: my-busybox1image: busyboxcommand: ["/bin/sh","-c","tail -f /logs/access.log"]volumeMounts:- name: my-volumemountPath: /logsvolumes:- name: my-volumepersistentVolumeClaim:claimName: my-pvc1---apiVersion: v1
kind: Pod
metadata:name: my-pod2namespace: myns
spec:containers:- name: my-nginx2image: nginxports:- name: nginx-port2containerPort: 80volumeMounts:- name: my-volumemountPath: /var/log/nginx- name: my-busybox2image: busyboxcommand: ["/bin/sh","-c","tail -f /logs/access.log"]volumeMounts:- name: my-volumemountPath: /logsvolumes:- name: my-volumepersistentVolumeClaim:claimName: my-pvc2
4.解决完成
[root@k8s-master pv]# kubectl apply -f pod.yaml
pod/my-pod1 created
pod/my-pod2 created
[root@k8s-master pv]# kubectl get pods -n myns
NAME READY STATUS RESTARTS AGE
my-pod1 2/2 Running 0 8s
my-pod2 2/2 Running 0 8s[root@k8s-master pv]# kubectl get pv,pvc,pod -n myns -o wide
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE VOLUMEMODE
persistentvolume/my-pv1 1G RWX Retain Bound myns/my-pvc1 40m Filesystem
persistentvolume/my-pv2 1G RWX Retain Bound myns/my-pvc2 40m FilesystemNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE
persistentvolumeclaim/my-pvc1 Bound my-pv1 1G RWX 40m Filesystem
persistentvolumeclaim/my-pvc2 Bound my-pv2 1G RWX 40m FilesystemNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/my-pod1 2/2 Running 0 4m12s 10.244.107.197 k8s-node3 <none> <none>
pod/my-pod2 2/2 Running 0 4m12s 10.244.36.69 k8s-node1 <none> <none>