amazon-web-services - 用于 python 应用程序的 AWS ALB 入口 Controller 和入口资源

标签 amazon-web-services kubernetes kubernetes-ingress nginx-ingress aws-alb

我在此链接 https://kubernetes.io/blog/2019/07/23/get-started-with-kubernetes-using-python/ 之后创建了 python 应用程序.我要配置AWS ALB Ingress Controller/nginx controlleringress resource但我无法理解该文件。我没有在 ec2-instance 上使用 Kops 的域,想在没有任何域的情况下对其进行配置。任何帮助,将不胜感激。
部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-python
spec:
  selector:
    matchLabels:
      app: hello-python
  template:
    metadata:
      labels:
        app: hello-python
    spec:
      containers:
      - name: hello-python
        image: hello-python:latest
        ports:
        - containerPort: 5000
服务
apiVersion: v1
kind: Service
metadata:
  name: hello-python-service
spec:
  selector:
    app: hello-python
  type: NodePort
  ports:
    - nodePort: 30010
      port: 6000
      targetPort: 5000

最佳答案

一个 Ingress 绑定(bind)一个像 hello-python-service 这样的服务。上面通过 nginx 入口 Controller 到 ALB。
它通过将虚拟主机映射到您的服务来做到这一点,以便 nginx 知道如何路由请求。
例子:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: python-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: ingress-controller-nginx
    nginx.ingress.kubernetes.io/default-backend: hello-python-service
    nginx.ingress.kubernetes.io/rewrite-target: /$1

spec:
  rules:
    - host: python.trash.net
      http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: hello-python-service
              servicePort: 6000
将生成类 Ingress 的资源如下所示:
python-ingress   python.trash.net   internal-0358a08f01385b2812-331143124.us-east-2.elb.amazonaws.com   80      10s
发出这样的 curl 请求:
curl -H "Host: python.trash.net" http://internal-0358a08f01385b2812-331143124.us-east-2.elb.amazonaws.com
应该让您从您的 hello python 应用程序中获得响应。
这显然取决于您在 EKS 集群中部署和配置了 nginx 入口 Controller 。
入口的关键要点是:它取代了对 LoadBalancer 类型的专用服务的需求,以提供对您服务的外部访问。相反,Ingress 通过在 Ingress list 文件中配置的虚拟主机将来自集群外部的流量映射到集群中的服务。

关于amazon-web-services - 用于 python 应用程序的 AWS ALB 入口 Controller 和入口资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64262229/

相关文章:

docker - node_modules 的 kubernetes 卷

docker - 如何启动一个简单的容器?

amazon-web-services - Kubernetes - Ingress-nginx 路由错误(无法将前端连接到后端)

kubernetes - NGINX Ingress 上的全局静态 IP 名称

kubernetes - 如何在OpenShift上为我的应用程序选择名称

certificate - 如何用通配符证书替换 "Kubernetes fake certificate"(在裸机私有(private)云上)Nginx Ingress 和证书管理器

amazon-web-services - 如何移除/撤消/删除 Amazon Aurora RDS 上的待处理修改?

amazon-web-services - 两个 aws cloudformation 堆栈可以共享一个 AWS::Serverless::Function 吗?

amazon-web-services - AWS CodeDeploy 能否为 lambda 进行跨账户部署?

amazon-web-services - 任务节点上具有多个横向扩展规则的 EMR 自动扩展行为