Kubernetes NGINX Ingress TLS问题

时间:2018-02-27 14:40:22

标签: ssl nginx kubernetes

我在云中部署了k8s集群(VMVare vSphere) - 3个主服务器和1个工作节点。然后用helm安装了nginx-ingress:

helm install stable/nginx-ingress

部署了一些简单http-svc

的pod

将nginx-controller服务类型从 LoadBalancer 更改为 NodePort 并添加 externalIPs (我的主节点的IP地址),因此它&#39 ; s看起来像:

NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP                              PORT(S)                       AGE
ing-nginx-ingress-controller        NodePort    10.233.15.202   172.16.40.21,172.16.40.22,172.16.40.23   80:31045/TCP,443:31427/TCP    1d
http-svc                            ClusterIP   10.233.13.55                                             80/TCP                        1d

创建证书和秘密

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /tmp/tls.key -out /tmp/tls.crt -subj "/CN=<FQDN_HERE>"
kubectl create secret tls secret --key /tmp/tls.key --cert /tmp/tls.crt

并创建了入口:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: some-ingress
  namespace: default
spec:
  tls:
  - hosts:
    - <FQDN_HERE>
    secretName: secret
  rules:
  - host: <FQDN_HERE>
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /

如果我使用云端DNAT

external_ip:8443 -> master01_ip:443 (e.g. 172.16.40.21:443)

然后我有回复:

curl --resolve <FQDN>:8443:<external_ip> https://<FQDN>:8443 -v -k
* Added <FQDN>:8443:<external_ip> to DNS cache
* Rebuilt URL to: https://<FQDN>:8443/
* Hostname <FQDN> was found in DNS cache
*   Trying <external_ip>...
* TCP_NODELAY set
* Connected to <FQDN> (<external_ip>) port 8443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=<FQDN>
*  start date: Feb 22 10:37:00 2018 GMT
*  expire date: Feb 22 10:37:00 2019 GMT
*  issuer: CN=<FQDN>
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET / HTTP/1.1
> Host: <FQDN>:8443
> User-Agent: curl/7.58.0

但如果我使用负载平衡功能(vEdge Gateway):

                -> 172.16.40.21:443
external_ip:443 -> 172.16.40.22:443
                -> 172.16.40.23:443

有一个问题:

curl --resolve <FQDN>:443:<external_ip> https://<FQDN> -vvvv -k
* Added <FQDN>:443:<external_ip> to DNS cache
* Rebuilt URL to: https://<FQDN>/
* Hostname <FQDN> was found in DNS cache
*   Trying <external_ip>...
* TCP_NODELAY set
* Connected to <FQDN> (<external_ip>) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to <FQDN>:443
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to <FQDN>:443

尝试使用nginx和自签名证书的两个独立虚拟机 - 按预期工作。云提供商称LB在k8s进入中是功能性和问题。

谢谢!

1 个答案:

答案 0 :(得分:0)

正如@Nickolay所说,我应该在TCP模式下配置HTTPS模式vEdge网关负载均衡器。但是vEdge Gateway不允许这样做,因为端口443严格绑定到HTTPS。我通过配置运行状况检查(!)解决了我的问题,而不是使用SSL,而且所有工作都已完成。