使用 TLS 保护 Kubernetes 服务

Securing Kubernetes Service with TLS

我有一个内部应用程序,仅通过具有集群 IP 的服务向集群上的其他应用程序公开。其他服务正在通过其 DNS (serviceName-namespace.svc.cluster.local) 访问此应用程序。此应用程序处理敏感数据,因此尽管所有通信都在集群内,但我想使用 TLS 来保护与此应用程序的通信。

我的问题是 - 如何在服务上启用 TLS?是否已经存在某些东西或者我应该在应用程序代码中处理它?另外,是否已经有我可以在集群上使用的 CA,它可以为 .svc.cluster.local 签署证书?

澄清一下,我知道我可以使用 ingress 来达到这个目的。唯一的问题是仅将此服务保留在内部 - 因此只有集群内的服务才能访问它。

谢谢, 奥马尔

检查教程“Secure Kubernetes Services with Ingress, TLS and LetsEncrypt”是否适用于您:

Ingress can be backed by different implementations through the use of different Ingress Controllers. The most popular of these is the Nginx Ingress Controller, however there are other options available such as Traefik, Rancher, HAProxy, etc. Each controller should support a basic configuration, but can even expose other features (e.g. rewrite rules, auth modes) via annotations.

Give it a domain name and enable TLS. LetsEncrypt is a free TLS certificate authority, and using the kube-lego controller we can automatically request and renew LetsEncrypt certificates for public domain names, simply by adding a few lines to our Ingress definition!

In order for this to work correctly, a public domain name is required and should have an A record pointing to the external IP of the Nginx service.

尽管 (svc.cluster.local),但为了限制在群集域内,you might need CoreDNS

根据@vonc 的评论,我想我有一个解决方案:

  • 为此服务购买 public 有效域(例如 something.mycompany.com)。
  • 使用 CoreDNS 添加覆盖规则,因此对 something.mycompany.com 的所有请求都将转到 something-namesapce.svc.cluster.local,因为该服务不会对外公开(对于我的用例,这也可以通过正常的 A 记录来完成).
  • 使用 Nginx 或其他工具来处理带有 something.mycompany.com.
  • 证书的 TLS

这听起来很复杂,但可能会奏效。你怎么看?

我刚刚发现 Kubernetes API 可用于生成证书,集群上的所有 pods 运行 都将信任该证书。此选项可能比其他选项更简单。您可以找到文档 here,包括生成和使用证书的完整流程。

在 Google Cloud 上,您可以将负载均衡器服务设置为内部,如下所示:

    annotations = {
      "cloud.google.com/load-balancer-type" = "Internal"
    }