我在 DigitalOcean 托管的 K8S 集群上安装了以下两个不同的入口 Controller :
并且它们已被分配到两个不同的 IP 地址。我的问题是,如果在同一个 K8S 集群上有两个不同的入口 Controller 是错误的?
之所以这样做,是因为 nginx 是针对harbor、argocd 等工具的,而istio 是针对微服务的。
我还发现,当两者并排安装时,有时在部署过程中,K8S 会突然出现故障。
例如,我部署了:
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes-first
namespace: dev
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 8080
selector:
app: hello-kubernetes-first
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes-first
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: hello-kubernetes-first
template:
metadata:
labels:
app: hello-kubernetes-first
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.7
ports:
- containerPort: 8080
env:
- name: MESSAGE
value: Hello from the first deployment!
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: istio
name: helloworld-ingress
namespace: dev
spec:
rules:
- host: hello.service.databaker.io
http:
paths:
- path: /*
backend:
serviceName: hello-kubernetes-first
servicePort: 80
---
然后我有:
Error from server (InternalError): error when creating "istio-app.yml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post https://ingress-nginx-controller-admission.nginx.svc:443/extensions/v1beta1/ingresses?timeout=30s: dial tcp 10.245.107.175:443: i/o timeout
最佳答案
你提出了几点——在回答你的问题之前,让我们退后一步。
Istio 不推荐 K8s Ingress
重要的是要注意 Istio 不推荐使用 K8s Ingress:
Using the Istio Gateway, rather than Ingress, is recommended to make use of the full feature set that Istio offers, such as rich traffic management and security features.
引用:https://istio.io/latest/docs/tasks/traffic-management/ingress/kubernetes-ingress/
如前所述,Istio 网关(Istio IngressGateway 和 EgressGateway)充当边缘,您可以在 https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-control/ 中找到更多信息.
Istio 中的多个端点
如果您需要为业务需求分配一个公共(public)端点,而另一个用于监控(例如您提到的 Argo CD、Harbor),您可以仅使用 Istio 来实现。大约有两种方法。
两者都是有效的,根据要求,您可能需要选择一种方式。
至于方法 #2,这是 Istio 的流量管理系统大放异彩的地方。这是 Istio 强大功能的一个很好的例子,但如果您是新手,设置会稍微复杂一些。所以这里有一个例子。
方法#2 示例
当您按照 default installation 创建 Istio IngressGateway 时,它将创建
istio-ingressgateway
如下所示(我过度简化了 YAML 定义):apiVersion: v1
kind: Service
metadata:
labels:
app: istio-ingressgateway
istio: ingressgateway
name: istio-ingressgateway
namespace: istio-system
# ... other attributes ...
spec:
type: LoadBalancer
# ... other attributes ...
然后,此 LB 服务将成为您的端点。 (我不熟悉 DigitalOcean K8s 环境,但我想他们会处理 LB 创建。)然后,您可以创建网关定义,如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: your-gateway
namespace: istio-system
spec:
selector:
app: istio-ingressgateway
istio: ingressgateway
servers:
- port:
number: 3000
name: https-your-system
protocol: HTTPS
hosts:
- "your-business-domain.com"
- "*.monitoring-domain.com"
# ... other attributes ...
然后您可以创建 2 个或更多 VirtualService定义。apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: business-virtsvc
spec:
gateways:
- istio-ingressgateway.istio-system.svc.cluster.local
hosts:
- "your-business-domain.com"
http:
- match:
- port: 3000
route:
- destination:
host: some-business-pod
port:
number: 3000
# ... other attributes ...
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: monitoring-virtsvc
spec:
gateways:
- istio-ingressgateway.istio-system.svc.cluster.local
hosts:
- "harbor.monitoring-domain.com"
http:
- match:
- port: 3000
route:
- destination:
host: harbor-pod
port:
number: 3000
# ... other attributes ...
注意:以上假设了很多东西,例如端口映射,流量处理等。请查看官方文档了解详细信息。所以,绕了很长一段路,回到这个问题:
问题:[是否] 在同一个 K8S 集群上有两个不同的入口 Controller 是错误的[?]
我相信没关系,尽管这可能会导致您看到的错误,因为两个入口 Controller 争夺 K8s Ingress 资源。
如上所述,如果您使用的是 Istio,最好坚持使用 Istio IngressGateway 而不是 K8s Ingress。如果您出于某种特定原因需要 K8s Ingress,您可以使用其他 Ingress Controller 进行 K8s Ingress,例如 Nginx。
至于您看到的错误,它来自 Nginx 部署的 webhook,即
ingress-nginx-controller-admission.nginx.svc
不可用。这意味着您已经创建了一个 K8s Ingress helloworld-ingress
与 kubernetes.io/ingress.class: istio
注释,但 Nginx webhook 正在干扰 K8s Ingress 处理。然后 webhook 无法处理资源,因为没有找到负责 webhook 流量的 Pod/Svc。错误本身只是说明 K8s 中的某些东西不健康——可能没有足够的节点分配给集群,因此没有发生 Pod 分配。还需要注意的是,Istio 确实需要一些 CPU 和内存占用,这可能会给集群带来更大的压力。
关于nginx - 同一个 K8S 集群上的两个入口 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61643319/