如何将根 CA 添加到 minikube?

How I can add root CA to minikube?

我的公司使用它自己的根 CA,当我尝试拉取图像时。即使是来自私人注册表,我也会收到错误消息:

1h 3m 22 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for gcr.io/google_containers/pause-amd64:3.0, this may be because there are no credentials on this request.

details: (Error response from daemon: Get https://gcr.io/v1/_ping: x509: certificate signed by unknown authority)" 1h 10s 387 {kubelet minikube} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"gcr.io/google_containers/pause-amd64:3.0\""

我如何将根 CA 安装到 minkube 或避免此消息,即仅使用私有注册表,并且不要从 gcr.io 中提取任何内容?

独立于 minikube 执行此操作的直接方法是使用 imagePullSecrets 配置。如 Pulling an Image from a Private Registry 指南中所述,您可以创建一个 Secret 并将其与图像一起使用,如下所示:

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
    - name: private-container
      image: <your-private-image>
  imagePullSecrets:
    - name: the_secret

the_secret 可以用以下方式创建:

kubectl create secret docker-registry the_secret --docker-server=xxx --docker-username=xxx --docker-password=xxx --docker-email=xxx

或与:

kubectl create secret generic the_secret --from-file=.docker/config.json

或与 kubectl create secret 相关的任何其他内容 - 参见 documentation for details


编辑: 即使在官方 minikube 文档中,您也会发现他们将 Secretsregistry-creds 插件一起使用。

您将找到通用文档 here and the documentation for the addon here

它燃烧到:

minikube addons enable registry-creds

但从技术上讲,它的作用与上述相同。

至地址:

x509: certificate signed by unknown authority

你能试试 Minikube 存储库中的以下建议吗?

copy the cert into the VM. The location should be:

/etc/docker/certs.d/

from here: https://docs.docker.com/engine/security/certificates/

ref

该线程还包括以下一行:

cat <certificatefile> \
  | minikube ssh "sudo mkdir -p /etc/docker/certs.d/<domain> && sudo tee /etc/docker/certs.d/<domain>/ca.crt"

这里的问题是 Linux 主机的 CA 信任链需要更新。最简单的方法是在将证书复制到 VM 后重新启动 Linux 主机,如果重新启动不是一个选项 - 寻找 update-ca-certificates.

的方法

只是重新启动 Docker 守护程序很可能无法解决此问题

注意:允许 Docker 守护程序使用不安全的注册表意味着证书未经过验证。虽然这可能有所帮助,但并不能解决此处提出的问题

到目前为止我找到的唯一解决方案是向 minikube 添加 --insecure-registry gcr.io 选项。

您可以通过首先将证书复制到 $HOME/.minikube/certs:

来将您的公司证书添加到 minikube kubernetes 集群中
mkdir -p $HOME/.minikube/certs
cp my-company.pem $HOME/.minikube/certs/my-company.pem

然后使用 --embed-certs 选项启动 minikube:

minikube start --embed-certs

来源:Official documentation