gpt4 book ai didi

Kubernetes Ingress 无法访问(本地主机)

转载 作者:行者123 更新时间:2023-12-02 16:02:15 25 4
gpt4 key购买 nike

我正在 Linux 机器上的本地主机上设置一个最小的 Kubernetes 集群(从 checkout 的存储库中的 hack/local-up-cluster 开始)。在我的部署文件中,我定义了一个入口,它应该使部署在集群中的服务可以从外部访问。部署.yml:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: foo-service-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: foo-service
spec:
containers:
- name: foo-service
image: images/fooservice
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7778
---
apiVersion: v1
kind: Service
metadata:
name: foo-service-service
spec:
ports:
- port: 7778
selector:
app: foo-service
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: api-gateway-ingress
spec:
rules:
- host:
http:
paths:
- path: /foo
backend:
serviceName: foo-service-service
servicePort: 7779
- path: /bar
backend:
serviceName: bar-service-service
servicePort: 7776

我无法访问服务。 kubectl描述显示了我的入口的以下内容:

Name:           api-gateway-ingress
Namespace: default
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
*
/foo foo-service-service:7779 (<none>)
/bar bar-service-service:7776 (<none>)
Annotations:
Events: <none>

是否是因为我的入口没有设置地址,所以外界还看不到它?

最佳答案

Ingress 资源只是集群如何处理入口流量的定义。它需要一个入口 Controller 来实际处理这些定义;在未部署 Ingress Controller 的情况下创建 Ingress 资源不会产生任何效果。

来自the documentation :

In order for the Ingress resource to work, the cluster must have an Ingress controller running. This is unlike other types of controllers, which typically run as part of the kube-controller-manager binary, and which are typically started automatically as part of cluster creation. You need to choose the ingress controller implementation that is the best fit for your cluster, or implement one.

有多个 Ingress Controller 可供您自行部署(通常通过部署资源),例如 NGINX ingress controller (这是 Kubernetes 项目的一部分)或第三方入口 Controller ,例如 Traefik , EnvoyVoyager .

关于Kubernetes Ingress 无法访问(本地主机),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45215465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com