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

ovn lb select the local chassis's backend prefer #4894

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

changluyi
Copy link
Collaborator

@changluyi changluyi commented Jan 2, 2025

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

目前只改了ovn 部分代码,kube-ovn 代码还在开发,可以暂时使用slr的配置:配置模板入下:

kind: SwitchLBRule
metadata:
  name:  cjh-slr-nginx
spec:
  vip: 1.1.1.1
  sessionAffinity: ClientIP
  namespace: default
  selector:
    - app:nginx
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - nginx
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: nginx-container
        image: nginx:alpine
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

实现原理是获取到vip backend的 chassis , 新增加流表入下:

is_chassis_resident("nginx-6f55f97f94-8kvlx.default") , 其中 nginx-6f55f97f94-8kvlx.default 是某个vip 的backend下的任意一个lsp,backends=10.16.0.3:80 表示这个lb 在这个chassis下的所有backendip: port 。

  table=13(ls_in_lb           ), priority=140  , match=(ct.new && ip4.dst == 1.1.1.1 && tcp.dst == 80 && is_chassis_resident("nginx-6f55f97f94-8kvlx.default")), action=(ct_lb_mark(backends=10.16.0.3:80; hash_fields="ip_src");)
  table=13(ls_in_lb           ), priority=140  , match=(ct.new && ip4.dst == 1.1.1.1 && tcp.dst == 80 && is_chassis_resident("nginx-6f55f97f94-zlr4p.default")), action=(ct_lb_mark(backends=10.16.0.2:80; hash_fields="ip_src");)

如果hit不到以上流表,就会走原来的ovn lb 规则。

该功能需要配置Load_balancer的 两个字段
option:prefer_local_backend

option:prefer_local_backend=true

ip_port_mappings

"10.16.0.10"="nginx-6f55f97f94-m4bxx.default:10.16.0.4", "10.16.0.2"="nginx-6f55f97f94-zlr4p.default:10.16.0.4", "10.16.0.3"="nginx-6f55f97f94-8kvlx.default:10.16.0.4", "10.16.0.5"="nginx-6f55f97f94-ns9th.default:10.16.0.4"

Which issue(s) this PR fixes

Fixes #(issue-number)

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 2, 2025
@coveralls
Copy link

coveralls commented Jan 2, 2025

Pull Request Test Coverage Report for Build 12684623577

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 22.083%

Totals Coverage Status
Change from base Build 12674528419: 0.004%
Covered Lines: 10166
Relevant Lines: 46035

💛 - Coveralls

@changluyi changluyi force-pushed the lb_service_select_local_backend branch from 93b8ed4 to 318cff3 Compare January 6, 2025 03:06
@changluyi changluyi changed the title template test ovn lb select the local chassis's backend prefer Jan 6, 2025
@changluyi changluyi added feature New network feature enhancement Improve exist functions labels Jan 6, 2025
@changluyi changluyi force-pushed the lb_service_select_local_backend branch from 318cff3 to cdbf329 Compare January 7, 2025 11:30
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jan 7, 2025
@changluyi changluyi force-pushed the lb_service_select_local_backend branch from cdbf329 to ffd7994 Compare January 8, 2025 02:47
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 8, 2025
@changluyi changluyi force-pushed the lb_service_select_local_backend branch from ffd7994 to 21e47a8 Compare January 9, 2025 05:30
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jan 9, 2025
@changluyi changluyi force-pushed the lb_service_select_local_backend branch from 21e47a8 to 2ade8ff Compare January 9, 2025 05:31
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jan 9, 2025
@changluyi changluyi force-pushed the lb_service_select_local_backend branch from 2ade8ff to add2969 Compare January 9, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve exist functions feature New network feature size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants