Pod拥有未绑定的PersistentVolumeClaims,但数量声明受到限制

时间:2018-06-26 11:17:45

标签: kubernetes persistent-volumes kubernetes-statefulset

我想在virtualbox的kubernetes中创建statefulset elasticsearch。我没有使用云提供商,所以我为我的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

似乎持久性卷已正确反弹,但pod始终处于崩溃循环并每次都重新启动。是因为使用了initContainer还是我的Yaml出了点问题?

Statefulset

pv,pvc

1 个答案:

答案 0 :(得分:-30)

添加更多Ram,扩展集群。