Pod has unbound PersistentVolumeClaims but volume claims is bounded

Yummel picture Yummel · Jun 26, 2018 · Viewed 18.6k times · Source

I want to create a statefulset elasticsearch in kubernetes on virtualbox. I'm not using cloud provider so i create two persistent volume localy for my two replicas of my statefulset :

pv0:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-elk-0
  namespace: elk
  labels:
    type: local
spec:
  storageClassName: gp2
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data/pv0"

pv1:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-elk-1
  namespace: elk
  labels:
    type: local
spec:
  storageClassName: gp2
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data/pv1"

Statefulset :

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: elasticsearch-logging
  namespace: elk
  labels:
    k8s-app: elasticsearch-logging
    version: v5.6.2
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  serviceName: elasticsearch-logging
  replicas: 2
  selector:
    matchLabels:
      k8s-app: elasticsearch-logging
      version: v5.6.2
  template:
    metadata:
      labels:
        k8s-app: elasticsearch-logging
        version: v5.6.2
        kubernetes.io/cluster-service: "true"
    spec:
      serviceAccountName: elasticsearch-logging
      containers:
      - image: gcr.io/google-containers/elasticsearch:v5.6.2
        name: elasticsearch-logging
        ports:
        - containerPort: 9200
          name: db
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        resources:
          limits:
            cpu: 0.1
        volumeMounts:
        - name: elasticsearch-logging
          mountPath: /data
        env:
        - name: "NAMESPACE"
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
      initContainers:
      - image: alpine:3.6
        command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
        name: elasticsearch-logging-init
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: elasticsearch-logging
    spec:
      accessModes: ["ReadWriteOnce"]
      storageClassName: gp2
      resources:
        requests:
          storage: 5Gi

It seems like the persistant volume is correctly bounced but the pod are always in crash loop and restart every time. It's it because of the use of the initContainer or something wrong with my yaml ?

Statefulset

pv,pvc

Answer

Yummel picture Yummel · Jun 28, 2018

Add more Ram, scale up the cluster.