nob*_*bar 14 amazon-ebs elasticsearch kubernetes
我正在 Kubernetes 中管理 Elasticsearch 部署。我看到磁盘存储已接近满,所以我想增加持久卷的大小。
我想在有状态集中更改此值:
spec.?volumeClaimTemplates[0].spec.resources.requests.storage : "10Gi"
但是当我使用 Kubernetes 仪表板执行此操作时,我收到以下消息:
内部服务器错误
StatefulSet.apps "es-cluster" 无效:spec: Forbidden: 禁止更新 statefulset > spec,用于除 'replicas'、'template' 和 'updateStrategy' 以外的字段。
这让我觉得我必须删除我现有的 Stateful Set 并部署一个新的。
是否可以在不中断服务或丢失数据的情况下增加 per-pod 磁盘存储?
我有多个 Elasticsearch 数据 pod,并且正在使用副本计数 = 1,所以如果我能够将它们取下并一次升级一个 pod 的磁盘存储,应该不会有问题。鉴于上述限制,我只是不知道如何做到这一点。
Chr*_*nes 22
根据https://github.com/kubernetes/kubernetes/issues/68737上的其他评论将这个过程拼凑在一起。我在 kubernetes 1.14 上对此进行了测试:
kubectl edit pvc <name>
对于 StatefulSet 中的每个 PVC,以增加其容量。kubectl delete sts --cascade=orphan <name>
删除 StatefulSet 并保留其 pod。kubectl apply -f <name>
重新创建 StatefulSet。kubectl rollout restart sts <name>
重新启动 Pod,一次一个。在重启期间,pod 的 PVC 将被调整大小。如果您想监视正在发生的事情,请在执行上述任何命令之前,使用这些命令再运行两个 shell 窗口:
kubectl get pod -w
kubectl get pvc -w
小智 8
这是一个完整的脚本,用于根据其他答案调整 STS 卷的大小。删除 STS 时我不需要这样做,--cascade=false
因为在这一步之前它已经被缩放到 0。
kubectl get -o jsonpath='{.allowVolumeExpansion}' sc <SC-NAME>
# should return true, otherwise, patch it:
kubectl patch -p '{"allowVolumeExpansion": true}' sc <SC-NAME>
# then run the first command again
Run Code Online (Sandbox Code Playgroud)
# we need the original replica count, so let's save it before scaling down
REPLICAS=`kubectl get -o jsonpath='{.spec.replicas}' sts/<STS-NAME>`
kubectl scale sts/<STS-NAME> --replicas 0
Run Code Online (Sandbox Code Playgroud)
NEW_SIZE=128Gi
for i in `seq 0 $[REPLICAS-1]`; do
PVC=<PVC-NAME-PREFIX>-$i
echo "Updating PVC $PVC"
# Print the current size:
kubectl get -o jsonpath='{.spec.resources.requests.storage} ' pvc/$PVC
# Set the new size:
kubectl patch -p '{"spec": {"resources": {"requests": {"storage": "'$NEW_SIZE'"}}}}' pvc/$PVC
# Verify the PV:
echo "Waiting for 10 seconds so that the PV picks up the change..."
echo "If you still see the same size, do not worry, to see the new size just run this script again"
sleep 10
PV=`kubectl get -o jsonpath='{.spec.volumeName}' pvc/$PVC`
kubectl get -o jsonpath='{.spec.capacity.storage} ' pv/$PV
echo "Done"
done
Run Code Online (Sandbox Code Playgroud)
kubectl delete sts <STS-NAME>
Run Code Online (Sandbox Code Playgroud)
for i in `seq 0 $[REPLICAS-1]`; do
PVC=<PVC-NAME-PREFIX>-$i
echo "Verifying the size of PVC $PVC"
# Verify the current size:
kubectl get -o jsonpath='{.status.capacity.storage} ' pvc/$PVC
done
Run Code Online (Sandbox Code Playgroud)
为了将此原则应用于舵图,我能够根据上面的输入以及有关此线程的一些指导执行以下操作:https : //github.com/kubernetes/kubernetes/issues/68737#issuecomment-469647348
下面的示例使用以下值:
可以使用以下命令在您的环境中找到这些值:
kubectl get pvc
kubectl get sts
helm list
以下是在 helm chart 的 StatefulSet 中更新 PV 大小的步骤:
kubectl edit storageClass standard
并设置/确保 allowVolumeExpansion: true (在我的情况下已经如此)kubectl delete sts --cascade=false rabbitmq-server
kubectl edit pvc data-rabbitmq-server-0
并将规格大小更改为 50Gihelm upgrade --recreate-pods --reuse-values -f rabbit-values.yaml rabbitmq-server stable/rabbitmq
注意:最后一步使用--recreate-pods
标志来强制重新启动 pod,这会触发实际的文件系统大小调整。这也会导致这些 Pod 停机。如果您想尝试在不停机的情况下执行此操作,您可以尝试删除该标志,并一次手动杀死/重新启动一个 pod,或者其他操作。
小智 4
即使从Kubernetes 1.11开始使用 Kubernetes 调整持久卷大小,它似乎也存在一些问题。
如 GitHub 中所述:StatefulSet:支持在 K8s v1.11 中调整 PVC 存储大小 #68737
由于此限制,Kubernetes 的许多数据库 Operator 不支持 PVC 大小调整。这是一个关键问题,因为当您的数据库变得比您预期的大时 - 您别无选择,需要备份数据库并从备份重新创建新的数据库。
您应该通过删除 Statefulset 来调整它的大小,这意味着您将删除所有 Pod,并且会导致停机。
DaveWHarvey发布了解决方法
我绕过了elasticsearch的这个限制,因为我必须做一些工作来避免EBS卷无法分配,因为它们位于错误的可用区,即我已经为每个可用区创建了一个有状态集。如果我想更改某些存储特性,我可以使用相同的存储类创建一个新的“AZ”,然后将所有数据迁移到该新AZ中的pod,然后销毁旧的AZ。
希望这对您有一点帮助。
归档时间: |
|
查看次数: |
19180 次 |
最近记录: |