我已经在AWS上使用Kubernetes创建了Cassandra集群。我创建的卷为persistentVolume,回收策略为retain。但是,当我删除pod(所有实例)并重新创建pod时,旧数据丢失了。 这是我的设置状态。
$kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-1bc3f896-c0a5-11e8-84a8-02c7556b5a4a 320Gi RWO Retain Bound default/cassandra-storage-cassandra-1 gp2 21d
pvc-f3ff4203-c0a4-11e8-84a8-02c7556b5a4a 320Gi RWO Retain Bound default/cassandra-storage-cassandra-0 gp2 21d
$kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
cassandra-storage-cassandra-0 Bound pvc-f3ff4203-c0a4-11e8-84a8-02c7556b5a4a 320Gi RWO gp2 21d
cassandra-storage-cassandra-1 Bound pvc-1bc3f896-c0a5-11e8-84a8-02c7556b5a4a 320Gi RWO gp2 21d
$kubectl get pods
NAME READY STATUS RESTARTS AGE
cassandra-0 1/1 Running 0 39s
cassandra-1 1/1 Running 0 27s
$kubectl get statefulsets
NAME DESIRED CURRENT AGE
cassandra 2 2 1m
----
现在,如果我添加一些数据(键空间,表),然后删除状态集并再次重新创建它,则会丢失旧数据(键空间,表)。当我的政策被收回时,它应该在那里。
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: cassandra
labels:
app: cassandra
spec:
serviceName: cassandra
replicas: 2
selector:
matchLabels:
app: cassandra
template:
metadata:
labels:
app: cassandra
spec:
terminationGracePeriodSeconds: 180
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: kubernetes.io/hostname
labelSelector:
matchLabels:
app: cassandra
containers:
- env:
- name: MAX_HEAP_SIZE
value: 1024M
- name: HEAP_NEWSIZE
value: 1024M
- name: CASSANDRA_SEEDS
value: "cassandra-0.cassandra.default.svc.cluster.local"
- name: CASSANDRA_CLUSTER_NAME
value: "CassandraCluster"
- name: CASSANDRA_DC
value: "DC1-Cassandra"
- name: CASSANDRA_RACK
value: "Rack1-Cassandra"
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
image: library/cassandra
name: cassandra
volumeMounts:
- mountPath: /cassandra-storage
name: cassandra-storage
volumeClaimTemplates:
- metadata:
name: cassandra-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 320Gi
PV的配置如下。
$kubectl describe pv [10:33]
Name: pvc-1bc3f896-c0a5-11e8-84a8-02c7556b5a4a
Labels: failure-domain.beta.kubernetes.io/region=us-west-2
failure-domain.beta.kubernetes.io/zone=us-west-2b
Annotations: kubernetes.io/createdby=aws-ebs-dynamic-provisioner
pv.kubernetes.io/bound-by-controller=yes
pv.kubernetes.io/provisioned-by=kubernetes.io/aws-ebs
Finalizers: [kubernetes.io/pv-protection]
StorageClass: gp2
Status: Bound
Claim: default/cassandra-storage-cassandra-1
Reclaim Policy: Retain
Access Modes: RWO
Capacity: 320Gi
Node Affinity: <none>
Message:
Source:
Type: AWSElasticBlockStore (a Persistent Disk resource in AWS)
VolumeID: aws://us-west-2b/vol-0dceef39c7948c69e
FSType: ext4
Partition: 0
ReadOnly: false
Events: <none>
Name: pvc-f3ff4203-c0a4-11e8-84a8-02c7556b5a4a
Labels: failure-domain.beta.kubernetes.io/region=us-west-2
failure-domain.beta.kubernetes.io/zone=us-west-2b
Annotations: kubernetes.io/createdby=aws-ebs-dynamic-provisioner
pv.kubernetes.io/bound-by-controller=yes
pv.kubernetes.io/provisioned-by=kubernetes.io/aws-ebs
Finalizers: [kubernetes.io/pv-protection]
StorageClass: gp2
Status: Bound
Claim: default/cassandra-storage-cassandra-0
Reclaim Policy: Retain
Access Modes: RWO
Capacity: 320Gi
Node Affinity: <none>
Message:
Source:
Type: AWSElasticBlockStore (a Persistent Disk resource in AWS)
VolumeID: aws://us-west-2b/vol-07c16900909f80cd1
FSType: ext4
Partition: 0
ReadOnly: false
Events: <none>
我丢失一些设置或删除所有statefulset时无法进行回收,只有单个pod删除/重新启动才能声明卷数据吗?
答案 0 :(得分:0)
我认为您的Cassandra的mountPath“ / cassandra-storage”可能不正确,如果您未更改Cassandra数据路径,则默认的Cassandra数据路径为“ / var / lib / cassandra / data”,因此您需要将Cassandra yaml文件中的卷mountPath更改为“ / var / lib / cassandra / data”。