安装harbor 镜像仓库

donwload pkg

http://harbor.orientsoft.cn/harbor-1.2.0/harbor-offline-installer-v1.2.0.tgz

wget http://harbor.orientsoft.cn/harbor-1.2.0/harbor-offline-installer-v1.2.0.tgz
tar xf harbor-*.tgz
cd harbor

git clone https://github.com/vmware/harbor.git
将`make`目录下的`kubernetes` 拷贝至 harbor目录下
[root@walker-1 harbor-v1.2.0]# ls
common                    docker-compose.notary.yml  harbor_1_1_0_template  harbor.v1.2.0.tar.gz  kubernetes  NOTICE   upgrade
docker-compose.clair.yml  docker-compose.yml         harbor.cfg             install.sh            LICENSE     prepare

下载好安装包后,载入harbor的docker镜像。

docker load -i harbor.v1.2.0.tar.gz

Configure

1. 编辑harbor.cfg

```
## Configuration file of Harbor

#The IP address or hostname to access admin UI and registry service.
#DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname = harbor.exmple.com:31883

#The protocol for accessing the UI and token/notification service, by default it is http.
#It can be set to https if ssl is enabled on nginx.
ui_url_protocol = http

#The password for the root user of mysql db, change this before any production use.
db_password = hello123

...
```

如果采用ingress的方式方式,则应将hostname设为域名形式。
31883 为ingress的http Nodeport 端口

2. 生成配置文件

    ./k8s_prepare

3. 编辑kubernetes/registry.deploy.yaml

    spec:
      containers:
      - name: registry-app
        image: vmware/registry:2.6.2-photon
        #image: registry:2.5.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5000
        - containerPort: 5001
        volumeMounts:
        - name: config
          mountPath: /etc/docker/registry
        - name: storage
          mountPath: /storage

/etc/registry 改为 /etc/docker/registry

相关issue如下:

https://github.com/vmware/harbor/issues/3348

4. 编辑kubernetes/registry.cm.yaml

auth:
  token:
    issuer: harbor-token-issuer
    realm: http://harbor.example.com:31883/service/token
    rootcertbundle: /etc/docker/registry/root.crt
    service: harbor-registry

/etc/registry/root.crt 改为 /etc/docker/registry/root.crt

5. 创建

[root@walker-1 kubernetes]# cat create.sh 
# create harbor namespace
kubectl create ns harbor

# create pv & pvc
kubectl apply -f ./pv/log.pv.yaml
kubectl apply -f ./pv/registry.pv.yaml
kubectl apply -f ./pv/storage.pv.yaml
kubectl apply -f ./pv/log.pvc.yaml
kubectl apply -f ./pv/registry.pvc.yaml
kubectl apply -f ./pv/storage.pvc.yaml

# create config map
kubectl apply -f ./jobservice/jobservice.cm.yaml
kubectl apply -f ./mysql/mysql.cm.yaml
kubectl apply -f ./registry/registry.cm.yaml
kubectl apply -f ./ui/ui.cm.yaml
kubectl apply -f ./adminserver/adminserver.cm.yaml

# create service
kubectl apply -f ./jobservice/jobservice.svc.yaml
kubectl apply -f ./mysql/mysql.svc.yaml
kubectl apply -f ./registry/registry.svc.yaml
kubectl apply -f ./ui/ui.svc.yaml
kubectl apply -f ./adminserver/adminserver.svc.yaml

# create k8s deployment
kubectl apply -f ./registry/registry.deploy.yaml
kubectl apply -f ./mysql/mysql.deploy.yaml
kubectl apply -f ./jobservice/jobservice.deploy.yaml
kubectl apply -f ./ui/ui.deploy.yaml
kubectl apply -f ./adminserver/adminserver.deploy.yaml

# create k8s ingress
# kubectl apply -f ./ingress.yaml

为了方便管理和查看,将harbor放入harbor namespace中

6. 访问

[root@walker-1 kubernetes]# kubectl get po -n harbor
NAME                           READY     STATUS    RESTARTS   AGE
adminserver-67d98fb8d6-lhtp5   1/1       Running   0          3h
jobservice-767cf6c4d5-4xmcn    1/1       Running   0          3h
mysql-d4b97c58-hqtwj           1/1       Running   0          3h
registry-6cd6f994-7qnxm        1/1       Running   0          1h
ui-5bdfd85f59-q55wr            1/1       Running   0          3h

确保pod运行正常后,打开浏览器,使用harbor.example.com:31883来访问UI

需要将域名写入到hosts文件中

页面如下所示:

image

7. 删除

[root@walker-1 kubernetes]# cat delete.sh 
# create pv & pvc
kubectl delete -f ./pv/log.pv.yaml
kubectl delete -f ./pv/registry.pv.yaml
kubectl delete -f ./pv/storage.pv.yaml
kubectl delete -f ./pv/log.pvc.yaml
kubectl delete -f ./pv/registry.pvc.yaml
kubectl delete -f ./pv/storage.pvc.yaml

# create config map
kubectl delete -f ./jobservice/jobservice.cm.yaml
kubectl delete -f ./mysql/mysql.cm.yaml
kubectl delete -f ./registry/registry.cm.yaml
kubectl delete -f ./ui/ui.cm.yaml
kubectl delete -f ./adminserver/adminserver.cm.yaml

# create service
kubectl delete -f ./jobservice/jobservice.svc.yaml
kubectl delete -f ./mysql/mysql.svc.yaml
kubectl delete -f ./registry/registry.svc.yaml
kubectl delete -f ./ui/ui.svc.yaml
kubectl delete -f ./adminserver/adminserver.svc.yaml

# create k8s deployment
kubectl delete -f ./registry/registry.deploy.yaml
kubectl delete -f ./mysql/mysql.deploy.yaml
kubectl delete -f ./jobservice/jobservice.deploy.yaml
kubectl delete -f ./ui/ui.deploy.yaml
kubectl delete -f ./adminserver/adminserver.deploy.yaml

# create k8s ingress
# kubectl delete -f ./ingress.yaml


# delete harbor namespace
kubectl delete ns harbor
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Harbor 是一个开源的云原生镜像仓库,支持 Docker 和 Kubernetes。搭建 Harbor 镜像仓库可以方便地管理和部署 Docker 镜像。 以下是 Harbor 镜像仓库的搭建步骤: 1. 安装 Docker 和 Docker Compose 首先需要在服务器上安装 Docker 和 Docker Compose,可以参考 Docker 官方文档进行安装。 2. 下载并解压 Harbor 安装包 在 Harbor 的官网上下载最新版本的 Harbor 安装包,解压到服务器上的任意目录。 3. 配置 Harbor 进入 Harbor 安装包所在目录,编辑 `harbor.cfg` 文件,配置相关参数,例如: ``` hostname = example.com ui_url_protocol = https harbor_admin_password = StrongPassword ``` 这里的 `hostname` 是 Harbor 的访问地址,`ui_url_protocol` 是访问协议,`harbor_admin_password` 是管理员密码。 4. 启动 HarborHarbor 安装包所在目录下执行以下命令启动 Harbor: ``` docker-compose up -d ``` 这会启动 Harbor 的所有组件,并且在后台运行。 5. 配置 Docker 客户端 在需要使用 Harbor 镜像仓库的客户端机器上,编辑 Docker 配置文件 `/etc/docker/daemon.json`,加入以下内容: ``` { "insecure-registries": ["example.com"] } ``` 这里的 `example.com` 是 Harbor 的访问地址。 6. 登录 Harbor 在客户端机器上执行以下命令登录 Harbor: ``` docker login example.com ``` 这里的 `example.com` 是 Harbor 的访问地址。 7. 使用 Harbor 登录成功后,就可以使用 Harbor 镜像仓库了,例如: ``` docker pull example.com/library/nginx:latest docker push example.com/library/nginx:latest ``` 这里的 `library/nginx` 是一个示例镜像,可以替换成其他镜像。 以上是 Harbor 镜像仓库的搭建步骤,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值