在 kubernetes 1.8 上安装 Harbor 仓库

下载

当前最新版本是 1.2.2

1
$ wget http://harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz

准备 Docker 镜像

解压以后要把所有镜像上传到 k8s 工作节点。

1
2
3
4
$ tar -vxf harbor-offline-installer-v1.2.2.tgz
$ cd harbor/
$ scp harbor.v1.2.2.tar.gz k8s-node
$ docker load -i harbor.v1.2.2.tar.gz

准备配置文件

下载源码

1
$ git clone https://github.com/vmware/harbor.git

在以下目录中所有的 rc.yaml 中镜像替换成正确的镜像地址

1
make/kubernetes/**/*.rc.yaml

在以下目录文件中设置存储的容量

1
make/kubernetes/pv/*.pvc.yaml 

如果你改变了 PVC 的容量,那么你也需要相应的设置 PV 的容量。

如果想让外部访问,需要修改两个地方

1
2
$ vim make/harbor.cfg
hostname = 172.31.21.226
1
2
3
4
5
6
7
8
9
10
11
12
$ vim make/kubernetes/nginx/nginx.svc.yaml
...
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
selector:
name: nginx-apps
externalIPs:
- 172.31.21.226

如果部署了 ingress,可以不用管上边两步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: harbor-ui
spec:
rules:
- host: hub.xxx.com
http:
paths:
- path: /
backend:
serviceName: harbor-ui
servicePort: 80

生成安装脚本

1
$ python make/kubernetes/k8s-prepare

脚本执行完成后会生成下面的一些文件:

  • make/kubernetes/jobservice/jobservice.cm.yaml
  • make/kubernetes/mysql/mysql.cm.yaml
  • make/kubernetes/nginx/nginx.cm.yaml
  • make/kubernetes/registry/registry.cm.yaml
  • make/kubernetes/ui/ui.cm.yaml

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# create pv & pvc
kubectl apply -f make/kubernetes/pv/log.pv.yaml &&\
kubectl apply -f make/kubernetes/pv/registry.pv.yaml &&\
kubectl apply -f make/kubernetes/pv/storage.pv.yaml &&\
kubectl apply -f make/kubernetes/pv/log.pvc.yaml &&\
kubectl apply -f make/kubernetes/pv/registry.pvc.yaml &&\
kubectl apply -f make/kubernetes/pv/storage.pvc.yaml

# create config map
kubectl apply -f make/kubernetes/adminserver/adminserver.cm.yaml &&\
kubectl apply -f make/kubernetes/jobservice/jobservice.cm.yaml &&\
kubectl apply -f make/kubernetes/mysql/mysql.cm.yaml &&\
kubectl apply -f make/kubernetes/registry/registry.cm.yaml &&\
kubectl apply -f make/kubernetes/ui/ui.cm.yaml &&\
kubectl apply -f make/kubernetes/nginx/nginx.cm.yaml

# create service
kubectl apply -f make/kubernetes/adminserver/adminserver.svc.yaml &&\
kubectl apply -f make/kubernetes/jobservice/jobservice.svc.yaml &&\
kubectl apply -f make/kubernetes/mysql/mysql.svc.yaml &&\
kubectl apply -f make/kubernetes/registry/registry.svc.yaml &&\
kubectl apply -f make/kubernetes/ui/ui.svc.yaml &&\
kubectl apply -f make/kubernetes/nginx/nginx.svc.yaml

# create k8s rc
kubectl apply -f make/kubernetes/registry/registry.rc.yaml &&\
kubectl apply -f make/kubernetes/mysql/mysql.rc.yaml &&\
kubectl apply -f make/kubernetes/jobservice/jobservice.rc.yaml &&\
kubectl apply -f make/kubernetes/ui/ui.rc.yaml &&\
kubectl apply -f make/kubernetes/nginx/nginx.rc.yaml &&\
kubectl apply -f make/kubernetes/adminserver/adminserver.rc.yaml

问题

Error response from daemon: Get https://myregistrydomain.com/v1/users/: dial tcp myregistrydomain.com:443 getsockopt: connection refused.

1
2
3
4
5
6
7
8
9
10
$ vim /etc/docker/daemon.json
"insecure-registries": ["172.31.21.226"]

$ cat /etc/docker/daemon.json
{
"insecure-registries": ["172.31.21.226"],
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}

$ sudo systemctl daemon-reload && systemctl restart docker