![](/img/trans.png)
[英]x509: certificate signed by unknown authority (possibly because of “crypto/rsa:…authority certificate ”osmacbook")
[英]x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error") in Kubernetes
我已經部署了一個監聽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
,我可以看到推送的圖像:
{“存儲庫”:[“你好世界”]}
在下一步中,我想創建一個 pod,從而創建一個 Deployment,它將能夠從我的本地注冊表下載圖像。 例子:
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 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
應用 Deployment 時,我得到
拉取圖像“my.local.registry:5000:5000/hello-world”失敗:rpc 錯誤:code = Unknown desc = 拉取和解壓圖像“my.local.registry:5000:5000/hello-world:latest”失敗“:無法解析引用“my.local.registry:5000:5000/hello-world:latest”:無法執行請求:Head“https://my.local.registry:5000:5000/v2/hello-world /manifests/latest": x509: 由未知權威機構簽署的證書(可能是因為在嘗試驗證候選權威機構證書“my.local.registry:5000”時出現“crypto/rsa: verification error”)
關於這個問題,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
但是錯誤仍然存在。
實際上,您在設置私有注冊表時所做的一切都是正確的。 然而,Kube.netes 不允許從不安全的私有注冊表中提取鏡像(是的,自簽名證書仍然被認為是“不安全的”)。
恐怕你必須告訴每個 Kube.netes 節點你的my.local.registry
是一個不安全的注冊表或者將證書文件放在每個節點中(如 Priyanka 答案的第二個鏈接中所述)。
一個不同的選擇可能是使用 letsencrypt 創建一個證書,因此它由一個已知的證書頒發機構簽名,因此是“安全的”。 但這限制了自定義域名的使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.