我们有两个入口控制器和两个单独的服务,如下所示,请求相同的部署(POD)。下面是服务定义。
kind: Service
metadata:
name: service-1
spec:
selector:
app: backend
ports:
- protocol: TCP
port: 80
type: NodePort
kind: Service
metadata:
name: service-2
spec:
selector:
app: backend
ports:
- protocol: TCP
port: 80
type: NodePort
入口定义如下
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: backend-1
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=150
namespace: staging
spec:
rules:
- host: domain.com
http:
paths:
- path: /*
backend:
serviceName: service-1
servicePort: 80
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: backend-2
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=150
namespace: staging
spec:
rules:
- host: different_domain_name.com
http:
paths:
- path: /*
backend:
serviceName: service-2
servicePort: 80
当请求到达POD时,是否有一种方法可以识别哪个服务/入口接收并处理了该请求。
理想情况下,我可以在服务或入口级别设置一些env变量,以便我可以在Pod中访问这些变量吗?
任何帮助如何实现这一点将是伟大的,谢谢。
1条答案
按热度按时间smdncfj31#
无法将env变量添加到Service或Ingress级别。Service只是一个逻辑集合或绑定的pod发送流量,你不能在那里添加任何东西。对于Ingress,您可以添加头