适用于Windows的docker具有在本地持久卷上掌舵的Kubernetes

时间:2019-03-28 04:48:25

标签: kubernetes kubernetes-helm

我试图在docker上使用helm在本地计算机上运行Windows。当我使用存储类作为本地存储,永久卷和没有掌权的永久卷声明时,它可以正常工作。但是当我将此设置与头盔一起使用时,发生了CrashLoopBackOff。

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描述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

当storageClassName是主机路径或未将配置文件用作
时 $ helm install --name mysql stable / mysql
工作正常。

请告诉我如何解决此问题。

1 个答案:

答案 0 :(得分:1)

我认为您在PVC定义中声明的内容(ReadWriteOnce)与存储类提供的内容(ReadWriteMany)之间的accessModes不匹配。

还请注意,HostPath类型的PersistentVolume不支持ReadWriteMany模式(请参见此处的spec)。

我建议您创建与此类似的PV:

# 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" 

并在头盔安装过程中覆盖默认的PVC storageClassName默认配置,如下所示:

helm install --name my-sql stable/mysql --set persistence.storageClass=manual