Kubernetes Ingress: 无法连接?

huangapple go评论84阅读模式
英文:

Kubernetes ingress: could not connect?

问题

Traffic flow to implement:

客户端 ---> Ingress(SSL,负载均衡器) --> 我的网站(服务) -> PODs

Ingress:

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: foo
  5. spec:
  6. ingressClassName: nginx
  7. rules:
  8. - host: "test.foo.com"
  9. http:
  10. paths:
  11. - pathType: Prefix
  12. path: "/"
  13. backend:
  14. service:
  15. name: my_web
  16. port:
  17. number: 8080

无法连接到 Ingress 的端口 80:

  1. curl http://test.foo.com:80 <--- 无法连接

test.foo.com 在 hosts 文件中映射到 127.0.0.1。

可以直接连接到 my_web 服务(负载均衡器):

  1. curl http://localhost:8080 <---- 成功

Ingress 是否外部暴露任何端口?

my_web_service.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: my_web
  5. labels:
  6. app: my_web
  7. spec:
  8. ports:
  9. - name: http
  10. port: 8080
  11. targetPort: 8080
  12. selector:
  13. app: my_web
  14. type: LoadBalancer

my_web_deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: my_web
  5. labels:
  6. app: my_web
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: my_web
  11. template:
  12. metadata:
  13. labels:
  14. app: my_web
  15. spec:
  16. containers:
  17. - image: my_web:latest
  18. name: my_web
  19. ports:
  20. - containerPort: 8080
英文:

Traffic flow to implement:

  1. client ---> Ingress (SSL,LoadBalancer) --> my_web(service) -> PODs

Ingress:

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: foo
  5. spec:
  6. ingressClassName: nginx
  7. rules:
  8. - host: "test.foo.com"
  9. http:
  10. paths:
  11. - pathType: Prefix
  12. path: "/"
  13. backend:
  14. service:
  15. name: my_web
  16. port:
  17. number: 8080

Could not connect ingress port 80:

  1. 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

  1. curl http://localhost:8080 <---- success

Does ingress expose any port externally?

my_web_service.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: my_web
  5. labels:
  6. app: my_web
  7. spec:
  8. ports:
  9. - name: http
  10. port: 8080
  11. targetPort: 8080
  12. selector:
  13. app: my_web
  14. type: LoadBalancer

my_web_deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: my_web
  5. labels:
  6. app: my_web
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: my_web
  11. template:
  12. metadata:
  13. labels:
  14. app: my_web
  15. spec:
  16. containers:
  17. - image: my_web:latest
  18. name: my_web
  19. ports:
  20. - containerPort: 8080

答案1

得分: 1

Ingress本身不会暴露端口,除非您为Ingress实现配置了负载均衡服务。

在您的情况下,请使用:

curl http://test.foo.com:8080

英文:

Ingress itself does not expose ports if you don't configure a loadbalancer service for the ingress implementation.

Use

curl http://test.foo.com:8080

in your case

huangapple
  • 本文由 发表于 2023年5月22日 18:50:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定