Kubernetes Ingress: 无法连接?

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

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实现配置了负载均衡服务。

在您的情况下,请使用:

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:

确定