gpt4 book ai didi

Kubernetes:如何将自动缩放的 pod 的访问模式更改为 ReadOnlyMany?

转载 作者:行者123 更新时间:2023-12-04 19:07:03 24 4
gpt4 key购买 nike

我正在尝试 HPA:https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

光伏:

apiVersion: v1
kind: PersistentVolume
metadata:
name: api-orientdb-pv
labels:
app: api-orientdb
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: api-orientdb-{{ .Values.cluster.name | default "testing" }}
fsType: ext4

PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: api-orientdb-pv-claim
labels:
app: api
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
selector:
matchLabels:
app: api-orientdb
storageClassName: ""

卫生署:
Name:                           api-orientdb-deployment
Namespace: default
Labels: <none>
Annotations: <none>
CreationTimestamp: Thu, 08 Jun 2017 10:37:06 +0700
Reference: Deployment/api-orientdb-deployment
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): 17% (8m) / 10%
Min replicas: 1
Max replicas: 2
Events: <none>

并创建了新的 pod:
NAME                                       READY     STATUS    RESTARTS   AGE
api-orientdb-deployment-2506639415-n8nbt 1/1 Running 0 7h
api-orientdb-deployment-2506639415-x8nvm 1/1 Running 0 6h

如您所见,我正在使用 gcePersistentDisk不支持 ReadWriteMany访问模式。

新创建的 pod 也将卷挂载为 rw模式:
Name:        api-orientdb-deployment-2506639415-x8nvm
Containers:
Mounts:
/orientdb/databases from api-orientdb-persistent-storage (rw)
Volumes:
api-orientdb-persistent-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: api-orientdb-pv-claim
ReadOnly: false

问题:在这种情况下它是如何工作的?有没有办法配置主要的 pod( n8nbt )以使用带有 ReadWriteOnce 的 PV访问模式,所有其他缩放的 pod ( x8nvm ) 应该是 ReadOnlyMany ?如何自动完成?

我能想到的唯一方法是在相同的磁盘上创建另一个 PVC 安装,但使用不同的 accessModes ,但问题变成了:如何配置新扩展的 pod 以使用该 PVC?

2017 年 6 月 9 日星期五 11:29:34 ICT

我发现了一些东西:没有什么可以确保新扩展的 pod 将在与第一个 pod 相同的节点上运行。所以,如果音量插件不支持 ReadWriteMany并且缩放后的 Pod 在另一个节点上运行,它将无法挂载:

Failed to attach volume "api-orientdb-pv" on node "gke-testing-default-pool-7711f782-4p6f" with: googleapi: Error 400: The disk resource 'projects/xx/zones/us-central1-a/disks/api-orientdb-testing' is already being used by 'projects/xx/zones/us-central1-a/instances/gke-testing-default-pool-7711f782-h7xv'



https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes

Important! A volume can only be mounted using one access mode at a time, even if it supports many. For example, a GCEPersistentDisk can be mounted as ReadWriteOnce by a single node or ReadOnlyMany by many nodes, but not at the same time.



如果是这样,确保 HPA 正常工作的唯一方法是 ReadWriteMany卷插件必须支持访问模式吗?

2017 年 6 月 9 日星期五 14:28:30 ICT

If you want only one Pod to be able to write then create two Deployments. One with replicas: 1 and the other one that has the autoscaler attached (and has readOnly: true in it)



好的。

Do note that a GCE PD can only be mounted by a single node if any of the Pods are accessing it readWrite.



那我得用 label selectors确保所有 pod 最终都在同一个节点上,对吗?

Your question is not clear to me



让我解释一下:在自动缩放的情况下,假设通过使用标签选择器,我可以确保新缩放的 pod 最终位于同一节点上,但由于卷安装为 rw ,它是否会破坏 GCE PD,因为我们有 2 个 pod 将卷安装为 rw ?

First of all, generally, if you have a Deployment with replicas: 1 you won't have 2 Pod running at the same time (most of the time!!)



我知道。

On the other hand if a PVC specifies ReadWriteOnce then after the first Pod is scheduled any other Pods will need to be scheduled on the same node or not be scheduled at all (most common case: there aren't enough resources on the Node)



如果是 HPA,则不会。有关更多详细信息,请参阅我的上述更新。

If for any reason you do have 2 Pods accessing the same mount readWrite then it's completely up the the application what will happen and is not kubernetes specific



让我感到困惑的主要事情是:

ReadWriteOnce – the volume can be mounted as read-write by a single node



好的,节点,而不是 pod。但是在自动缩放的情况下,如果 2 个 Pod 在同一个节点上运行,并且都将卷挂载为 rw ,GCE PD支持吗?如果是这样,它是如何工作的?

最佳答案

它按预期工作。曾经在 ReadWriteOnce指的是可以使用 PVC 的节点数,而不是 Pod 数(HPA 或无 HPA)。

如果您只希望一个 Pod 能够写入,则创建两个部署。一带replicas: 1另一个附加了自动缩放器(其中包含 readOnly: true)。请注意,如果任何 Pod 正在以读写方式访问 GCE PD,则它只能由单个节点挂载。

关于Kubernetes:如何将自动缩放的 pod 的访问模式更改为 ReadOnlyMany?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44432833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com