gpt4 book ai didi

ssl - 如何在 Kubernetes 中的 pod-to-service 调用中轻松启用 SSL

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:43 25 4
gpt4 key购买 nike

我需要能够从 pod 发出请求以使用 SSL 提供服务。最简单的方法是什么?

在我的设置中,我已将 CoreDNS 配置为将来自 domain.com 的每个请求的目标重写为 service.namespace.svc.cluster.local。这是因为我在 Kubernetes 中运行的调用者软件的限制,我希望这些请求在 Kubernetes 中路由。

最佳答案

根据评论,我的建议是使用 initContainer 在包含该服务的 pod 上生成一个新的自签名证书,配置您的服务以使用这个新证书并确保客户端应用不验证证书的权威性。

这是一个您可以添加到您的服务中的 yaml 示例:

apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: alpine
name: alpine
spec:
replicas: 1
selector:
matchLabels:
app: alpine
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: alpine
spec:
initContainers:
- name: ssl-init
image: wolmi/tools:v1.0.0
command: ["sh", "-c", "openssl req -nodes -x509 -newkey rsa:4096 -keyout /tmp/ssl/key.pem -out /tmp/ssl/cert.pem -days 365 -subj "/C=DE/ST=NRW/L=Berlin/O=My Inc/OU=DevOps/CN=www.example.com/emailAddress=dev@www.example.com""]
volumeMounts:
- name: ssl-folder
mountPath: /tmp/ssl
containers:
- image: alpine
name: alpine
resources: {}
volumeMounts:
- name: ssl-folder
mountPath: /tmp/ssl
volumes:
- name: ssl-folder
emptyDir: {}

在那个 Deployment 上,您使用 emptyDir 参数创建一个卷,以允许容器安装它并能够在里面写入,然后是 initContainer 在该文件夹内生成 key 和证书文件,并且可供 pod 上的所有容器使用。

关于ssl - 如何在 Kubernetes 中的 pod-to-service 调用中轻松启用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57254797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com