Google Kubernetes Engine:为服务类型启用 HTTPS
Google Kubernetes Engine: Enable HTTPS for Service type
我在 GKE 上有一个应用程序,我希望它只能通过 HTTPS 访问,所以我已经获得了一个签名证书来使用 TLS 保护该应用程序。
我已经查看了很多关于如何执行此操作的教程,但它们都提到使用 Ingress 并使用 LetsEncrypt 和 KubeLego 自动请求证书。但我希望继续使用外部负载平衡器(google 提供给我的计算引擎实例),但我只希望我的应用程序可以通过 https 访问。
如何应用我的 server.crt 和 server.key 文件来启用 https.Do I apply it to the Load balancers 或 kubernetes 集群。
Ingress 是最简单的方法。您不需要使用 LetsEncrypt,您可以指定自己的证书。
入口控制器只是一个 NGINX 代理。如果您不想使用入口(为什么?),您必须自己创建此代理服务。这实际上是这项服务的入口。
在通过 HTTPS 公开您的应用程序时,Ingress 可能是您的最佳选择。 Ingress 资源指定后端服务,因此您将继续将您的应用程序公开为 Kubernetes 服务,只需将类型设置为 ClusterIP
。这将为您的集群生成一个 "internal" 服务,一旦您设置好它,就可以通过 Ingress 从外部访问它。
现在,特别是在 Google Kubernetes Engine (GKE) 中,集群中定义的任何入口资源都将由 Google 云负载均衡器提供服务,所以我认为您不必担心部署自己的 Ingress Controller(例如 Nginx Ingress Controller)。
在 TLS 方面,如果您有证书,则可以使用自己的证书。证书必须通过 Kubernetes Secret 上传到集群。定义该秘密后,您可以在 Ingress 定义中引用该秘密。 (https://kubernetes.io/docs/concepts/services-networking/ingress/#tls)
您可以使用以下命令创建密钥:
kubectl create secret tls my-app-certs --key /tmp/tls.key --cert /tmp/tls.crt
获得秘密后,您可以在入口资源中引用它:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app-ingress
spec:
tls:
- secretName: my-app-certs
backend:
serviceName: s1
servicePort: 80
创建入口资源后,GKE 将配置负载均衡器并为您提供一个可公开访问的 IP,您可以使用该 IP:
kubectl get ingress my-app-ingress
以下是一个很好的教程,可以引导您完成 GKE 上的 Ingress:
https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer
解决方法:
在 运行 时间内获取您的证书,很多人使用 LetsEncrypt 因为它非常简单,但您可以将证书存储在实际安全的存储中,例如云平台的密钥管理存储,或者 运行 你自己的 Hashicorp Vault(我推荐 Hashicorp Vault,它 非常 好!)然后在 运行 时间安全地检索你的秘密。
您注意到每个教程或指南都建议动态获取它们。
but they all refer to using Ingress and automatically requesting the certificate using, LetsEncrypt and KubeLego.
原因如下:
https://kubernetes.io/docs/concepts/configuration/secret/#risks
Risks
In the API server secret data is stored as plaintext in etcd; therefore:
Administrators should limit access to etcd to admin users
Secret data in the API server is at rest on the disk that etcd uses; admins may want to wipe/shred disks used by etcd when no longer in use
A user who can create a pod that uses a secret can also see the value of that secret. Even if apiserver policy does not allow that user to read the secret object, the user could run a pod which exposes the secret.
If multiple replicas of etcd are run, then the secrets will be shared between them. By default, etcd does not secure peer-to-peer communication with SSL/TLS, though this can be configured.
Currently, anyone with root on any node can read any secret from the apiserver, by impersonating the kubelet. It is a planned feature to only send secrets to nodes that actually require them, to restrict the impact of a root exploit on a single node.
因此每个人都正确地建议您不要使用 K8s SECRETS 来存储您宝贵的证书,因为它不适合这份工作。
我在 GKE 上有一个应用程序,我希望它只能通过 HTTPS 访问,所以我已经获得了一个签名证书来使用 TLS 保护该应用程序。
我已经查看了很多关于如何执行此操作的教程,但它们都提到使用 Ingress 并使用 LetsEncrypt 和 KubeLego 自动请求证书。但我希望继续使用外部负载平衡器(google 提供给我的计算引擎实例),但我只希望我的应用程序可以通过 https 访问。
如何应用我的 server.crt 和 server.key 文件来启用 https.Do I apply it to the Load balancers 或 kubernetes 集群。
Ingress 是最简单的方法。您不需要使用 LetsEncrypt,您可以指定自己的证书。
入口控制器只是一个 NGINX 代理。如果您不想使用入口(为什么?),您必须自己创建此代理服务。这实际上是这项服务的入口。
在通过 HTTPS 公开您的应用程序时,Ingress 可能是您的最佳选择。 Ingress 资源指定后端服务,因此您将继续将您的应用程序公开为 Kubernetes 服务,只需将类型设置为 ClusterIP
。这将为您的集群生成一个 "internal" 服务,一旦您设置好它,就可以通过 Ingress 从外部访问它。
现在,特别是在 Google Kubernetes Engine (GKE) 中,集群中定义的任何入口资源都将由 Google 云负载均衡器提供服务,所以我认为您不必担心部署自己的 Ingress Controller(例如 Nginx Ingress Controller)。
在 TLS 方面,如果您有证书,则可以使用自己的证书。证书必须通过 Kubernetes Secret 上传到集群。定义该秘密后,您可以在 Ingress 定义中引用该秘密。 (https://kubernetes.io/docs/concepts/services-networking/ingress/#tls)
您可以使用以下命令创建密钥:
kubectl create secret tls my-app-certs --key /tmp/tls.key --cert /tmp/tls.crt
获得秘密后,您可以在入口资源中引用它:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app-ingress
spec:
tls:
- secretName: my-app-certs
backend:
serviceName: s1
servicePort: 80
创建入口资源后,GKE 将配置负载均衡器并为您提供一个可公开访问的 IP,您可以使用该 IP:
kubectl get ingress my-app-ingress
以下是一个很好的教程,可以引导您完成 GKE 上的 Ingress: https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer
解决方法:
在 运行 时间内获取您的证书,很多人使用 LetsEncrypt 因为它非常简单,但您可以将证书存储在实际安全的存储中,例如云平台的密钥管理存储,或者 运行 你自己的 Hashicorp Vault(我推荐 Hashicorp Vault,它 非常 好!)然后在 运行 时间安全地检索你的秘密。
您注意到每个教程或指南都建议动态获取它们。
but they all refer to using Ingress and automatically requesting the certificate using, LetsEncrypt and KubeLego.
原因如下:
https://kubernetes.io/docs/concepts/configuration/secret/#risks
Risks
In the API server secret data is stored as plaintext in etcd; therefore: Administrators should limit access to etcd to admin users Secret data in the API server is at rest on the disk that etcd uses; admins may want to wipe/shred disks used by etcd when no longer in use
A user who can create a pod that uses a secret can also see the value of that secret. Even if apiserver policy does not allow that user to read the secret object, the user could run a pod which exposes the secret.
If multiple replicas of etcd are run, then the secrets will be shared between them. By default, etcd does not secure peer-to-peer communication with SSL/TLS, though this can be configured.
Currently, anyone with root on any node can read any secret from the apiserver, by impersonating the kubelet. It is a planned feature to only send secrets to nodes that actually require them, to restrict the impact of a root exploit on a single node.
因此每个人都正确地建议您不要使用 K8s SECRETS 来存储您宝贵的证书,因为它不适合这份工作。