简体   繁体   English

如何使用 nginx 入口将流量从 route53 中的域转发到 pod?

[英]How to forward traffic from domain in route53 to a pod using nginx ingress?

I deployed grafana using helm and now it is running in pod.我使用 helm 部署了 grafana,现在它在 pod 中运行。 I can access it if I proxy port 3000 to my laptop.如果我将端口 3000 代理到我的笔记本电脑,我就可以访问它。 Im trying to point a domain grafana.something.com to that pod so I can access it externally.我试图将域grafana.something.com指向该 pod,以便我可以从外部访问它。 I have a domain in route53 that I can attach to a loadbalancer (Application Load Balancer, Network Load Balancer, Classic Load Balancer).我在 route53 中有一个域,我可以将其附加到负载均衡器(应用程序负载均衡器、网络负载均衡器、传统负载均衡器)。 That load balancer can forward traffic from port 80 to port 80 to a group of nodes (Let's leave port 443 for later).该负载均衡器可以将流量从端口 80 转发到端口 80 到一组节点(让我们将端口 443 留待稍后)。 I'm really struggling with setting this up.我真的很难设置这个。 Im sure there is something missing but I don't know what.我确定缺少一些东西,但我不知道是什么。

Basic diagram would look like this I imagine.基本图看起来像我想象的这样。

Internet互联网
↓↓ ↓↓
Domain in route53 (grafana.something.com) route53 中的域 (grafana.something.com)
↓↓ ↓↓
Loadbalancer 80 to 80 (Application Load Balancer, Network Load Balancer, Classic Load Balancer) I guess that LB would forward traffic to port 80 to the below Ingress Controllers (Created when Grafana was deployed using Helm)负载均衡器 80 到 80(应用程序负载均衡器、网络负载均衡器、经典负载均衡器)我猜 LB 会将流量转发到端口 80 到下面的入口控制器(在使用 Helm 部署 Grafana 时创建)
↓↓ ↓↓
Group of EKS worker nodes EKS 工作节点组
↓↓ ↓↓
Ingress resource ?????入口资源???
↓↓ ↓↓
Ingress Controllers - Created when Grafana was deployed using Helm in namespace test.入口控制器 - 在命名空间测试中使用 Helm 部署 Grafana 时创建。

kubectl get svc grafana -n test

grafana Type:ClusterIP ClusterIP:10.xxx Port:80/TCP

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 
  labels:
    app: grafana
    chart: grafana-
    heritage: Tiller
    release: grafana-release
  name: grafana
  namespace: test
  resourceVersion: "xxxx"
  selfLink: 
  uid: 
spec:
  clusterIP: 10.x.x.x
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    app: grafana
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

↓↓ ↓↓
Pod Grafana is listening on port 3000. I can access it successfully after proxying to my laptop port 3000. Pod Grafana 正在监听端口 3000。我可以在代理到我的笔记本电脑端口 3000 后成功访问它。

Given that it seems you don't have an Ingress Controller installed, if you have the aws cloud-provider configured in your K8S cluster you can follow this guide to install the Nginx Ingress controller using Helm. 鉴于您似乎没有安装Ingress Controller ,如果您在K8S群集中配置了aws云提供程序,则可以按照本指南使用Helm安装Nginx Ingress控制器。

By the end of the guide you should have a load balancer created for your ingress controller, point your Route53 record to it and create an Ingress that uses your grafana service. 在本指南的最后,您应该为入口控制器创建一个负载均衡器,将Route53记录指向它并创建一个使用您的grafana服务的Ingress。 Example: 例:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/app-root: /
    nginx.ingress.kubernetes.io/enable-access-log: "true"
  name: grafana-ingress
  namespace: test
spec:
  rules:
  - host: grafana.something.com
    http:
      paths:
      - backend:
          serviceName: grafana
          servicePort: 80
        path: /

The final traffic path would be: 最终的交通路径是:

Route53 -> ELB -> Ingress -> Service -> Pods

Adding 2 important suggestions here.在此添加 2 个重要建议。

1 ) Following improvements to the ingress api in kubernetes 1.18 - a new ingressClassName field has been added to the Ingress spec that is used to reference the IngressClass that should be used to implement this Ingress. 1 ) 在 kubernetes 1.18 中对 ingress api 的改进之后 - Ingress 规范中添加了一个新的ingressClassName字段,用于引用应该用于实现此 Ingress 的 IngressClass。
Please consider to switch to ingressClassName field instead of the kubernetes.io/ingress.class annotation :请考虑切换到ingressClassName字段而不是kubernetes.io/ingress.class注释

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: grafana-ingress
  namespace: test
spec:
  ingressClassName: nginx # <-- Here
  rules:
    - host: grafana.something.com
      http:
        paths:
          - path: /
            backend:
              serviceName: grafana
              servicePort: 80

2 ) Consider using External-DNS for the integration between external DNS servers (Check this example on AWS Route53) and the Kubernetes Ingresses / Services. 2 )考虑使用外部 DNS来集成外部 DNS 服务器(在 AWS Route53 上查看示例)和 Kubernetes 入口/服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM