kubernetes redis pod failure when mounted with a GKE persistent volume

6/6/2019

I have the following redis.yaml file in which I create a GKE persistent volume and try to mount it in a redis stateful set. But, the pod never comes up and it stays in Pending state forever. Any help ?

redis.yaml

apiVersion: v1
kind: Service
metadata:
  name: my-redis
spec:
  ports:
    - port: 6379
      name: my-redis
  type: LoadBalancer
  selector:
    app: my-redis
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: my-storage-class
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-redis-volume-claim
spec:
  storageClassName: my-storage-class
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
  name: my-redis
spec:
  selector:
    matchLabels:
      app: my-redis # has to match .spec.template.metadata.labels
  serviceName: my-redis
  replicas: 1
  template:
    metadata:
      labels:
        app: my-redis # has to match .spec.selector.matchLabels
    spec:
      nodeSelector:
        node-name: default
      containers:
        - name: redis
          image: redis:3.2-alpine
          args:
            [
              "--requirepass",
              "$(REDIS_PASS)",
              "--appendonly",
              "yes",
              "--save",
              "30",
              "1",
            ]
          ports:
            - containerPort: 6379
              name: redis
          env:
            - name: REDIS_PASS
              value: password
          volumeMounts:
            - name: my-redis-volume
              mountPath: /data
      volumes:
        - name: my-redis-volume
          persistentVolumeClaim:
            claimName: my-redis-volume-claim

The pod remains in Pending state even after 10s of minutes. I think I am missing something in the volume creation but not able to figure out what it is.

➜ kubectl apply -f redis.yaml 
service/my-redis created
storageclass.storage.k8s.io/my-storage-class created
persistentvolumeclaim/my-redis-volume-claim created
statefulset.apps/my-redis created

kubectl get pv  
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                           STORAGECLASS       REASON   AGE
pvc-bc439c93-881a-11e9-9958-42010a800034   10Gi       RWO            Delete           Bound    default/my-redis-volume-claim   my-storage-class            14s

kubectl get statefulsets
NAME       DESIRED   CURRENT   AGE
my-redis   1         1         31s

kubectl get pods        
NAME         READY   STATUS    RESTARTS   AGE
my-redis-0   0/1     Pending   0          36s 
-- Sankar
google-kubernetes-engine
kubernetes
persistent-storage
redis

0 Answers