连接拒绝尝试通过入口接口连接

Connection refused trying to connect via ingress interface

使用 Calico 作为 CNI 和 CRI-O。正确配置 DNS 设置。使用 helm 通过 NGINX 的官方文档页面安装 NGINX 入口控制器。安装时设置replicaset为2。

之后使用此文件创建 3 个对象:DeploymentService 用于公开 Web 服务器和 Ingress.

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: test-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-service-pod
  template:
    metadata:
      labels:
        app: nginx-service-pod
    spec:
      containers:
      - image: nginx 
        name: test-nginx
---
apiVersion: v1
kind: Service
metadata:
   name: nginx-service
spec:
   type: ClusterIP
   selector:
      app: nginx-service-pod
   ports:
      - port: 80
        targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
  - host: k8s.example.com
    http:
      paths:
      - path: /test
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80
...

尝试通过卷曲来测试部署服务,它工作正常:

# curl http://10.103.88.163
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

但是当我尝试卷曲 Ingress 时出现错误:

# curl http://k8s.example.com/test
curl: (7) Failed to connect to k8s.example.com port 80: Connection refused

为什么会这样?因为正如我所见,对象配置中没有错误配置。

这个问题应该通过添加

来解决
spec: 
  template:
    spec:
      hostNetwork: true

到入口控制器 yaml 清单。更多请查看this github issue and this answer.

问题是缺少 on-premise 基础设施的 metallb。因为我尝试使用默认的 443/80 端口访问服务。