files stored on PV persistent storage by pod application are not visible on host machine [GKE]

9/18/2019

files stored on PV persistent storage by pod application are not visible on host machine. Configuration shows no errors. Config - single pv, pvc, pod. I am quite new to this environment.

pv:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: notowania-pv
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi #Size of the volume
  accessModes:
    - ReadWriteOnce #type of access
  hostPath:
    path: "/home/user1684/dane" #host location

pv status:

NAME           CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                  STORAGECLASS   REASON   AGE
notowania-pv   10Gi       RWO            Retain           Bound    default/notowania-pv   manual                  22m

pvc:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: notowania-pv
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

pvc status:

NAME           STATUS   VOLUME         CAPACITY   ACCESS MODES   STORAGECLASS   AGE
notowania-pv   Bound    notowania-pv   10Gi       RWO            manual         24m

pod:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  name: "notowania"
  namespace: "default"
  labels:
    app: "notowania"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "notowania"
  template:
    metadata:
      labels:
        app: "notowania"
    spec:
      containers:
      - name: "selenium-docker-sha256"
        image: "eu.gcr.io/firstapp-249912/selenium_docker@sha256:da15e666c3472e93979d821c912c2855951e579a91238f35f0e339b85343ed6b"
        volumeMounts:
        - name: notowania
          mountPath: /notowania
      volumes:
      - name: notowania 
        persistentVolumeClaim:
          claimName: notowania-pv

pod status:

NAME                         READY   STATUS    RESTARTS   AGE
notowania-79d68c8c56-79q55   1/1     Running   0          25m

files on pod:

user1684@cloudshell:~ (firstapp-249912)$ kubectl exec -it  notowania-79d68c8c56-79q55 -- /bin/bash
root@notowania-79d68c8c56-79q55:/usr/src/app# ll /notowania/
total 8
drwxr-xr-x 2 root root 4096 Sep 18 12:54 ./
drwxr-xr-x 1 root root 4096 Sep 18 12:51 ../
-rw-r--r-- 1 root root    0 Sep 18 12:54 aaa

files on host:

user1684@cloudshell:~ (firstapp-249912)$ pwd
/home/user1684
user1684@cloudshell:~ (firstapp-249912)$ ll dane
total 8
drwxr-xr-x  2 user1684 user1684 4096 Sep 17 23:13 ./
drwxr-xr-x 15 user1684 user1684 4096 Sep 18 14:47 ../

So I have no idea why aaa is not visible on the host machine in google cloud - as I think 'aaa' file should be here.

-- Wojtas.Zet
google-kubernetes-engine
kubernetes

1 Answer

9/18/2019

I think the issue is caused by on what host you examine the directory contents.

  • You've executed the last command on the "cloudshell" VM which is only meant for interacting with GCP and is not a cluster node.
  • And you should rather inspect it on a cluster node.
  • To inspect the state of the cluster node you should do something like this:
gcloud compute instances list 
NAME                                     ZONE            MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
gke-tt-test1-default-pool-a4cf7d86-rgt2  europe-west3-a  g1-small                   10.156.0.2   1.2.3.4  RUNNING

gcloud compute ssh gke-tt-test1-default-pool-a4cf7d86-rgt2 

user@gke-tt-test1-default-pool-a4cf7d86-rgt2 ~ $ ls -la /home/user1684/dane
total 8
drwxr-xr-x 2 root root 4096 Sep 18 14:16 .
drwxr-xr-x 3 root root 4096 Sep 18 14:12 ..
-rw-r--r-- 1 root root    0 Sep 18 14:16 aaa
-- Tomasz Tarczynski
Source: StackOverflow