Apigee Hybrid 将一圈 Cassandra 节点用作 StatefulSet。Cassandra 为运行时层面中的某些 Apigee 实体提供永久性存储。如需详细了解 Cassandra,请参阅关于运行时层面。
Cassandra 是一项资源密集型服务,不应和任何其他混合服务一起部署在 pod 上。根据负载,您可能希望扩缩集群中环中的 Cassandra 节点的数量。
缩减 Cassandra 环的一般过程如下:
- 停用一个 Cassandra 节点。
- 更新
overrides.yaml
中的cassandra.replicaCount
属性。 - 应用配置更新。
- 对要移除的每个节点重复这些步骤。
- 删除永久性卷声明或卷,具体取决于您的集群配置。
注意事项
- 请一次在一个节点上执行该任务,然后再继续到下一个节点。
- 如果除要停用的节点以外的任何节点运行状况不佳,请不要继续。Kubernetes 将无法从集群中缩减这些 pod。
- 始终按三个节点进行缩减或扩容。
前提条件
在缩减环中的 Cassandra 节点数量之前,请验证集群是否正常运行且所有节点是否都已启动并运行,如以下示例所示:
kubectl get pods -n yourNamespace -l app=apigee-cassandra NAME READY STATUS RESTARTS AGE apigee-cassandra-default-0 1/1 Running 0 2h apigee-cassandra-default-1 1/1 Running 0 2h apigee-cassandra-default-2 1/1 Running 0 2h apigee-cassandra-default-3 1/1 Running 0 16m apigee-cassandra-default-4 1/1 Running 0 14m apigee-cassandra-default-5 1/1 Running 0 13m
kubectl -n yourNamespace exec -it apigee-cassandra-default-0 nodetool status Datacenter: us-east1 ==================== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.16.2.6 690.17 KiB 256 48.8% b02089d1-0521-42e1-bbed-900656a58b68 ra-1 UN 10.16.4.6 700.55 KiB 256 51.6% dc6b7faf-6866-4044-9ac9-1269ebd85dab ra-1 to UN 10.16.11.11 144.36 KiB 256 48.3% c7906366-6c98-4ff6-a4fd-17c596c33cf7 ra-1 UN 10.16.1.11 767.03 KiB 256 49.8% ddf221aa-80aa-497d-b73f-67e576ff1a23 ra-1 UN 10.16.5.13 193.64 KiB 256 50.9% 2f01ac42-4b6a-4f9e-a4eb-4734c24def95 ra-1 UN 10.16.8.15 132.42 KiB 256 50.6% a27f93af-f8a0-4c88-839f-2d653596efc2 ra-1
停用 Cassandra 节点
-
使用 nodetool 命令从集群中停用 Cassandra 节点。
kubectl -n yourNamespace exec -it nodeName nodetool decommission
例如,此命令将停用
apigee-cassandra-5
(名称中编号值最大的节点):kubectl -n apigee exec -it apigee-cassandra-5 nodetool decommission
- 等待停用完成,并验证集群现在少了一个节点。例如:
kubectl -n yourNamespace exec -it nodeName nodetool status Datacenter: us-east1 ==================== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.16.2.6 710.37 KiB 256 59.0% b02089d1-0521-42e1-bbed-900656a58b68 ra-1 UN 10.16.4.6 720.97 KiB 256 61.3% dc6b7faf-6866-4044-9ac9-1269ebd85dab ra-1 UN 10.16.1.11 777.11 KiB 256 58.9% ddf221aa-80aa-497d-b73f-67e576ff1a23 ra-1 UN 10.16.5.13 209.23 KiB 256 62.2% 2f01ac42-4b6a-4f9e-a4eb-4734c24def95 ra-1 UN 10.16.8.15 143.23 KiB 256 58.6% a27f93af-f8a0-4c88-839f-2d653596efc2 ra-1
- 在
overrides.yaml
文件中更新或添加cassandra.replicaCount
属性。例如,如果当前节点数为 6,请将其更改为 5:cassandra: replicaCount: 5 # (n-1 5 in this example)
- 将配置更改应用到您的集群:
./apigeectl apply --datastore namespace/apigee unchanged secret/ssl-cassandra unchanged storageclass.storage.k8s.io/apigee-gcepd unchanged service/apigee-cassandra unchanged statefulset.apps/apigee-cassandra configured
- 验证其余所有 Cassandra 节点是否正在运行:
kubectl get pods -n yourNamespace -l app=apigee-cassandra NAME READY STATUS RESTARTS AGE apigee-cassandra-default-0 1/1 Running 0 3h apigee-cassandra-default-1 1/1 Running 0 3h apigee-cassandra-default-2 1/1 Running 0 2h apigee-cassandra-default-3 1/1 Running 0 25m apigee-cassandra-default-4 1/1 Running 0 24m
- 对要停用的每个节点重复第 1-5 步。
- 完成节点停用后,验证
cassandra.replicaCount
值是否等于nodetool status
命令返回的节点数。例如,如果您将 Cassandra 缩减为三个节点,请运行以下命令:
kubectl -n yourNamespace exec -it apigee-cassandra-default-0 nodetool status Datacenter: us-east1 ==================== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.16.2.6 710.37 KiB 256 59.0% b02089d1-0521-42e1-bbed-900656a58b68 ra-1 UN 10.16.4.6 720.97 KiB 256 61.3% dc6b7faf-6866-4044-9ac9-1269ebd85dab ra-1 UN 10.16.5.13 209.23 KiB 256 62.2% 2f01ac42-4b6a-4f9e-a4eb-4734c24def95 ra-1
- Cassandra 集群缩减后,请务必删除 pvc (PersistentVolumeClaim),以确保下一个纵向扩容事件不会使用相同的永久性卷和之前创建的数据。
获取 pvcs 的名称:
kubectl get pvc -n yourNamespace NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE cassandra-data-apigee-cassandra-default-0 Bound pvc-f9c2a5b9-818c-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-1 Bound pvc-2956cb78-818d-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-2 Bound pvc-79de5407-8190-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-3 Bound pvc-d29ba265-81a2-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 5h cassandra-data-apigee-cassandra-default-4 Bound pvc-0675a0ff-81a3-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 5h cassandra-data-apigee-cassandra-default-5 Bound pvc-354afa95-81a3-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 5h
在本示例中,以下 pvcs 与三个停用节点相对应:
cassandra-data-apigee-cassandra-5
cassandra-data-apigee-cassandra-4
cassandra-data-apigee-cassandra-3
- 删除 pvcs:
kubectl -n yourNamespace delete pvc cassandra-data-apigee-cassandra-5 persistentvolumeclaim "cassandra-data-apigee-cassandra-5" deleted
kubectl -n yourNamespace delete pvc cassandra-data-apigee-cassandra-4 persistentvolumeclaim "cassandra-data-apigee-cassandra-4" deleted
kubectl -n yourNamespace delete pvc cassandra-data-apigee-cassandra-3 persistentvolumeclaim "cassandra-data-apigee-cassandra-3" deleted
- 验证 pvc 是否已删除:
kubectl get pvc -n yourNamespace NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE cassandra-data-apigee-cassandra-default-0 Bound pvc-f9c2a5b9-818c-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-1 Bound pvc-2956cb78-818d-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-2 Bound pvc-79de5407-8190-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 7h cassandra-data-apigee-cassandra-default-3 Bound pvc-d29ba265-81a2-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 5h cassandra-data-apigee-cassandra-default-4 Bound pvc-0675a0ff-81a3-11e9-8862-42010a8e014a 100Gi RWO apigee-gcepd 5h
- 如果您要使用 Anthos 安装程序,请使用相同序列从 Anthos Kubernetes 集群中删除永久性卷。
获取永久性卷的名称:
kubectl get pv -n youNamespace NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-0675a0ff-81a3-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-4 apigee-gcepd 5h pvc-2956cb78-818d-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-1 apigee-gcepd 7h pvc-354afa95-81a3-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-5 apigee-gcepd 5h pvc-79de5407-8190-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-2 apigee-gcepd 7h pvc-d29ba265-81a2-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-3 apigee-gcepd 5h pvc-f9c2a5b9-818c-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-0 apigee-gcepd 7h
在本示例中,以下卷对应三个停用的节点:
- 5:
pvc-354afa95-81a3-11e9-8862-42010a8e014a
- 4:
pvc-0675a0ff-81a3-11e9-8862-42010a8e014a
- 3:
pvc-d29ba265-81a2-11e9-8862-42010a8e014a
- 5:
- 删除永久性卷:
kubectl -n yourNamespace delete pv pvc-354afa95-81a3-11e9-8862-42010a8e014a
kubectl -n yourNamespace delete pv pvc-0675a0ff-81a3-11e9-8862-42010a8e014a
kubectl -n yourNamespace delete pv pvc-d29ba265-81a2-11e9-8862-42010a8e014a
- 验证永久性卷是否已删除:
kubectl get pv -n youNamespace NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-2956cb78-818d-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-1 apigee-gcepd 7h pvc-79de5407-8190-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-2 apigee-gcepd 7h pvc-f9c2a5b9-818c-11e9-8862-42010a8e014a 100Gi RWO Delete Bound apigee/cassandra-data-apigee-cassandra-default-0 apigee-gcepd 7h