setup kubernetes hostpath, but file don't show up in container

9/4/2017

I am new to kubernets (~ 3 days). I try to setup a hostpath to share file with pods, I followint his guide Configure a Pod to Use a PersistentVolume for Storage, after setup. I check the status of pv, pvc, pod, result are as following.

enter image description here

here are the config file for pv,pvc,pod.

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

PVC:

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

POD:

kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:

  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

can some give a clue ? any suggestion, command of how to debug this kind of issue is welcome.

-- scott huang
kubernetes

2 Answers

9/4/2017

did you put a local file in /tmp/data in the first place ?

-- Sebastien Goasguen
Source: StackOverflow

9/4/2017

I think I figure it out. HostPath is only suitable for a one-node cluster. my cluster have 2 nodes. so the physical storage the PV use is on another computer.

when I first go through the documentation, I don't pay attention this:

"You need to have a Kubernetes cluster that has only one Node"

-- scott huang
Source: StackOverflow