【问题标题】:unable to configure NGINX Ingress Controller无法配置 NGINX 入口控制器
【发布时间】:2019-09-12 00:56:17
【问题描述】:

我有一个 eks 集群,我的部署、服务和 loadBalancer 都工作正常。每个服务创建自己的 LoadBalancer,所有服务都启动并运行。我有一个前端服务和 2 个后端服务 这是我的部署和入口文件

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache-kubernetes
spec:
  replicas: 2
  selector:
    matchLabels:
      app: apache-kubernetes
  template:
    metadata:
      labels:
        app: apache-kubernetes
    spec:
      containers:
      - name: apache-kubernetes
        image: httpd
        ports:
        - containerPort: 80
        env:
        - name: MESSAGE
          value: Hello Kubernetes!
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-apache-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"

spec:
  rules:
  - host: apache.example.com
  - http:
      paths:
      - path: /
        backend:
          serviceName: apache-kubernetes
          servicePort: 80

我有一个类似的部署和服务 yaml 文件,它部署并创建了一个 nginx Web 服务器。我还运行了以下命令 所有部署都需要以下强制命令。

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml

如该网址中所述https://kubernetes.github.io/ingress-nginx/deploy/#aws

然后我运行这两个命令 kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/service-l4.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/patch-configmap-l4.yaml

我运行kubectl get all,我看到我的 pod、replicatsets 和部署运行良好,

kubectl get ingress shows 
hosts                 ADDRESS
apache.example.com   216990309c-1626238635.us-east-2.elb.amazonaws.com
nginx.example.com    216990309c-1626238635.us-east-2.elb.amazonaws.com

我期待当我点击 apache.example.com 时——它应该显示“它有效” 并且 Nginx.example.com 应该显示“欢迎 Nginx”

我这样做对吗

浏览器 ==>ALB==>ingresscontroller==>ekscluster

更新 1

当我点击 url 时,我得到 503,但 pod 正在运行

kubectl -n ingress-nginx 记录 nginx-ingress-controller-db5f9d7b5-cwwh2

给我

6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:02.505451       6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store
W0911 23:43:20.846517       6 controller.go:781] Error obtaining Endpoints for Service "default/hello-kubernetes": no object matching key "default/hello-kubernetes" in local store
W0911 23:43:20.846540       6 controller.go:781] Error obtaining Endpoints for Service "default/nginx-kubernetes": no object matching key "default/nginx-kubernetes" in local store

【问题讨论】:

  • 尝试更新您的问题并使其更加清晰。谢谢。
  • 您未能指定当您点击这些网址时会发生什么;也就是说,入口控制器是基于虚拟主机的,所以你需要类似于 curl -v -H "host: apache.example.com" http://216990309c-1626238635.us-east-2.elb.amazonaws.com 的东西(或者,当然,有 DNS 条目,但我的意思是仅用于测试)
  • @Yasen 不清楚哪一部分,我会尽量具体一点

标签: kubernetes nginx-ingress amazon-eks


【解决方案1】:

所以只是一个想法(我可能错过了阅读您的问题)但入口控制器不会直接路由到您的部署,它需要一个服务来路由,所以在您的情况下,您必须创建一个服务像这样:

apiVersion: v1
kind: Service
metadata:
  name: apache-kubernetes
spec:
  selector:
    app: apache-kubernetes
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

然后,这将配置 nginx 入口,其中包含要路由到的端点,您在入口中指定的位置:

...
paths:
      - path: /
        backend:
          serviceName: apache-kubernetes
          servicePort: 80

这将指向服务而不是部署

流程(从逻辑上讲,就像 nginx 入口为更少的跳数做了一些魔术):

浏览器 ==>ALB==>ekscluster==>ingresscontroller==>service==>pod

【讨论】:

  • 我支持这个。确实缺少服务:)
猜你喜欢
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 1970-01-01
  • 2020-01-08
  • 2020-03-01
  • 1970-01-01
  • 2023-02-06
  • 2018-05-14
相关资源
最近更新 更多