【问题标题】:Unable to apply Nginx ingress controller无法应用 Nginx 入口控制器
【发布时间】:2021-10-19 02:59:10
【问题描述】:

我在本地系统中运行 3 个 VMS,每个 1 个主节点,2 个节点。我已经安装了编织 CNI 网络。我正在尝试使用

安装 Nginx 入口控制器
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.44.0/deploy/static/provider/cloud/deploy.yaml

但我无法创建它。我对 AWS Ec2 实例进行了同样的尝试。它总是崩溃 我看过描述 在 admission-create pod MountVolume.SetUp failed for volume "kube-api-access-kdhpc" : object "ingress-nginx"/"kube-root-ca.crt" not registered 中遇到此错误

admission-patch,controller pod 不断重启 控制器 pod 输出 我在这里有点震惊。我也尝试过使用法兰绒 cni,结果是一样的。 任何建议表示赞赏。

【问题讨论】:

  • 可能跑题了,只是因为你说你也试过法兰绒,你试过tigera.io/project-calico吗?
  • 是的,我也尝试过使用印花布。在 calico 中,calico pod 直接在循环中崩溃。
  • 您检查过 nginx-admission-patch pod 的日志吗?你能分享它们吗?入口控制器可能要到那时才会启动。
  • 我发现错误可能是版本问题。我将 k8s 从 1.22 版本降级到 1.18 版本,并且 pod 开始正常工作。我使用 metallb 来获取分配给入口外部端点的 ip。

标签: nginx kubernetes kubernetes-ingress nginx-ingress


【解决方案1】:

试试这些步骤,这些配置对我很有效。

入口控制器

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ingress-controller
  namespace: ingress-space
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nginx-ingress
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: nginx-ingress
    spec:
      containers:
      - args:
        - /nginx-ingress-controller
        - --configmap=$(POD_NAMESPACE)/nginx-configuration
        - --default-backend-service=app-space/default-http-backend
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
        imagePullPolicy: IfNotPresent
        name: nginx-ingress-controller
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        - containerPort: 443
          name: https
          protocol: TCP
      restartPolicy: Always
      serviceAccount: ingress-serviceaccount
      serviceAccountName: ingress-serviceaccount
      terminationGracePeriodSeconds: 30

入口服务

根据您的配置应用此 NodePort 或 LoadBalancer:

apiVersion: v1
kind: Service
metadata:
  name: ingress
  namespace: ingress-space
spec:
  ports:
  - name: http
    nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    nodePort: 31640
    port: 443
    protocol: TCP
    targetPort: 443
  selector:
    name: nginx-ingress
  type: NodePort

入口角色

您需要为入口创建一个服务帐户,您可以选择任何名称,应用这些rbac集群角色和集群角色绑定

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: ingress-role
rules:
- apiGroups:
  - ""
  resources:
  - services
  - endpoints
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - secrets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - configmaps
  verbs:
  - get
  - list
  - watch
  - update
  - create
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - patch
  - list
- apiGroups:
  - networking.k8s.io
  - extensions
  resources:
  - ingresses
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - networking.k8s.io
  resources:
  - ingressclasses
  verbs:
  - get
- apiGroups:
  - networking.k8s.io
  - extensions
  resources:
  - ingresses/status
  verbs:
  - update
- apiGroups:
  - k8s.nginx.org
  resources:
  - virtualservers
  - virtualserverroutes
  - globalconfigurations
  - transportservers
  - policies
  verbs:
  - list
  - watch
  - get
- apiGroups:
  - k8s.nginx.org
  resources:
  - virtualservers/status
  - virtualserverroutes/status
  - policies/status
  - transportservers/status
  verbs:
  - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: ingress-role-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: ingress-role
subjects:
- kind: ServiceAccount
  name: ingress-serviceaccount
  namespace: ingress-space

您的入口源已准备好安装,请参考https://kubernetes.io/docs/concepts/services-networking/ingress/ 并应用入口资源

【讨论】:

  • 我发现了这个问题。是k8s版本的问题。降级它并且它工作。豆荚产生了。用 metallb 分配 ip。但是当我尝试卷曲 pod 的外部 ip 时,我得到 ngnix 404 not found。知道问题可能出在哪里。我使用了 ingress 的默认 0.44 云 yaml 文件。
  • 如果您指的是负载均衡服务的外部 IP,可能是由于云配置,请确保您没有防火墙或安全组选项来禁止来自您的 IP 的流量。此外,请确保您正确设置了nginx.ingress.kubernetes.io/rewrite-target
  • 我已经确认没有防火墙在运行。我在默认的 yaml 文件中没有找到这个nginx.ingress.kubernetes.io/rewrite-target。如果可用,您能否分享一个示例文件或指导我在 yaml 文件中的哪个位置进行设置
  • 这里是链接kubernetes.github.io/ingress-nginx/examples/rewrite - 向下滚动一点
  • 抱歉回复晚了。感谢您的链接将检查它并更新您。
【解决方案2】:

我认为你应该使用这个(用于裸机)

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.31.1/deploy/static/provider/baremetal/deploy.yaml

关注这篇文章:

Nginx Ingress Controller - Failed Calling Webhook

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    相关资源
    最近更新 更多