【发布时间】:2021-10-25 04:56:02
【问题描述】:
我在 Kubernetes 上创建了一个 pod 并挂载了一个本地卷,但是当我尝试在本地挂载的卷上执行 ls 命令时,我收到一个权限被拒绝的错误。如果我禁用 SELINUX,那么一切正常。我无法弄清楚如何让它在启用 SELinux 的情况下工作。
下面是permission denied的输出:
kubectl apply -f testpod.yaml
root@olcne-operator-ol8 opc]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/testpod 1/1 Running 0 5s
# kubectl exec -i -t testpod /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
[root@testpod /]# cd /u01
[root@testpod u01]# ls
ls: cannot open directory '.': Permission denied
[root@testpod u01]#
下面是testpod.yaml
cat testpod.yaml
kind: Pod
apiVersion: v1
metadata:
name: testpod
labels:
name: testpod
spec:
hostname: testpod
restartPolicy: Never
volumes:
- name: swvol
hostPath:
path: /u01
containers:
- name: testpod
image: oraclelinux:8
imagePullPolicy: Always
securityContext:
privileged: false
command: [/usr/sbin/init]
volumeMounts:
- mountPath: "/u01"
name: swvol
工作节点上的 Selinux 配置:
# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31
---
# semanage fcontext -l | grep kub | grep container_file
/var/lib/kubelet/pods(/.*)? all files system_u:object_r:container_file_t:s0
/var/lib/kubernetes/pods(/.*)? all files system_u:object_r:container_file_t:s0
机器操作系统详情
rpm -qa | grep kube
kubectl-1.20.6-2.el8.x86_64
kubernetes-cni-0.8.1-1.el8.x86_64
kubeadm-1.20.6-2.el8.x86_64
kubelet-1.20.6-2.el8.x86_64
kubernetes-cni-plugins-0.9.1-1.el8.x86_64
----
cat /etc/oracle-release
Oracle Linux Server release 8.4
---
uname -r
5.4.17-2102.203.6.el8uek.x86_64
【问题讨论】:
-
你好@drifter 请在stackoverflow上查看相同问题的答案。
-
嗨,它对我有用,感谢您分享信息。
标签: kubernetes