如何在kubernetes statefulset中还原永久磁盘?

时间:2018-07-07 17:54:44

标签: elasticsearch kubernetes google-kubernetes-engine

我有一个带有elasticsearch索引的gcePersistentDisk。当我删除并重新创建有状态集时,我想重用此磁盘,以便在新的有状态集上可以使用相同的索引。

我设法将磁盘my-es-disk重新绑定到新的有状态集,但是当我连接到容器并检查索引时,没有索引。

我已经查看过Google和k8s文档,而且yamls似乎正确,但是我仍然无法保留索引。我敢肯定这很简单!感谢您的帮助!

我的工作流程:

1-创建存储类

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: ssd
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
  zone: us-central1-a
reclaimPolicy: Retain
allowVolumeExpansion: true

2-创建PersistentVolume和PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-es
spec:
  storageClassName: ssd
  capacity:
    storage: 3G
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: my-es-disk
    fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-es
spec:
  storageClassName: ssd
  volumeName: pv-es
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3G

3-部署statefulSet

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: elastic-data
  labels:
    app: elastic-data
    area: devs
    role: nosql
    version: "6.1.4"
    environment: elastic
spec:
  serviceName: elastic-data
  replicas: 1
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: elastic-data
        area: devs
        role: nosql
        version: "6.1.4"
        environment: elastic
    spec:
      terminationGracePeriodSeconds: 10
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
      containers:
      - name: elastic-data
        image: docker.elastic.co/elasticsearch/elasticsearch:6.1.4
        resources:
          requests:
            memory: "512Mi"
          limits:
            memory: "1024Mi"
        ports:
        - containerPort: 9300
          name: transport
        - containerPort: 9200
          name: http
        volumeMounts:
        - name: data-volume
          mountPath: /usr/share/elasticsearch/data
      volumes:
      - name: data-volume
        persistentVolumeClaim:
          claimName: pv-claim-es

0 个答案:

没有答案