英文:
Kubernetes ingress: could not connect?
问题
Traffic flow to implement:
客户端 ---> Ingress(SSL,负载均衡器) --> 我的网站(服务) -> PODs
Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo
spec:
  ingressClassName: nginx
  rules:
    - host: "test.foo.com"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: my_web
                port:
                  number: 8080
无法连接到 Ingress 的端口 80:
curl http://test.foo.com:80      <--- 无法连接
test.foo.com 在 hosts 文件中映射到 127.0.0.1。
可以直接连接到 my_web 服务(负载均衡器):
curl http://localhost:8080    <---- 成功
Ingress 是否外部暴露任何端口?
my_web_service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  selector:
    app: my_web
  type: LoadBalancer
my_web_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  selector:
    matchLabels:
      app: my_web
  template:
    metadata:
      labels:
        app: my_web
    spec:
      containers:
        - image: my_web:latest
          name: my_web
          ports:
            - containerPort: 8080
英文:
Traffic flow to implement:
client ---> Ingress (SSL,LoadBalancer) --> my_web(service) -> PODs
Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo
spec:
  ingressClassName: nginx
  rules:
    - host: "test.foo.com"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: my_web
                port:
                  number: 8080
Could not connect ingress port 80:
curl http://test.foo.com:80      <--- could not connect
test.foo.com is mapped to 127.0.0.1 in hosts file.
Could connect to the my_web service (loadBalancer) directly
curl http://localhost:8080    <---- success
Does ingress expose any port externally?
my_web_service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  selector:
    app: my_web
  type: LoadBalancer
my_web_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my_web
  labels:
    app: my_web
spec:
  selector:
    matchLabels:
      app: my_web
  template:
    metadata:
      labels:
        app: my_web
    spec:
      containers:
        - image: my_web:latest
          name: my_web
          ports:
            - containerPort: 8080
答案1
得分: 1
Ingress本身不会暴露端口,除非您为Ingress实现配置了负载均衡服务。
在您的情况下,请使用:
英文:
Ingress itself does not expose ports if you don't configure a loadbalancer service for the ingress implementation.
Use
in your case
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论