x509:Kubernetes 中由未知机构签署的证书(可能是因为“crypto/rsa:验证错误”)

问题描述 投票:0回答:1

我已经部署了一个本地注册表来监听

192.168.xx.xx:5000

/etc/hosts
中我添加了:

192.168.xx.xx my.local.registry

并使用

sudo vim /etc/docker/daemon.json
我添加了:

{“不安全注册表”:[“my.local.registry:5000”]}

然后我使用以下方法在其上推送图像:

sudo docker tag hello-world my.local.registry:5000/hello-world
sudo docker push my.local.registry:5000/hello-world

一切都按预期进行。在

https://my.local.registry:5000/v2/_catalog
中我可以看到推送的图像:

{“存储库”:[“hello-world”]}

在下一步中,我想创建一个 Pod,即一个能够从本地注册表下载映像的部署。示例:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry-test
  labels:
    app: registry-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: registry-test
  template:
    metadata:
      labels:
        app: registry-test
    spec:
      containers:
      - name: registry-test
        image: my.local.registry:5000/hello-world

我已经使用以下方法生成了自己的证书:

openssl req -newkey rsa:4096 -nodes -sha256 -keyout ./certs/tls.key -x509 -days 365  -subj "/C=GR/ST=./L=./O=./CN=my.local.registry" -addext "subjectAltName = DNS:my.local.registry" -out ./certs/tls.crt

然后我创建了一个文件夹

sudo mkdir -p /etc/docker/certs.d/my.local.registry:5000
,我使用
sudo scp certs/tls.crt /etc/docker/certs.d/my.local.registry:5000/ca.crt

放置新创建的证书

然后我添加了

sudo cp certs/tls.crt /usr/local/share/ca-certificates/ca.crt
,最后我执行了:

sudo update-ca-certificates 
sudo service docker restart
sudo systemctl restart containerd

但是,当我使用

kubectl apply -f mytestDeployment.yaml
应用部署时,我得到了

无法拉取镜像“my.local.registry:5000:5000/hello-world”:rpc 错误:代码 = 未知 desc = 无法提取和解压映像 “my.local.registry:5000:5000/hello-world:latest”:无法解析 参考“my.local.registry:5000:5000/hello-world:latest”:失败 做请求:头 “https://my.local.registry:5000:5000/v2/hello-world/manifests/latest”: x509:由未知机构签署的证书(可能是因为 尝试验证候选人时出现“crypto/rsa:验证错误” 权威证书“my.local.registry:5000”)

关于这个问题,SO 中有很多答案,但我无法解决这个问题。 有谁知道我在这里缺少什么?

更新

我也在使用DeamonSet:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: registry-ca
  namespace: ches
  labels:
    k8s-app: registry-ca
spec:
  selector:
    matchLabels:
      name: registry-ca
  template:
    metadata:
      labels:
        name: registry-ca
    spec:
      containers:
      - name: registry-ca-docker
        image: busybox
        command: [ 'sh' ]
        args: [ '-c', 'mkdir /etc/docker/certs.d/my.local.registry:5000 && cp /home/core/tls.crt /etc/docker/certs.d/my.local.registry:5000/ca.crt && exec tail -f /dev/null' ]
        volumeMounts:
        - name: etc-docker
          mountPath: /etc/docker/certs.d
        - name: ca-cert
          mountPath: /home/core
      - name: registry-ca-containerd
        image: busybox
        command: [ 'sh' ]
        args: [ '-c', 'cat /home/core/tls.crt > /home/core-containerd/ca.crt && exec tail -f /dev/null']
        volumeMounts:
        - name: ca-cert
          mountPath: /home/core
        - name: etc-containerd
          mountPath: /home/core-containerd
      terminationGracePeriodSeconds: 30
      volumes:
      - name: etc-docker
        hostPath:
          path: /etc/docker/certs.d
      - name: ca-cert
        secret:
          secretName: ches-registry-secret
      - name: etc-containerd
        hostPath:
          path: /usr/local/share/ca-certificates

但是错误仍然存在。

docker kubernetes yaml docker-registry
1个回答
0
投票

实际上,您在设置私人注册表方面所做的一切都是正确的。然而,Kubernetes 不允许从不安全的私有注册表中提取镜像(是的,自签名证书仍然被认为是“不安全的”)。

恐怕你必须告诉每个 Kubernetes 节点,你的

my.local.registry
要么是不安全的注册表,要么将证书文件放置在每个节点中(如 Priyanka 答案的第二个链接中所述)。

另一种选择可能是使用 LetsEncrypt 创建证书,因此它是由已知的证书颁发机构签名的,因此是“安全的”。但这限制了自定义域名的使用。

© www.soinside.com 2019 - 2024. All rights reserved.