Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes/Minikube:装入卷后,pod装入目录为空_Kubernetes_Minikube_Kubernetes Pod - Fatal编程技术网

Kubernetes/Minikube:装入卷后,pod装入目录为空

Kubernetes/Minikube:装入卷后,pod装入目录为空,kubernetes,minikube,kubernetes-pod,Kubernetes,Minikube,Kubernetes Pod,我是k8s的新手。下面我将使用minikube在k8s中设置Nginx pod,装载一个卷并提供index.html 当我挂载并转到hompe页面时,我收到这个错误 目录索引“/usr/share/nginx/html/”被禁止 如果我没有挂载任何东西,我会收到一个“欢迎使用Nginx”页面 这是装载前该文件夹的内容。坐骑空了之后 root@00c1:/usr/share/nginx/html# ls -l total 8 -rw-r--r-- 1 root root 494 Jul 23 11

我是k8s的新手。下面我将使用minikube在k8s中设置Nginx pod,装载一个卷并提供index.html

当我挂载并转到hompe页面时,我收到这个错误
目录索引“/usr/share/nginx/html/”被禁止

如果我没有挂载任何东西,我会收到一个“欢迎使用Nginx”页面

这是装载前该文件夹的内容。坐骑空了之后

root@00c1:/usr/share/nginx/html# ls -l
total 8
-rw-r--r-- 1 root root 494 Jul 23 11:45 50x.html
-rw-r--r-- 1 root root 612 Jul 23 11:45 index.html

为什么吊舱内的挂载文件夹在挂载后是空的

这是我的设置

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/my_username/test/html"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Mi
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-hello-rc
spec:
  replicas: 2
  selector:
    app: hello-nginx-tester
  template:
    metadata:
      labels:
        app: hello-nginx-tester
    spec:
      securityContext:
        fsGroup: 1000
      volumes:
        - name: task-pv-storage
          persistentVolumeClaim:
            claimName: task-pv-claim
      containers:
        - name: task-pv-container
          image: nginx
          ports:
            - containerPort: 80
              name: "http-server"
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: task-pv-storage
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-tester
  labels:
    app: hello-nginx-tester
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30500
    protocol: TCP
  selector:
    app: hello-nginx-tester

任何信息将不胜感激。谢谢

目录“/usr/share/nginx/html”的所有者将是1000,因为您已经设置了SecurityContext fsGroup值。因此,您无法访问该目录。如果删除SecurityContext部分,则已装入卷的所有者将设置为root。您将不会遇到访问问题。

我已在运行的k8s环境中检查了您的配置。经过一些调整后,以下清单对我来说运行顺利:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Mi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/my_username/test/html"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Mi
  volumeName: task-pv-volume
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-hello-rc
spec:
  replicas: 2
  selector:
    app: hello-nginx-tester
  template:
    metadata:
      labels:
        app: hello-nginx-tester
    spec:
      securityContext:
        fsGroup: 1000
      volumes:
        - name: task-pv-volume
          persistentVolumeClaim:
            claimName: task-pv-claim
      containers:
        - name: task-pv-container
          image: nginx
          ports:
            - containerPort: 80
              name: "http-server"
          volumeMounts:
            - mountPath: "/usr/share/nginx/html"
              name: task-pv-volume
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-tester
  labels:
    app: hello-nginx-tester
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30500
    protocol: TCP
  selector:
    app: hello-nginx-tester

并不是说,删除了指令,重新生成minicube只是为了确保它仍然是一样的。如果我不挂载任何东西,它将正常工作,如果我把文件夹变成空的,我尝试了这段代码,但仍然收到相同的错误。你在用minikube吗?我搜索了它,之所以收到此错误,是因为我需要先将卷装载到minikube,然后再将这些卷转移到k8s。我将在以后发布解决方案。我已通过
kubeadm
进行了检查。您更改了什么?