我应该在 kubernetes 入口清单中使用什么值作为主机?

我应该在 kubernetes 入口清单中使用什么值作为主机?

我有一个 Ingress 的 yaml:

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: app
  namespace: ingress-controller
... omitted for brevity ...
spec:
  rules:
    - host: ifs-alpha-kube-001.example.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: service-nodeport
              servicePort: 80
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: service-nodeport
              servicePort: 443
status:
  loadBalancer:
    ingress:
      - {}

在上面我设置了...

    - host: ifs-alpha-kube-001.example.com

该主机恰好是我的节点之一。我有三个节点。我非常确定这是不正确的。入口可以工作,但如果我关闭 ifs-alpha-kube-001,入口就会停止工作。host如果我想要一个高可用性集群,我应该设置什么?

谢谢

更新:我尝试了 duct_tape_coder 的建议,但我仍然做错了什么。

我需要能够访问端口 80 和 443 上的 Web 服务器,因此我创建了两个“单一服务”入口。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: port-80-ingress
  namespace: ingress-controller
spec:
  backend:
    serviceName: port-80-service
    servicePort: 80

... 和 ...

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: port-443-ingress
  namespace: ingress-controller
spec:
  backend:
    serviceName: port-443-service
    servicePort: 443

我删除了旧的入口。但我仍然只能访问我的第一个节点 ifs-alpha-kube-001 上的 Web 服务器,而不能访问 ifs-alpha-kube-002 和 ifs-alpha-kube-003。我验证了我的 Web 服务器正在 Pod 上运行。

更新二:

好吧我尝试了这个:

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: app2
  namespace: ingress-controller

... omitted ...

spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: service-nodeport
              servicePort: 80
          - path: /
            pathType: ImplementationSpecific
            backend:
              serviceName: service-nodeport
              servicePort: 443
status:
  loadBalancer:
    ingress:
      - {}
$ kubectl describe ingress app2 --namespace=ingress-controller
Name:             app2
Namespace:        ingress-controller
Address:
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /   service-nodeport:80 (10.233.119.22:80,10.233.123.33:80,10.233.125.29:80)
              /   service-nodeport:443 (10.233.119.22:443,10.233.123.33:443,10.233.125.29:443)
Annotations:  Events:
  Type        Reason  Age   From                Message
  ----        ------  ----  ----                -------
  Normal      CREATE  13m   ingress-controller  Ingress ingress-controller/app2
  Normal      CREATE  13m   ingress-controller  Ingress ingress-controller/app2
  Normal      UPDATE  12m   ingress-controller  Ingress ingress-controller/app2
  Normal      UPDATE  12m   ingress-controller  Ingress ingress-controller/app2

并删除了所有其他入口。但我仍然只能在主机 ifs-alpha-kube-001 上访问 http,但奇怪的是...如果我执行:

curl -L --insecure https://ifs-alpha-kube-001.example.com -vvvv

我收到大量有关重定向的输出。

> GET / HTTP/2
> Host: ifs-alpha-kube-001
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/2 302
< date: Tue, 23 Jun 2020 15:52:28 GMT
< server: Apache/2.4.39 (Unix) OpenSSL/1.0.2k-fips mod_wsgi/4.7.1 Python/3.6
< location: https://ifs-alpha-kube-001/
< content-length: 211
< content-type: text/html; charset=iso-8859-1
< strict-transport-security: max-age=15768000
<
* Ignoring the response-body
* Connection #1 to host ifs-alpha-kube-001 left intact
* Maximum (50) redirects followed
curl: (47) Maximum (50) redirects followed
* Closing connection 0
* Closing connection 1

这里发生了什么?

更新三

以下是我已设置的服务:

$ kubectl get service --namespace=ingress-controller  -o wide
NAME                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                                     AGE     SELECTOR
haproxy-ingress           NodePort    10.233.23.21   <none>        80:30032/TCP,443:30643/TCP,1936:30302/TCP   6d4h    run=haproxy-ingress
ingress-default-backend   ClusterIP   10.233.5.224   <none>        8080/TCP                                    6d5h    run=ingress-default-backend
service-nodeport          NodePort    10.233.3.139   <none>        80:30080/TCP,443:30443/TCP                  5d18h   k8s-app=test-caasa-httpd,pod-template-hash=7d79794567

我相信我已经将该service-nodeport服务与我的入口绑定在一起了app2

答案1

无需设置主机,它将在所有主机上可用,https://kubernetes.io/docs/concepts/services-networking/ingress/。您还可以指定 hostPort,使其在所有主机上的特定端口上可用。我建议这样做,然后使用外部负载平衡器/代理来访问所有节点上的入口主机端口。

相关内容