记录一下Kubernetes安装Docker registry的过程。
生成证书
参考http://blog.gcalls.cn/blog/2017/01/Docker学习总结.html#证书安装方式
1 | openssl req \ |
ConfigMap
将domain.crt与domain.key通过configmap方式mount在容器中:
registry-configMap.yaml
1 | apiVersion: v1 |
PV
registry-pv.yaml
1 | apiVersion: v1 |
PVC
registry-pvc.yaml
1 | apiVersion: v1 |
registry-ds
registry-ds.yaml
1 | apiVersion: apps/v1beta1 |
registry-svc
registry-svc.yaml
1 | apiVersion: v1 |
创建
1 | kubectl create -f registry-configMap.yaml |
客户端
如果要用docker pull或者docker push的客户端,都需要执行以下命令:1
2mkdir -p /etc/docker/certs.d/192.168.10.6:30009
cp domain.crt /etc/docker/certs.d/192.168.10.6:30009/ca.crt
否则,会报以下错误:1
Error response from daemon: Get https://192.168.10.6:30009/v1/_ping: x509: certificate signed by unknown authority
测试
1 | docker pull hello-world |
异常
如测试出现:
Get https://192.168.10.6:30009/v1/_ping: net/http: TLS handshake timeout
有可以本地与docker开启了代理,需要关闭docker代理或者将ip添加到NO_PROXY中,文件位于:1
/etc/systemd/system/docker.service.d/http-proxy.conf
Get https://192.168.10.6:30009/v1/_ping: x509: cannot validate certificate for 192.168.10.6 because it doesn’t contain any IP SANs
这个是由于CN为registry.gcalls.cn,但通过ip,需要添加SAN信息:
先/etc/pki/tls/openssl.cnf配置,在该文件中找到[ v3_ca ],在它下面添加如下内容:1
2
3[ v3_ca ]
# Extensions for a typical CA
subjectAltName = IP:192.168.10.6
也可以直接在创建crt时,传-reqexts SAN参数。
参考
https://github.com/kubernetes/kubernetes/blob/v1.7.5/cluster/addons/registry/