2

我有一个文件有 PV、Service 和 2 个 Pod 状态集,包括动态 PVC。当我部署文件时,PVC 状态出现问题。

# kubectl get pvc
NAME            STATUS    VOLUME           CAPACITY   ACCESS MODES   STORAGECLASS       AGE
www-web-0       Bound     pv-test          10Gi       RWO            my-storage-class   7m19s
www-web-1       Pending                                              my-storage-class   7m17s

PVC 的状态之一是“Pending”,原因是“Storage class name not found”。但是其中一个 PVC 是正常创建的。

以下是文件的内容。

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-test
  labels:
    type: local
spec:
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: "my-storage-class"
  capacity:
    storage: 10Gi
  hostPath:
    path: /tmp/data
    type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 2 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

如果有人知道原因,请告诉我。提前致谢。

描述有关 PV、PVC (www-web-1)、Pod (web-1) 的信息

kubectl describe pv pv-test
Name:            pv-test
Labels:          type=local
Annotations:     kubectl.kubernetes.io/last-applied-configuration:
                   {"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"labels":{"type":"local"},"name":"pv-test"},"spec":{"accessModes...
                 pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    my-storage-class
Status:          Bound
Claim:           default/www-web-0
Reclaim Policy:  Delete
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/data
    HostPathType:  DirectoryOrCreate
Events:            <none>

#kubectl  describe pvc www-web-1
Name:          www-web-1
Namespace:     default
StorageClass:  my-storage-class
Status:        Pending
Volume:
Labels:        app=nginx
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Events:
  Type       Reason              Age               From                         Message
  ----       ------              ----              ----                         -------
  Warning    ProvisioningFailed  20s (x7 over 2m)  persistentvolume-controller  storageclass.storage.k8s.io "my-storage-class" not found
Mounted By:  web-1


#kubectl describe po web-1
Name:               web-1
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               <none>
Labels:             app=nginx
                    controller-revision-hash=web-6596ffb49b
                    statefulset.kubernetes.io/pod-name=web-1
Annotations:        <none>
Status:             Pending
IP:
Controlled By:      StatefulSet/web
Containers:
  nginx:
    Image:        k8s.gcr.io/nginx-slim:0.8
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:
      /usr/share/nginx/html from www (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-lnfvq (ro)
Conditions:
  Type           Status
  PodScheduled   False
Volumes:
  www:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  www-web-1
    ReadOnly:   false
  default-token-lnfvq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-lnfvq
    Optional:    false
QoS Class:       BestEffort
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
  ----     ------            ----                     ----               -------
  Warning  FailedScheduling  3m43s (x183 over 8m46s)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 3 times)

4

2 回答 2

1

您的卷pv-testaccessModes: - ReadWriteOnce我认为您需要为第二个 pod 再创建一个卷。

所以我认为如果www-web-1 也尝试安装pv-test它将无法安装它。

于 2019-04-11T07:31:27.463 回答
0

您正在使用主机路径卷来存储数据。您正在主机上使用 /tmp/data。确保 /tmp/data 目录存在于集群中的所有节点中。

于 2019-04-11T07:26:23.510 回答