Kubernetes with helm on local persistent volume with docker for Windows

3/28/2019

I tried to use helm on docker for windows on the local machine. When I used a storage class as local storage, persistent volume, and persistent volume claim without helm, it works fine. But when I used this setting with helm, CrashLoopBackOff happened.

localStrageClass.yaml

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-pv002
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  #storageClassName: hostpath
  mountOptions:
    - hard
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    path: /c/k/share/mysql
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        #- key: docker.io/hostname
        - key: kubernetes.io/hostname
          operator: In
          values:
          - docker-desktop

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-mysql-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: local-storage

mysqlConf.yaml

persistence:
  enabled: true
  storageClass: local-storage
  existingClaim: local-mysql-claim
  accessMode: ReadWriteOnce
  size: 1Gi
  annotations: {}

$ helm install --name mysql stable/mysql -f mysqlConf.yaml
$ kubectl describe pod mysql

Containers:
  mysql:
    Container ID:   docker://533e4569603b05fac83a0a701da97898b3190503618796678ac5db6340c4dce6
    Image:          mysql:5.7.14
    Image ID:       docker-pullable://mysql@sha256:c8f03238ca1783d25af320877f063a36dbfce0daa56a7b4955e6c6e05ab5c70b
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Thu, 28 Mar 2019 13:24:25 +0900
      Finished:     Thu, 28 Mar 2019 13:24:25 +0900
    Ready:          False
    Restart Count:  2
    Requests:
      cpu:      100m
      memory:   256Mi
    Liveness:   exec [sh -c mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}] delay=30s timeout=5s period=10s #success=1 #failure=3
    Readiness:  exec [sh -c mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}] delay=5s timeout=1s period=10s #success=1 #failure=3

    Environment:
      MYSQL_ROOT_PASSWORD:  <set to the key 'mysql-root-password' in secret 'mysql'>  Optional: false
      MYSQL_PASSWORD:       <set to the key 'mysql-password' in secret 'mysql'>       Optional: true
      MYSQL_USER:
      MYSQL_DATABASE:
    Mounts:
      /var/lib/mysql from data (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-dccpv (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  data:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  local-mysql-claim
    ReadOnly:   false
  default-token-dccpv:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-dccpv
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From                     Message
  ----     ------     ----               ----                     -------
  Normal   Scheduled  39s                default-scheduler        Successfully assigned default/mysql-698897ff79-n768k to docker-desktop
  Normal   Pulled     38s                kubelet, docker-desktop  Container image "busybox:1.29.3" already present on machine
  Normal   Created    38s                kubelet, docker-desktop  Created container
  Normal   Started    38s                kubelet, docker-desktop  Started container
  Normal   Pulled     18s (x3 over 37s)  kubelet, docker-desktop  Container image "mysql:5.7.14" already present on machine
  Normal   Created    17s (x3 over 37s)  kubelet, docker-desktop  Created container
  Normal   Started    17s (x3 over 37s)  kubelet, docker-desktop  Started container
  Warning  BackOff    13s (x5 over 35s)  kubelet, docker-desktop  Back-off restarting failed container

When storageClassName was hostpath or did not used the configuration file as
$ helm install --name mysql stable/mysql
it worked fine.

Please tell me how to fix this problem.

-- k_trader
kubernetes
kubernetes-helm

1 Answer

3/28/2019

I think you are having a mismatch of accessModes between what you claim in PVC definition (ReadWriteOnce) and what your Storage Class offers (ReadWriteMany).

Please mind also that PersistentVolume(s) of HostPath type does not support ReadWriteMany mode (see spec here).

I would propose you to create PV similar to this one:

# Create PV of manual StorageClass
kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/C/Users/K8S/mysql" 

and override default PVC storageClassName configuration during helm install like this:

helm install --name my-sql stable/mysql --set persistence.storageClass=manual
-- Nepomucen
Source: StackOverflow