pod具有未绑定的立即PersistentVolumeClaims(重复3次)

时间:2020-06-05 12:52:24

标签: kubernetes kubernetes-pod kubernetes-pvc

下面有什么问题。

# config for es data node
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: infra
  name: elasticsearch-data-config
  labels:
    app: elasticsearch
    role: data
data:
  elasticsearch.yml: |-
    cluster.name: ${CLUSTER_NAME}
    node.name: ${NODE_NAME}
    discovery.seed_hosts: ${NODE_LIST}
    cluster.initial_master_nodes: ${MASTER_NODES}

    network.host: 0.0.0.0

    node:
      master: false
      data: true
      ingest: false

    xpack.security.enabled: true
    xpack.monitoring.collection.enabled: true
---
# service for es data node
apiVersion: v1
kind: Service
metadata:
  namespace: infra
  name: elasticsearch-data
  labels:
    app: elasticsearch
    role: data
spec:
  ports:
  - port: 9300
    name: transport
  selector:
    app: elasticsearch
    role: data
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  namespace: infra
  name: elasticsearch-data
  labels:
    app: elasticsearch
    role: data
spec:
  serviceName: "elasticsearch-data"
  replicas: 1
  template:
    metadata:
      labels:
        app: elasticsearch-data
        role: data
    spec:
      containers:
      - name: elasticsearch-data
        image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
        env:
        - name: CLUSTER_NAME
          value: elasticsearch
        - name: NODE_NAME
          value: elasticsearch-data
        - name: NODE_LIST
          value: elasticsearch-master,elasticsearch-data,elasticsearch-client
        - name: MASTER_NODES
          value: elasticsearch-master
        - name: "ES_JAVA_OPTS"
          value: "-Xms300m -Xmx300m"
        ports:
        - containerPort: 9300
          name: transport
        volumeMounts:
        - name: config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          readOnly: true
          subPath: elasticsearch.yml
        - name: elasticsearch-data-persistent-storage
          mountPath: /data/db
      volumes:
      - name: config
        configMap:
          name: elasticsearch-data-config
      initContainers:
      - name: increase-vm-max-map
        image: busybox
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: elasticsearch-data-persistent-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 10Gi

全状态输出:

Name:           elasticsearch-data-0
Namespace:      infra
Priority:       0
Node:           <none>
Labels:         app=elasticsearch-data
                controller-revision-hash=elasticsearch-data-76bdf989b6
                role=data
                statefulset.kubernetes.io/pod-name=elasticsearch-data-0
Annotations:    <none>
Status:         Pending
IP:             
IPs:            <none>
Controlled By:  StatefulSet/elasticsearch-data
Init Containers:
  increase-vm-max-map:
    Image:      busybox
    Port:       <none>
    Host Port:  <none>
    Command:
      sysctl
      -w
      vm.max_map_count=262144
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-9nhmg (ro)
Containers:
  elasticsearch-data:
    Image:      docker.elastic.co/elasticsearch/elasticsearch:7.3.0
    Port:       9300/TCP
    Host Port:  0/TCP
    Environment:
      CLUSTER_NAME:  elasticsearch
      NODE_NAME:     elasticsearch-data
      NODE_LIST:     elasticsearch-master,elasticsearch-data,elasticsearch-client
      MASTER_NODES:  elasticsearch-master
      ES_JAVA_OPTS:  -Xms300m -Xmx300m
    Mounts:
      /data/db from elasticsearch-data-persistent-storage (rw)
      /usr/share/elasticsearch/config/elasticsearch.yml from config (ro,path="elasticsearch.yml")
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-9nhmg (ro)
Conditions:
  Type           Status
  PodScheduled   False 
Volumes:
  elasticsearch-data-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  elasticsearch-data-persistent-storage-elasticsearch-data-0
    ReadOnly:   false
  config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      elasticsearch-data-config
    Optional:  false
  default-token-9nhmg:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-9nhmg
    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  46s (x4 over 3m31s)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 3 times)

kubectl获取sc

NAME                 PROVISIONER            AGE
standard (default)   kubernetes.io/gce-pd   5d19h

kubectl get pv
No resources found in infra namespace.
kubectl get pvc
NAME                                                         STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
elasticsearch-data-persistent-storage-elasticsearch-data-0   Pending                                      gp2            8h

3 个答案:

答案 0 :(得分:2)

从文档here

给定Pod的存储空间必须由 基于请求的存储类的PersistentVolume Provisioner,或者 由管理员预先设置。

应该有一个StorageClass可以动态地设置PV,并在storageClassName中提到volumeClaimTemplates,或者需要有一个满足PVC的PV。

volumeClaimTemplates:
  - metadata:
      name: elasticsearch-data-persistent-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "standard"
      resources:
        requests:
          storage: 10Gi

答案 1 :(得分:1)

您的PVC似乎有问题。

NAME                                                         STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
elasticsearch-data-persistent-storage-elasticsearch-data-0   Pending                                      gp2            8h

您可以看到您的PV也没有创建。我认为您的存储类存在问题。集群中没有gp2存储类。

如果您在AWS EKS中,请运行此yaml文件

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: gp2
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  fsType: ext4

或仅在GCP GKE中将存储类更改为标准

答案 2 :(得分:1)

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  namespace: default
  name: elasticsearch-data
  labels:
    app: elasticsearch
    role: data
spec:
  serviceName: "elasticsearch-data"
  replicas: 1
  template:
    metadata:
      labels:
        app: elasticsearch-data
        role: data
    spec:
      containers:
        - name: elasticsearch-data
          image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
          env:
            - name: CLUSTER_NAME
              value: elasticsearch
            - name: NODE_NAME
              value: elasticsearch-data
            - name: NODE_LIST
              value: elasticsearch-master,elasticsearch-data,elasticsearch-client
            - name: MASTER_NODES
              value: elasticsearch-master
            - name: "ES_JAVA_OPTS"
              value: "-Xms300m -Xmx300m"
          ports:
            - containerPort: 9300
              name: transport
          volumeMounts:
            - name: config
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              readOnly: true
              subPath: elasticsearch.yml
            - name: elasticsearch-data-persistent-storage
              mountPath: /data/db
      volumes:
        - name: config
          configMap:
            name: elasticsearch-data-config
      initContainers:
        - name: increase-vm-max-map
          image: busybox
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          securityContext:
            privileged: true
  volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data-persistent-storage
        annotations:
          volume.beta.kubernetes.io/storage-class: "standard"
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 10Gi
---

这对我有用。就像Avinash所说的那样,我只是在GCP GKE中将存储类更改为标准