简体   繁体   中英

Persistent volume Kubernetes on Google Cloud

I have a Redis pod on my Kubernetes cluster on Google Cloud. I have built PV and the claim.


   
kind: PersistentVolume
apiVersion: v1
metadata:
 name: redis-pv
 labels:
   type: local
spec:
 storageClassName: manual
 capacity:
   storage: my-size 
 accessModes:
   - ReadWriteOnce
 hostPath:
   path: "/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 labels:
   app: postgres
 name: redis-pv-claim
spec:
 storageClassName: manual
 accessModes:
 - ReadWriteOnce
 resources:
   requests:
     storage: my size 
I also mounted it in my deployment.yaml

volumeMounts:
     - mountPath: /data
       name: redis-pv-claim
   volumes:
   - name: redis-pv-claim
     persistentVolumeClaim:
       claimName: redis-pv-claim  

I can't see any error while running describe pod



Volumes:
 redis-pv-claim:
   Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
   ClaimName:  redis-pv-claim
   ReadOnly:   false

But it just can't save any key. After every deployment, the "/data" folder is just empty.

My NFS is active now but i still cant keep data.

Describe pvc


Namespace:     my namespace 
StorageClass:  nfs-client
Status:        Bound
Volume:        pvc-5d278b27-a51e-4262-8c1b-68b290b21fc3
Labels:        <none>
Annotations:   pv.kubernetes.io/bind-completed: yes
              pv.kubernetes.io/bound-by-controller: yes
              volume.beta.kubernetes.io/storage-class: nfs-client
              volume.beta.kubernetes.io/storage-provisioner: cluster.local/ext1-nfs-client-provisioner
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      1Gi
Access Modes:  RWX
VolumeMode:    Filesystem
Mounted By:    my grafana pod
Events:        <none>

Describe pod gives me an error though.


Warning  FailedMount  18m   kubelet, gke-devcluster-pool-1-36e6a393-rg7d  MountVolume.SetUp failed for volume "pvc-5d278b27-a51e-4262-8c1b-68b290b21fc3" : mount failed: exit status 1
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/8f7b6630-ed9b-427a-9ada-b75e1805ed60/volumes/kubernetes.io~nfs/pvc-5d278b27-a51e-4262-8c1b-68b290b21fc3 --scope -- /
home/kubernetes/containerized_mounter/mounter mount -t nfs 192.168.1.21:/mnt/nfs/development-test-claim-pvc-5d278b27-a51e-4262-8c1b-68b290b21fc3 /var/lib/kubelet/pods/8f7b6630-ed9b-427a-9ada-b75e1805ed60
/volumes/kubernetes.io~nfs/pvc-5d278b27-a51e-4262-8c1b-68b290b21fc3
Output: Running scope as unit: run-ra5925a8488ef436897bd44d526c57841.scope
Mount failed: mount failed: exit status 32
Mounting command: chroot

Working redis with PV and PVC on GKE

apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  type: LoadBalancer
  ports:
  - port: 6379
    name: redis
  selector:
    app: redis
---
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  name: redis
spec:
  selector:
    matchLabels:
      app: redis  
  serviceName: redis
  replicas: 1
  template:
    metadata:
      labels:
        app: redis 
    spec:
      containers:
        - name: redis
          image: redislabs/rejson
          args: ["--requirepass", "password", "--appendonly", "no", "--loadmodule", "/usr/lib/redis/modules/rejson.so"]
          ports:
            - containerPort: 6379
              name: redis
          resources:
            limits:
              cpu: .50
              memory: 1500Mi
            requests:
              cpu: .25
              memory: 1000Mi
          volumeMounts:
            - name: redis-volume
              mountPath: /data
  volumeClaimTemplates:
  - metadata:
      name: redis-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi

you can update image in this stateful sets as per need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM