指向 ExternalName 服务的 GKE Ingress 不起作用
GKE Ingress pointing to ExternalName service doesn't work
首先,我要建造的就在下面。
如上图所示,我希望 Ingress 将流量分发到同一集群中其他命名空间 me
中的服务。 (Ingress 在 main
命名空间中)但是 Ingress 不允许直接指向 dns,我让 ExternalName Service 指向 me-service
dns me-service.me.svc.cluster.local
然后 Ingress 指向它。
它的 Yaml 是
主.k8s.yaml
apiVersion: v1
kind: Namespace
metadata:
name: main
---
apiVersion: v1
kind: Service
metadata:
name: me-service
namespace: main
spec:
externalName: me-service.me.svc.cluster.local
type: ExternalName
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: gce
name: main-router
namespace: main
spec:
rules:
- host: some-domain.me
http:
paths:
- backend:
service:
name: me-service
port:
number: 80
path: /
pathType: ImplementationSpecific
我.k8s.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
stag: production
name: me
---
apiVersion: v1
kind: Service # <-- this is the service I want to point
metadata:
labels:
app: me
stag: production
name: me-service
namespace: me
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: me
stag: production
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: me
stag: production
name: me-deployment
namespace: me
spec:
replicas: 2
selector:
matchLabels:
app: me
stag: production
template:
metadata:
labels:
app: me
stag: production
spec:
containers:
- image: gcr.io/me:latest
name: me
ports:
- containerPort: 80
resources:
limits:
cpu: 300m
memory: 512M
requests:
cpu: 250m
memory: 512M
我检查了 dns 地址是否有效,但未创建 Ingress 对象并显示错误消息
me-service:80 (<error: endpoints "me-service" not found>)
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Translate 6m21s (x233 over 22h) loadbalancer-controller Translation failed: invalid ingress spec: could not find port "80" in service "main/me-service"
我怎样才能让 ingress 工作?如果您需要更多信息,请告诉我。 :祈祷:
GKE 引擎:1.20.6-gke.1000
HTTP 负载平衡:已启用
网络策略:禁用
Dataplane V2:启用
我将其作为答案发布是为了提高可见度。正如我在评论中提到的:
据我所知,您不能将 GKE ingress 与 ExternalName
服务类型一起使用。支持的两种类型是 LoadBalancer
和 NodePort
。如果最近没有任何变化,即使使用简单的 ClusterIP
,您也不应该能够创建入口资源,只有上面提到的两种 svc 类型,所以我不相信 ExternalName
会起作用。好吧,您实际上可以使用 ClusterIP
,但前提是您使用 container native load balancing,这需要您的 GKE 集群是 VPC 原生的。
您仍然可以使用 GKE,但您不必同时使用 GCE ingress 作为入口控制器。但如果它不适用于提到的容器原生负载平衡,我会先尝试。
您始终可以在 GKE 集群上部署 不同的入口控制器,例如nginx-ingress。它可以使用开箱即用的 ClusterIP
服务,但我不确定它是否可以处理 ExternalName
所以你必须尝试一下。
OP 确认使用 nginx-ingress 可以将流量分配到位于不同命名空间的服务:
@mario Thank you for your comment. I successfully distribute traffics
to other namespace svc using NGINX-ingress. – HyeonJunOh Jul 23 at
9:23
首先,我要建造的就在下面。
如上图所示,我希望 Ingress 将流量分发到同一集群中其他命名空间 me
中的服务。 (Ingress 在 main
命名空间中)但是 Ingress 不允许直接指向 dns,我让 ExternalName Service 指向 me-service
dns me-service.me.svc.cluster.local
然后 Ingress 指向它。
它的 Yaml 是
主.k8s.yaml
apiVersion: v1
kind: Namespace
metadata:
name: main
---
apiVersion: v1
kind: Service
metadata:
name: me-service
namespace: main
spec:
externalName: me-service.me.svc.cluster.local
type: ExternalName
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: gce
name: main-router
namespace: main
spec:
rules:
- host: some-domain.me
http:
paths:
- backend:
service:
name: me-service
port:
number: 80
path: /
pathType: ImplementationSpecific
我.k8s.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
stag: production
name: me
---
apiVersion: v1
kind: Service # <-- this is the service I want to point
metadata:
labels:
app: me
stag: production
name: me-service
namespace: me
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: me
stag: production
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: me
stag: production
name: me-deployment
namespace: me
spec:
replicas: 2
selector:
matchLabels:
app: me
stag: production
template:
metadata:
labels:
app: me
stag: production
spec:
containers:
- image: gcr.io/me:latest
name: me
ports:
- containerPort: 80
resources:
limits:
cpu: 300m
memory: 512M
requests:
cpu: 250m
memory: 512M
我检查了 dns 地址是否有效,但未创建 Ingress 对象并显示错误消息
me-service:80 (<error: endpoints "me-service" not found>)
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Translate 6m21s (x233 over 22h) loadbalancer-controller Translation failed: invalid ingress spec: could not find port "80" in service "main/me-service"
我怎样才能让 ingress 工作?如果您需要更多信息,请告诉我。 :祈祷:
GKE 引擎:1.20.6-gke.1000
HTTP 负载平衡:已启用
网络策略:禁用
Dataplane V2:启用
我将其作为答案发布是为了提高可见度。正如我在评论中提到的:
据我所知,您不能将 GKE ingress 与 ExternalName
服务类型一起使用。支持的两种类型是 LoadBalancer
和 NodePort
。如果最近没有任何变化,即使使用简单的 ClusterIP
,您也不应该能够创建入口资源,只有上面提到的两种 svc 类型,所以我不相信 ExternalName
会起作用。好吧,您实际上可以使用 ClusterIP
,但前提是您使用 container native load balancing,这需要您的 GKE 集群是 VPC 原生的。
您仍然可以使用 GKE,但您不必同时使用 GCE ingress 作为入口控制器。但如果它不适用于提到的容器原生负载平衡,我会先尝试。
您始终可以在 GKE 集群上部署 不同的入口控制器,例如nginx-ingress。它可以使用开箱即用的 ClusterIP
服务,但我不确定它是否可以处理 ExternalName
所以你必须尝试一下。
OP 确认使用 nginx-ingress 可以将流量分配到位于不同命名空间的服务:
@mario Thank you for your comment. I successfully distribute traffics to other namespace svc using NGINX-ingress. – HyeonJunOh Jul 23 at 9:23