Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tunnel heartbeat for fast datapath failover #847

Merged
merged 1 commit into from
Oct 30, 2023
Merged

Add tunnel heartbeat for fast datapath failover #847

merged 1 commit into from
Oct 30, 2023

Conversation

lou-lan
Copy link
Collaborator

@lou-lan lou-lan commented Oct 18, 2023

Datapath Failover

背景

因为 Node 的默认 Ready/NotReady 的检测时间为 40s,对于 EgressGateway 来说改时间太长,无法做到快速故障转移。

所以增加一个 EgressTunnel 的心跳机制,实现快速的故障转移。目前 EgressGateway 控制器已经支持了 watch EgressTunnel 的 CR 进行 EIP 选举。所以只需要在 Controller 和 Agent 各自增加一个小的控制起,实现定期更新的 EgressTunnel 状态判断即可。

在处理数据面故障转移时,创建 EgressGateway 可以通过使用 nodeSelector 来选择一组节点作为 Egress Node。Egress IP 将会绑定到其中的一个节点上。当某个节点发生故障时,Egress IP 将会自动转移到另一个可用节点上。

设计

apiVersion: egressgateway.spidernet.io/v1beta1
kind: EgressGateway
metadata:
  name: egw1
spec:
  clusterDefault: true
  ippools:
    ipv4:
      - 10.6.1.55
      - 10.6.1.56
    ipv4DefaultEIP: 10.6.1.56
    ipv6:
      - fd00::55
      - fd00::56
    ipv6DefaultEIP: fd00::55
  nodeSelector:
    selector:
      matchLabels:
        egress: "true"
status:
  nodeList:
    - eips:
        - ipv4: 10.6.1.56
          ipv6: fd00::55
          policies:
            - name: policy1
              namespace: default
      name: workstation2
      status: Ready
    - name: workstation3
      status: Ready

通过 Helm 的 values 配置,可以调整状态检测和 Egress IP 转移的时间。

  • feature.tunnelMonitorPeriod:Egress Controller 以秒为单位设置的间隔检查 EgressTunnel 的最后更新状态,默认为 5
  • feature.tunnelUpdatePeriod:Egress Agent 以秒为单位设置的间隔更新 EgressTunnel 状态,默认为 5
  • feature.eipEvictionTimeout:如果 EgressTunnel 的最后更新时间超过此时间,则将节点的 Egress IP 移动到另一个可用节点,单位为秒,默认为 15

Datapath Failover 问题排查步骤:

  1. 首先,查看 EgressGateway 应用的安装配置文件 values.yaml,确认与 Datapath Failover 相关的配置是否设置合理,特别是确保 eipEvictionTimeout 的值大于 tunnelMonitorPeriod 加上 tunnelUpdatePeriod 的总和;
  2. 执行 kubectl get egt -w 命令,检查 EgressTunnel 的状态。检查选中的 Node 是否处于 HeartbeatTimeout 状态,并且是否存在其他处于 Ready 状态的 EgressTunnel
  3. 检查 EgressGateway Controller Pod 的日志信息。

备选设计

  1. 使用无中心八卦算法等(缺点时改造量较大)

@lou-lan lou-lan changed the title Add the logic for egress IP eviction, controlled by heartbeat. WIP: Add the logic for egress IP eviction, controlled by heartbeat. Oct 18, 2023
pkg/config/config.go Outdated Show resolved Hide resolved
pkg/agent/vxlan.go Outdated Show resolved Hide resolved
@weizhoublue
Copy link
Collaborator

gateway pod 的 一些高可用 能力,可以在相关文档中 体现下:
(1)gateway pod 故障 心跳
(2)gateway node 故障

故障后,vip 是怎么处理的, 恢复后,vip 是怎么处理的
...... 诸如此类

@lou-lan lou-lan force-pushed the heartbeat branch 2 times, most recently from e14e474 to 029ac58 Compare October 20, 2023 08:32
@lou-lan lou-lan added the release/feature-new feature pr recoded in new release label Oct 20, 2023
@lou-lan lou-lan force-pushed the heartbeat branch 6 times, most recently from e111148 to 646b209 Compare October 23, 2023 04:33
@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Merging #847 (875bbd6) into main (94708aa) will decrease coverage by 0.75%.
Report is 24 commits behind head on main.
The diff coverage is 12.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #847      +/-   ##
==========================================
- Coverage   40.20%   39.45%   -0.75%     
==========================================
  Files          18       18              
  Lines        2512     2585      +73     
==========================================
+ Hits         1010     1020      +10     
- Misses       1334     1396      +62     
- Partials      168      169       +1     
Flag Coverage Δ
unittests 39.45% <12.04%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pkg/controller/egress_policy.go 0.00% <ø> (ø)
pkg/config/config.go 50.83% <75.00%> (+2.68%) ⬆️
pkg/controller/egress_tunnel.go 26.91% <1.40%> (-3.66%) ⬇️

@lou-lan lou-lan force-pushed the heartbeat branch 2 times, most recently from c4d47de to 4830630 Compare October 23, 2023 11:46
@lou-lan lou-lan changed the title WIP: Add the logic for egress IP eviction, controlled by heartbeat. Add EgressTunnel heartbeat for fast datapath failover Oct 23, 2023
@lou-lan lou-lan changed the title Add EgressTunnel heartbeat for fast datapath failover Add tunnel heartbeat for fast datapath failover Oct 23, 2023
@@ -60,6 +60,9 @@ spec:
type: object
status:
properties:
lastHeartbeatTime:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是所有的agent 都要 更新 心跳,还只是 gateway node 心跳

Copy link
Collaborator Author

@lou-lan lou-lan Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是所有的agent 都要 更新 心跳,还只是 gateway node 心跳

是所有的 agent 都要更新心跳,不是仅为 gateway 的 node。先由 tunnel ready 才会选为 gateway 的可用的节点。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否 不是 gateway 校色的 节点,不需要 更新 ?避免 大规模集群增加 api 负担

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否 不是 gateway 校色的 节点,不需要 更新 ?避免 大规模集群增加 api 负担

可以实现,被选中的节点上包心跳。需要再更新下代码。

charts/values.yaml Outdated Show resolved Hide resolved
@weizhoublue
Copy link
Collaborator

假设一个场景:
gateway 1 的 agent 和 api server 断网,agent 还在运行
gateway 2 的 agent 因此接管 vip
那么是否会出现 vip 脑裂

@lou-lan
Copy link
Collaborator Author

lou-lan commented Oct 23, 2023

假设一个场景: gateway 1 的 agent 和 api server 断网,agent 还在运行 gateway 2 的 agent 因此接管 vip 那么是否会出现 vip 脑裂

脑裂这种场景只要分区就会发生,

假设一个场景: gateway 1 的 agent 和 api server 断网,agent 还在运行 gateway 2 的 agent 因此接管 vip 那么是否会出现 vip 脑裂

  1. 因为是心跳机制,要达到与 api-server 的伪一致性,那么这个与 etcd 失去连接的 agent 应该把 vip 移除(等待超时后)。
  2. 如果不按照 1 的方式做,你的假设只有 api-server 分区,但是数据面没有分区,这时候 eip 的新选举,导致出现 2 的 vip 会带来负面影响。
  3. 如果不按照 1 的方式,假设真的分为 2 个区,包括数据面。那么与 apiserver 失去连接的 agent 不把 vip 移除是十分友好的。也许这个区有 100 个业务 pod 在使用你的 eip。

@weizhoublue
Copy link
Collaborator

因为是心跳机制,要达到与 api-server 的伪一致性,那么这个与 etcd 失去连接的 agent 应该把 vip 移除(等待超时后)
-------- 当前代码,是有有这个逻辑

@lou-lan
Copy link
Collaborator Author

lou-lan commented Oct 25, 2023

因为是心跳机制,要达到与 api-server 的伪一致性,那么这个与 etcd 失去连接的 agent 应该把 vip 移除(等待超时后) -------- 当前代码,是有有这个逻辑

讨论结论是,按照 apiserver 超时是,agent 应该摘掉 eip 的方式做。代码还未更新

@lou-lan lou-lan force-pushed the heartbeat branch 4 times, most recently from 67ec51c to 1f5e3c9 Compare October 26, 2023 03:16
## Controller Failover

EgressGateway 控制面故障转移时,可以通过在安装时指定 `controller.replicas` 参数来控制 Controller 的副本数量。在多个 Controller 副本中的一个发生故障时,系统会自动选择另一个副本作为主要控制器,以确保服务的持续提供。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

说明下该功能 默认是 开启的,可通过 helm 什么选项 关闭

@weizhoublue
Copy link
Collaborator

weizhoublue commented Oct 27, 2023

单独开个 相关 用例 PR, 下个月再合入

Datapath Failover 问题排查步骤:

1. 首先,查看 EgressGateway 应用的安装配置文件 `values.yaml`,确认与 Datapath Failover 相关的配置是否设置合理,特别是确保 `eipEvictionTimeout` 的值大于 `tunnelMonitorPeriod` 加上 `tunnelUpdatePeriod` 的总和;
2. 执行 `kubectl get egt -w` 命令,检查 `EgressTunnel` 的状态。检查选中的 Node 是否处于 `HeartbeatTimeout` 状态,并且是否存在其他处于 `Ready` 状态的 `EgressTunnel`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

检查选中的 Node 是否处于.... 如果有,那么该怎么做


1. 首先,查看 EgressGateway 应用的安装配置文件 `values.yaml`,确认与 Datapath Failover 相关的配置是否设置合理,特别是确保 `eipEvictionTimeout` 的值大于 `tunnelMonitorPeriod` 加上 `tunnelUpdatePeriod` 的总和;
2. 执行 `kubectl get egt -w` 命令,检查 `EgressTunnel` 的状态。检查选中的 Node 是否处于 `HeartbeatTimeout` 状态,并且是否存在其他处于 `Ready` 状态的 `EgressTunnel`;
3. 如果想查询是否出现过 HeartbeatTimeout 导致的 IP 切换,可以在 controller 容器检索 `update tunnel status to HeartbeatTimeout` 相关的日志。
Copy link
Collaborator

@weizhoublue weizhoublue Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是一个后端式的运维,是否 进一步 把 出现过 的问题事件 以 cr 的 event 生成,产品化才能对接 告警,否则 没法 产品化 告警 这么高危的事件

@biqiangwu
Copy link
Contributor

1、心跳策略中关于时间参数的设置可以再讨论下
2、Agent 配置心跳探针是不是达到同等效果?

@lou-lan lou-lan force-pushed the heartbeat branch 3 times, most recently from 7352b79 to a2f10b8 Compare October 30, 2023 13:16
@lou-lan lou-lan merged commit e090e9c into main Oct 30, 2023
38 checks passed
@lou-lan lou-lan deleted the heartbeat branch October 30, 2023 13:33
@lou-lan lou-lan mentioned this pull request Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/feature-new feature pr recoded in new release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants