This knowledge base article provides instructions on configuring the ingress controller in Rancher RKE1 and RKE2 Kubernetes clusters to be exposed through a LoadBalancer service instead of the default host ports 80 and 443 on worker nodes. This is particularly useful when running a Kubernetes cluster on a cloud provider that supports automatic configuration and management of LoadBalancer services through Kubernetes's cloud provider integration.
这篇知识库文章提供了如何配置 Rancher RKE1 和 RKE2 Kubernetes 集群的入口控制器,使其通过 LoadBalancer 服务暴露,而不是工作节点默认的主机端口 80 和 443。这在运行支持通过 Kubernetes 云服务商集成自动配置和管理 LoadBalancer 服务的云服务提供商时,尤为有用。
Exposing the Ingress Controller with a LoadBalancer Service in:
在以下环境中通过负载均衡服务暴露入口控制器:
RKE1: RKE1:
In RKE1, it is not possible to directly configure the ingress-nginx controller with a LoadBalancer service through the ingress options in the cluster configuration. However, you can manually create a LoadBalancer service as shown below:
在 RKE1 中,无法通过集群配置中的入口选项直接配置 ingress-nginx 控制器与负载均衡器服务。不过,你可以手动创建负载均衡器服务,如下所示:
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#f3f3f3">apiVersion: v1 kind: Service metadata: name: ingress-nginx-lb namespace: ingress-nginx spec: ports: - name: http port: 80 protocol: TCP targetPort: 80 - name: https port: 443 protocol: TCP targetPort: 443 selector: app: ingress-nginx type: LoadBalancer </span></span></span>This will create a LoadBalancer service named "ingress-nginx-lb" in the "ingress-nginx" namespace, exposing ports 80 and 443.
这将在“ingress-nginx”命名空间中创建一个名为“ingress-nginx-lb”的负载均衡器服务,暴露端口 80 和 443。
This LoadBalancer service manifest can be added to the cluster via the user addons configuration, as documented at https://rke.docs.rancher.com/config-options/add-ons/user-defined-add-ons, to manage and deploy it alongside the cluster components/upgrades.
该 LoadBalancer 服务清单可以通过用户插件配置添加到集群,如 https://rke.docs.rancher.com/config-options/add-ons/user-defined-add-ons 文档所述,以便与集群组件/升级一同管理和部署。
RKE2: RKE2:
In RKE2, the ingress-nginx controller is managed through a Helm chart, allowing configuration changes using a HelmChartConfig resource. For more information see the following - https://docs.rke2.io/helm#customizing-packaged-components-with-helmchartconfig. Here is an example below of how to achieve this configuration.
在 RKE2 中,入口-nginx 控制器通过 Helm 图表管理,允许使用 HelmChartConfig 资源进行配置更改。更多信息请参见以下内容——https://docs.rke2.io/helm#customizing-packaged-components-with-helmchartconfig。下面是一个实现这种配置的示例。
<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#f3f3f3">apiVersion: <a>This configuration changes the ingress controller from a DaemonSet to a Deployment, sets the number of replicas to 3 for high availability, and updates the service type to LoadBalancer, enabling external access via a cloud load balancer. You should adjust the replica count based on the size and availability requirements of your environment.
该配置将入口控制器从守护进程集改为部署,将副本数量设置为3以实现高可用性,并将服务类型更新为负载均衡器,从而允许通过云负载均衡器进行外部访问。你应根据环境的规模和可用性需求调整副本数量。For standalone RKE2 clusters, this HelmChartConfig manifest can be defined within the manifests directory on server nodes, as documented at https://docs.rke2.io/helm#customizing-packaged-components-with-helmchartconfig.
对于独立的 RKE2 集群,这个 HelmChartConfig manifest 可以在服务器节点的 manifests 目录中定义,详见 https://docs.rke2.io/helm#customizing-packaged-components-with-helmchartconfig。
For Rancher-provisioned RKE2 clusters, this HelmChartConfig manifest can be defined within the cluster configuration under 'Additional Manifest'.
对于 Rancher 配置的 RKE2 集群,可以在集群配置中的“额外清单”下定义此 HelmChartConfig 清单。
An RKE or RKE2 cluster deployed with the bundled ingress-nginx ingress controller
随捆绑的 ingress-nginx 入口控制器部署的 RKE 或 RKE2 集群
访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009