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 multiple ingress controller support + traefik #5943

Merged
merged 3 commits into from
Jul 10, 2024

Conversation

brandond
Copy link
Member

@brandond brandond commented May 21, 2024

Waiting on:


Proposed Changes

  • Add ADR for multiple ingress controller support; initially with traefik as the only additional packaged ingress controller.
  • Add CLI flag to select ingress controllers; multiple may be chosen, and --ingress-controller=none will disable all of them, same as --cni=none.
  • Update charts

Note: while multiple ingress controllers can be selected via the CLI flag, and the first one will be set as the default ingress class, additional user-provided configuration will be necessary to allow both ingress controllers to run in parallel , due to both charts defaulting to deploying a DaemonSet that binds to ports 80 and 443. For this reason, while allowed by the CLI flag, we will not be supporting parallel installation of multiple ingress controllers.

If someone did want to do it on a cluster with a LoadBalancer controller capable of binding multiple LoadBalancer services on the same ports, something like this would work to reconfigure both controllers to use Deployment+LoadBalancer instead of Daemonset+HostPort:

apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
  name: rke2-ingress-nginx
  namespace: kube-system
spec:
  valuesContent: |-
    controller:
      kind: Deployment
      hostPort:
        enabled: false
      service:
        enabled: true
        type: LoadBalancer
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
  name: rke2-traefik
  namespace: kube-system
spec:
  valuesContent: |-
    deployment:
      kind: Deployment
    service:
      enabled: true
      type: LoadBalancer
    ports:
      web:
        hostPort: null
      websecure:
        hostPort: null

Types of Changes

ADR; packaged component

Verification

  • See linked issue and ADR
    1. Start rke2 with one or more ingress controllers selected by --ingress-controller flag
    2. Note that selected ingress controller charts are installed and ingressClass resources created.
    3. Note that the first selected ingressClass has annotation ingressclass.kubernetes.io/is-default-class: "true"; others are false or absent.
    4. Note that Ingress resources are picked up by the default ingress controller if the ingressClassName is not set, and the selected ingress controller if ingressClassName is set to one of the installed controller names.
brandond@dev01:~$ kubectl get node -o 'custom-columns=NAME:.metadata.name,NODE-ARGS:metadata.annotations.rke2\.io/node-args'
NAME            NODE-ARGS
rke2-server-1   ["server","--ingress-controller","traefik,ingress-nginx"]

brandond@dev01:~$ kubectl get ingressclass -o 'custom-columns=NAME:.metadata.name,CONTROLLER:.spec.controller,DEFAULT:.metadata.annotations.ingressclass\.kubernetes\.io/is-default-class'
NAME      CONTROLLER                      DEFAULT
nginx     k8s.io/ingress-nginx            <none>
traefik   traefik.io/ingress-controller   true

Testing

Linked Issues

User-Facing Change


Further Comments

@brandond brandond requested a review from a team as a code owner May 21, 2024 20:50
@brandond brandond force-pushed the traefik-ingress branch 3 times, most recently from c3faab8 to 66eabcd Compare May 22, 2024 03:19
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2024

Codecov Report

Attention: Patch coverage is 3.57143% with 54 lines in your changes missing coverage. Please review.

Project coverage is 25.82%. Comparing base (311b3a5) to head (e56bb43).
Report is 3 commits behind head on master.

Files Patch % Lines
pkg/cli/cmds/server.go 0.00% 46 Missing ⚠️
pkg/bootstrap/bootstrap.go 0.00% 4 Missing ⚠️
pkg/rke2/rke2_linux.go 50.00% 1 Missing and 1 partial ⚠️
pkg/podexecutor/staticpod.go 0.00% 1 Missing ⚠️
pkg/rke2/rke2.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5943       +/-   ##
===========================================
+ Coverage    9.77%   25.82%   +16.05%     
===========================================
  Files          32       32               
  Lines        2712     2734       +22     
===========================================
+ Hits          265      706      +441     
+ Misses       2425     1981      -444     
- Partials       22       47       +25     
Flag Coverage Δ
inttests 9.69% <0.00%> (-0.08%) ⬇️
unittests 18.39% <3.57%> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brandond brandond force-pushed the traefik-ingress branch 4 times, most recently from 0d0377a to 5431573 Compare May 22, 2024 19:19
pkg/cli/cmds/server.go Show resolved Hide resolved
// prepare a list of items to disable, based on all valid components.
// we have to use an intermediate set because the flag interface
// doesn't allow us to remove flag values once added.
disabledCharts := sets.Set[string]{}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we need a set instead of a slice. If I understand correclty, the "values" are always slices that we are hardcoding with rke2 components in "pkg/rke2/rke2.go", e.g. CNIItems

Copy link
Member Author

@brandond brandond May 23, 2024

Choose a reason for hiding this comment

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

I made it a set so that I can easily remove entries from it by value, without having to find their indexes in the slice and elide them. It'd be much more boilerplate code than just the Insert() and Delete() functions that sets provide. I could use a map[string]struct{} and insert/delete keys but generic sets are implemented as a map[comparable]struct{} under the hood anyway:
https://github.com/kubernetes/apimachinery/blob/master/pkg/util/sets/set.go#L24-L25

Copy link
Contributor

Choose a reason for hiding this comment

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

aaah ok, I was thinking on the property that no copies are possible in sets by default and that did not make sense here. Thanks

docs/adrs/008-traefik-ingress.md Show resolved Hide resolved
@@ -105,7 +106,7 @@ func (p *PEBinaryConfig) Bootstrap(ctx context.Context, nodeConfig *config.Node,
}

if p.IsServer {
return bootstrap.UpdateManifests(p.Resolver, nodeConfig, cfg)
return bootstrap.UpdateManifests(p.Resolver, p.IngressController, nodeConfig, cfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have just realized that if we ever reach this line, something would be broken because windows can never be the server. What if we use this PR to add an error message instead saying that this is not supported?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wired it up here in case we ever do support windows server nodes. I don't think it needs to be an error, it's just not a code path that is reachable at the moment.

@brandond brandond force-pushed the traefik-ingress branch 2 times, most recently from ec51387 to 6f53be4 Compare May 23, 2024 19:11
* Add new --ingress-controller CLI flag
* Refactor --ingress-controller and --cni flags to use common helper for
  disabling all unused charts
* Wire first ingress controller name into global.systemDefaultIngressClass
  chart variable

Signed-off-by: Brad Davidson <[email protected]>
Signed-off-by: Brad Davidson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants