130. 在 RKE1 和 RKE2 的 Kubernetes 集群中,通过负载均衡服务暴露 ingress-nginx 控制器

张开发
2026/4/18 17:47:11 15 分钟阅读

分享文章

130. 在 RKE1 和 RKE2 的 Kubernetes 集群中,通过负载均衡服务暴露 ingress-nginx 控制器
Situation 地理位置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 Kubernetess cloud provider integration.这篇知识库文章提供了如何配置 Rancher RKE1 和 RKE2 Kubernetes 集群的入口控制器使其通过 LoadBalancer 服务暴露而不是工作节点默认的主机端口 80 和 443。这在运行支持通过 Kubernetes 云服务商集成自动配置和管理 LoadBalancer 服务的云服务提供商时尤为有用。Resolution 结局Exposing the Ingress Controller with a LoadBalancer Service in:在以下环境中通过负载均衡服务暴露入口控制器RKE1: RKE1In 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 stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#f3f3f3apiVersion: 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/spanThis 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: RKE2In 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 stylecolor:#000000span stylebackground-color:#ffffffspan stylebackground-color:#f3f3f3apiVersion: 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 清单。Cause 病因Additional Information 附加信息Environment 环境An RKE or RKE2 cluster deployed with the bundled ingress-nginx ingress controller随捆绑的 ingress-nginx 入口控制器部署的 RKE 或 RKE2 集群访问Rancher-K8S解决方案博主企业合作伙伴 https://blog.csdn.net/lidw2009

更多文章