# 私有镜像仓库+自签名证书

<mark style="color:purple;">**问题描述：**</mark>

使用本地的docker registry作为镜像仓库，而且配置了https证书，但是在k8s一定会报x509错误，镜像拉取不下来。

<mark style="color:red;">**失败的尝试方案：**</mark>

* 将运行时换成docker：
  * 观察到将虚拟机上的docker服务启动之后，配置docker的insecure-registries属性，之后在该虚拟机上执行docker login \<registry>可以成功，而一旦关闭docker服务，同样的命令却会失败，因此考虑将底层运行时换成docker
  * 另一个考虑时，相比k8s，本人对docker更熟悉，因此能够更好的观察k8s的执行情况
  * 但最终结果是失败，因为更换底层运行时成本太高，导致k8s集群搭建失败。
  * 阅读k8s的官网后，发现使用docker作为运行时需要先安装一个名为[`cri-dockerd`](https://github.com/Mirantis/cri-dockerd)适配器，因此可能导致遭遇新的问题，故而<mark style="color:orange;">放弃</mark>
  * <https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes/#docker>
* 经过思考，既然直接使用docker没问题，而当前k8s底层使用的时containerd，于是便向chatgpt询问containerd是否存在类似的机制，但是根据chatgpt给出的方案，无效果，问题依然存在
* 尝试了使用SAN证书，但是依然失败，原因可能是因为证书配置错误，对于SSL了解过于匮乏，openssl命令产生的文件数量过多，进而导致配置出错，但与原始的错误不同，错误提示信息出现了变化：

  ```log
  tls: failed to verify certificate: x509: certificate signed by unknown authority
  ```

<mark style="color:purple;">**最终解决方案：**</mark>

直接放弃私有仓库，使用aliyun提供的仓库服务，问题得以避免。

```url
registry.cn-hangzhou.aliyuncs.com
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/devops/kubernetes/group-1/yu-dao-de-yi-xie-wen-ti/si-you-jing-xiang-cang-ku-+-zi-qian-ming-zheng-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
