1

我正在使用标准程序为在 Kubernetes 上运行的应用程序启用 HTTPS 终止,使用: - 入口 nginx - AWS ELB 经典 - 让我们加密的证书管理器

我使用了此处描述的程序:https ://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-kubernetes

我之前已经能够使 Ingress 与 HTTP 一起工作,但我遇到了 HTTPS 问题,当我尝试 cURL 应用程序 URL 时出现以下错误:

$ curl -iv https://<SERVER>
* Rebuilt URL to: <SERVER>
*   Trying <IP_ADDR>...
* Connected to <SERVER> (<IP_ADDR>) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* gnutls_handshake() failed: An unexpected TLS packet was received.
* Closing connection 0
curl: (35) gnutls_handshake() failed: An unexpected TLS packet was received.

这是我目前拥有的:

在 kube-system 命名空间中运行的证书管理器:

$ kubectl get pods -n kube-system
    NAME                                     READY   STATUS      RESTARTS   AGE
    cert-manager-5f8db6f6c4-c4t4k            1/1     Running     0          2d1h
    cert-manager-webhook-85dd96d87-rxc7p     1/1     Running     0          2d1h
    cert-manager-webhook-ca-sync-pgq6b       0/1     Completed   2          2d1h

ingress-nginx 命名空间中的入口设置:

$ kubectl get all -n ingress-nginx
NAME                                            READY   STATUS    RESTARTS   AGE
pod/default-http-backend-587b7d64b5-ftws2       1/1     Running   0          2d1h
pod/nginx-ingress-controller-68bb4bfd98-zsz8d   1/1     Running   0          12h

NAME                           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/default-http-backend   ClusterIP   <IP_ADDR_1>   <none>        80/TCP                       2d1h
service/ingress-nginx          NodePort    <IP_ADDR_2>   <none>        80:32327/TCP,443:30313/TCP   2d1h

NAME                                       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/default-http-backend       1         1         1            1           2d1h
deployment.apps/nginx-ingress-controller   1         1         1            1           12h

应用命名空间中的应用和入口:

$ kubectl get all -n app
NAME              READY   STATUS    RESTARTS   AGE
pod/appserver-0   1/1     Running   0          2d1h

NAME                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE
service/appserver   ClusterIP   <IP_ADDR>   <none>        22/TCP,80/TCP   2d1h

NAME                         DESIRED   CURRENT   AGE
statefulset.apps/appserver   1         1         2d1h

$ kubectl describe ingress -n app
Name:             appserver
Namespace:        app
Address:
Default backend:  default-http-backend:80 (<none>)
TLS:
  letsencrypt-prod terminates <SERVER>
Rules:
  Host                      Path  Backends
  ----                      ----  --------
  <SERVER>
                            /   appserver:80 (<none>)
Annotations:
  certmanager.k8s.io/cluster-issuer:  letsencrypt-prod
  kubernetes.io/ingress.class:        nginx
Events:                               <none>

这是入口资源的样子:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
  name: appserver
  namespace: app
spec:
  tls:
  - hosts:
    - <SERVER>
    secretName: letsencrypt-prod
  rules:
  - host: <SERVER>
    http:
      paths:
      - backend:
          serviceName: appserver
          servicePort: 80
        path: /

我已经完成的其他检查:

检查证书是否已正确生成:

$ kubectl describe cert -n app
Name:         letsencrypt-prod
...
Status:
  Conditions:
    Last Transition Time:  2019-03-20T14:23:07Z
    Message:               Certificate is up to date and has not expired
    Reason:                Ready
    Status:                True
    Type:                  Ready

来自 cert-manager 的检查日志:

$ kubectl logs -f cert-manager-5f8db6f6c4-c4t4k -n kube-system
...
I0320 14:23:08.368872       1 sync.go:177] Certificate "letsencrypt-prod" for ingress "appserver" already exists
I0320 14:23:08.368889       1 sync.go:180] Certificate "letsencrypt-prod" for ingress "appserver" is up to date
I0320 14:23:08.368894       1 controller.go:179] ingress-shim controller: Finished processing work item "app/appserver"
I0320 14:23:12.548963       1 controller.go:183] orders controller: syncing item 'app/letsencrypt-prod-1237734172'
I0320 14:23:12.549608       1 controller.go:189] orders controller: Finished processing work item "app/letsencrypt-prod-1237734172"

目前还不确定还有什么值得检查的?

4

2 回答 2

1

看来您正在使用带有 cert-manager 的 nginx-ingress 的旧版本,这可能是您的错误的罪魁祸首。

我建议您尝试使用最新版本的 Helm 部署 nginx-ingress(确保 nginx-ingress-controller 的映像标记为 v0.23.0)。还要确保在 helm 部署期间使用最新版本 (--version v0.7.0) 部署 cert-manager。默认情况下,您应该会看到三个 pod:cert-manager、cert-manager-cainjector 和 cert-manager-webhook。

我不得不禁用 webhook,因为尽管为它提供了正确的参数,但它阻止了证书的颁发,所以你可能必须这样做。

希望这可以帮助!

于 2019-03-21T22:45:43.107 回答
1

毕竟,这个问题似乎与我如何在 AWS 上的 ELB 经典上设置监听器有关。

我做了以下工作:

HTTP 80 -> HTTP <INGRESS_SVC_NODE_PORT_1>
HTTP 443 -> HTTP <INGRESS_SVC_NODE_PORT_2>

第一个错误是我对 443 端口使用了 HTTP 而不是 HTTPS。当我尝试使用 HTTPS 时,我必须输入 SSL 证书,这对我来说没有意义,因为我正在使用 Let's encrypt 进行 Ingress 级别的 SSL 终止。

因此,以下侦听器配置起作用:

TCP 80 -> TCP <INGRESS_SVC_NODE_PORT_1>
TCP 443 -> TCP <INGRESS_SVC_NODE_PORT_2>
于 2019-03-22T11:57:15.567 回答