Gitlab的 Registry 是自动化部署一个环节。计划从Gitlab的自动化集成、自动化部署,以及如何配合Kubernets(谷歌的平台简称K8s),这些属于Devops的应用。
之前写过一篇文章,感慨现在的云服务实在是太方便了:快速部署的目的是让创业公司专注自己的业务,而无需浪费人力去折腾基础服务.
那么为何不使用 Docker Hub 服务?反而要自己搭建呢?
几个原因:
* Docker Hub 访问实在是太慢,甚至是访问不了.
* 使用 Docker Hub必须开源自己的仓库, 很多用户比较敏感.(当然可以花钱购买私有仓库进行扩容)
* 自己机器上数据和云服务数据同步,保证数据安全
---------------------------------------------------------
Gitlab 功能太多,我也是使用 CI 、CD 配合 Kubernetes(k8s)时候偶然发现竟然还集成了Docker Registry 的功能...这下爽了,终于不用看墙的脸色决定网速了~我自己的 Docker Hub,想怎么push、pull 都行~
---------------------------------------------------------
我们这篇主要讲怎么避免踩坑,具体服务怎么搭建回头找个机会,再整理下详细步骤.
我的环境是一台 DELL 16G 的1U 服务器,在 EXSI 6.5 上给 Ubuntu17.04 server 分配了4 Core 以及 6G内存.
只跑 Gitlab 基础 + Registry 的服务, 和这个配套的 K8s 、Gitlab-runner 等服务在另外一个系统上跑(K8s 、CI CD、 Gitlab-runner 如何搭建以及应用,会以后讲).
以下注意几点:
- Registry 不支持自签(Self-Signed Cretificate)
所以不要想着局域网随便在路由器上制定个域名,然后自签证去访问 Registry
(例如定义 registry-inter.gitlab.com 192.168.2.50, 这种是不行的)
2. 推荐用 Letsencrypt 做签名,去官网看最新文档.
3. 不做这个配置,Docker 是只能 pull 不能 push 的
( 敲黑板! )
( 敲黑板! )
registry_nginx['listen_port'] = 5001
registry_nginx['listen_https'] = 5001
registry_nginx['ssl_certificate'] = "/etc/letsencrypt/live/xxx.sn.mynetname.net/fullchain.pem"
registry_nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/xxx.sn.mynetname.net/privkey.pem"
registry_nginx['proxy_set_headers'] = {
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
}
4. 要把Registry 的 URL开启
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html
external_url 'https://xxx.sn.mynetname.net'
registry_external_url 'https://xxx.sn.mynetname.net:5001'
---------------------------------
效果展示开始~~~
- 按照上面注意的几个点,reconfigure Gitlab 就会开启 Registry
- Login 自己的 Registry
- 输入 Gitlab 的用户名和密码
- docker pull 和 push
[~] $ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[~] $ docker login xxx.sn.mynetname.net:5001
Username (root): root
Password:
Login Succeeded
[~] $ docker pull xxx.sn.mynetname.net:5001/root/ruby-auto-deploy
Using default tag: latest
latest: Pulling from root/ruby-auto-deploy
53478ce18e19: Pull complete
205e695b160d: Pull complete
3053289718c1: Pull complete
f20587270031: Pull complete
0216ea0ad0cc: Pull complete
Digest: sha256:671b5000e5ea039380cc2652cb116b7acc7af670771d5f31ce1745b7520a426f
Status: Downloaded newer image for xxx.sn.mynetname.net:5001/root/ruby-auto-deploy:latest
[~] $ docker -it xxx.sn.mynetname.net:5001/root/ruby-auto-deploy
[~] $ docker push xxx.sn.mynetname.net:5001/root/ruby-auto-deploy
The push refers to a repository [xxx.sn.mynetname.net:5001/root/ruby-auto-deploy]
27e56f3be4b2: Layer already exists
dc5ac3916e39: Layer already exists
cc70f6121a9a: Layer already exists
9fb8cf09ee55: Layer already exists
7b1b6293e1d4: Layer already exists
9f8566ee5135: Layer already exists
latest: digest: sha256:671b5000e5ea039380cc2652cb116b7acc7af670771d5f31ce1745b7520a426f size: 1573
[~] $ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xxx.sn.mynetname.net:5001/root/ruby-auto-deploy latest 97e68bc00cfe 2 weeks ago 60.9MB
(这里仅作演示,代表自建服务是可以 push 和 pull 的)
----------------------------------------------------
说个题外话,我司虽然是企业宽带,但是固定 IP还是要额外花钱,那么我就也直接用路由自带的 DDNS 来做域名了.所以用 Letsencrypt 的签名免费真的是一级棒~~
既然这个公众号叫 '略略的什么路由值得买' , 那么我推荐中小型创业公司去购买 MikroTik 出的 路由器,便宜好使.
--------------------- 我叫分割线 -----------------
是否还有童鞋记得某期文章说要写一个 Gitlab +K8s + CI、CD? 是的~~我没忘,只是懒~~~
自签证书?可以用的啊。
回复删除在服务端docker的daemon.json里面设置insecure-registry和registry-mirrors(registry-mirrors好像不一定有用,反正我是都设了。)
https://docs.gitlab.com/ce/administration/container_registry.html#container-registry-domain-configuration
Using self-signed certificates with Container Registry 这部分
我原文表达有误吧,容易产生歧义。
删除主要我在测试的时候发现了 CI配合自己的 REGISTRY有问题。
Using self-signed certificates with Container Registry
If you’re using a self-signed certificate with your Container Registry, you might encounter issues during the CI jobs like the following:
Error response from daemon: Get registry.example.com/v1/users/: x509: certificate signed by unknown authority
The Docker daemon running the command expects a cert signed by a recognized CA, thus the error above.
While GitLab doesn’t support using self-signed certificates with Container Registry out of the box, it is possible to make it work if you follow Docker’s documentation. You may find some additional information in issue 18239
赞 确实解决了问题
回复删除