环境
K3s 1.27+ (may apply to other versions)
K3s 1.27+(可能适用于其他版本)
情况
Important: Ingress NGINX Deprecation Per the Kubernetes announcement, Ingress NGINX is retired in March 2026. After this date, upstream will no longer provide security patches or bug fixes. Traefik is the default supported Ingress Controller bundled with K3s, and its use is recommended, rather than maintaining a custom Ingress NGINX installation.
重要提示:Ingress NGINX 弃用 根据 Kubernetes 公告 ,Ingress NGINX 将于 2026 年 3 月退役。此后,上游将不再提供安全补丁或漏洞修复。Traefik 是 K3s 默认支持的 Ingress 控制器,建议使用它,而不是维护自定义的 Ingress NGINX 安装。
Task  任务

This knowledge base article will provide the directions for deploying NGINX instead of Traefik as your Kubernetes ingress controller on K3s. Please note that Traefik is the supported ingress controller for K3s and NGINX is not officially supported by SUSE Rancher support.
这篇知识库文章将提供如何在 K3s 上部署 NGINX 而不是 Traefik 作为 Kubernetes 入口控制器的指导。请注意,Traefik 是 K3s 支持的入口控制器,而 NGINX 并未获得 SUSE Rancher 官方支持。

Background  背景

By default, K3s uses Traefik as the ingress controller for your cluster. The decision to use Traefik over NGINX was based on multi-architecture support across x86 and ARM based platforms. Normally Traefik meets the needs of most Kubernetes clusters. However, there are unique use cases where NGINX may be required or preferred. If you don't think you need NGINX, it's recommended to stick with Traefik.
默认情况下,K3s 使用 Traefik 作为你集群的入口控制器。选择 Traefik 而非 NGINX 的决定基于跨 x86 和 ARM 平台的多架构支持。通常 Traefik 满足大多数 Kubernetes 集群的需求。然而,在某些特殊情况下,NGINX 可能是必需或偏好的。如果你觉得不需要 NGINX,建议继续用 Traefik。

    解决方案

    The first step to using NGINX or any alternative ingress controller is to tell K3s that you do not want to deploy Traefik. When installing K3s add the following --no-deploy traefik flag to the INSTALL_K3S_EXEC environment variable.  Or in some cases, you may need a --disable traefik option instead:
    使用 NGINX 或其他入口控制器的第一步是告诉 K3s 你不想部署 Traefik。安装 K3s 时,在 INSTALL_K3S_EXEC 环境变量中添加以下 --no-deploy traefik 标志。 或者在某些情况下,你可能需要一个 --disable traefik 选项:

    curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--no-deploy traefik" sh -s -
    or
    curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik" sh -s -
    If you have already downloaded the k3s.sh install script, you can run the following:
    INSTALL_K3S_EXEC="--no-deploy traefik" k3s.sh
    or
    INSTALL_K3S_EXEC="--disable traefik" k3s.sh
     
    This will install the K3s server and form a single node cluster. You can confirm the cluster is operational ("Ready") by running:
    $ kubectl get nodes
    NAME                         STATUS   ROLES                  AGE     VERSION
    ubuntu-s-2vcpu-4gb-nyc1-01   Ready    control-plane,master   3h35m   v1.30.4+k3s1
     
    Note, if you already had the kubectl binary installed on your host and it is not configured correctly, you may need to run k3s kubectl instead of kubectl.
    如果你已经下载了 k3s.sh 安装脚本,可以运行以下程序: 这样可以安装 K3s 服务器,形成单节点集群。您可以通过运行以下程序确认集群已运行(“准备就位”): 注意,如果你主机上已经安装了 kubectl 二进制文件但配置不正确,可能需要运行 k3s kubectl 代替 kubectl

    Next, confirm your out-of-box pods are running and Traefik is not running:
    接下来,确认你的开箱舱是否运行,而 Traefik 没有运行:

    $ kubectl get pods -A
    NAMESPACE       NAME                                      
    READY   STATUS      RESTARTS   AGE
    kube-system     coredns-576bfc4dc7-n4k72                  
    1/1     Running     0          3h47m
    kube-system     local-path-provisioner-6795b5f9d8-mzwb8   
    1/1     Running     0          3h47m
    kube-system     metrics-server-557ff575fb-ntkh6           
    1/1     Running     0          3h47m
     
    K3s has a nice feature that allows you to deploy Helm Charts by placing a HelmChart YAML in /var/lib/rancher/k3s/server/manifests. Create this file by running:
    cat >/var/lib/rancher/k3s/server/manifests/ingress-nginx.yaml <<EOF
    apiVersion: v1
    kind: Namespace
    metadata:
      name: ingress-nginx
    ---
    apiVersion: helm.cattle.io/v1
    kind: HelmChart
    metadata:
      name: ingress-nginx
      namespace: kube-system
    spec:
      chart: ingress-nginx
      repo: https://kubernetes.github.io/ingress-nginx
      targetNamespace: ingress-nginx
      version: v4.11.2
      set:
      valuesContent: |-
        fullnameOverride: ingress-nginx
        controller:
          kind: DaemonSet
          hostNetwork: true
          hostPort:
            enabled: true
          service:
            enabled: false
          publishService:
            enabled: false
          metrics:
            enabled: true
            serviceMonitor:
              enabled: false
          config:
            use-forwarded-headers: "true"
    EOF
     
    K3s periodically polls the manifests folder and applies the YAML in these files. After about a minute, you should see new pods running, including the NGINX Ingress Controller and default backend:
    $ kubectl get pods -A
    NAMESPACE       NAME                                      READY   STATUS      RESTARTS   AGE
    ingress-nginx   ingress-nginx-controller-t25nm            1/1     Running     0          34m
    kube-system     coredns-576bfc4dc7-n4k72                  1/1     Running     0          3h49m
    kube-system     helm-install-ingress-nginx-bfcgs          0/1     Completed   0          35m
    kube-system     local-path-provisioner-6795b5f9d8-mzwb8   1/1     Running     0          3h49m
    kube-system     metrics-server-557ff575fb-ntkh6           1/1     Running     0          3h49m
     
    You'll also see a helm-install-ingress-nginx pod in your environment. K3s uses this pod to deploy the Helm Chart and it's normal for it to be in a READY=0/1 and STATUS=Completed state once the Helm Chart has been successfully deployed. In the event your Helm Chart failed to deploy, you can view the logs of this pod to troubleshoot further.
    K3s 有一个不错的功能,可以通过在 中放置 HelmChart YAML 来 /var/lib/rancher/k3s/server/manifests 部署 Helm Charts 通过运行以下方式创建此文件: K3s 会定期轮询 manifests 文件夹,并在这些文件中应用 YAML。大约一分钟后,你应该会看到新的 Pods 正在运行,包括 NGINX Ingress 控制器和默认后端: 你还会在环境中看到一个 helm-install-ingress-nginx 舱。K3s 使用该舱体部署舵仪图,正常情况下,舵手图成功部署后,舱体通常处于 READY=0/1 和 STATUS=Completed 状态。如果您的舵手图未能部署,您可以查看该舱的日志以便进一步排查。
      原因
      Logo

      欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

      更多推荐