我在此链接 https://kubernetes.io/blog/2019/07/23/get-started-with-kubernetes-using-python/ 之后创建了 python 应用程序.我要配置AWS ALB Ingress Controller/nginx controller
和 ingress 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/