k8s 部署Harbor

Harbor 可以采用http访问和https访问,本文使用https访问,所以先生成证书

环境

# 安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

root@kubernetes-master1:/# docker-compose version
docker-compose version 1.21.2, build a133471
docker-py version: 3.3.0
CPython version: 3.6.5
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

一、安装openssl

root@kubernetes-master1:/# apt-get install openssl
root@kubernetes-master1:/# openssl rand -writerand .rnd
root@kubernetes-master1:/# mkdir /etc/certs/
root@kubernetes-master1:/# cd /etc/certs/
root@kubernetes-master1:/# openssl genrsa -out ca.key 4096
root@kubernetes-master1:/# openssl req -x509 -new -nodes -key /etc/certs/ca.key -subj "/CN=192.168.247.110" -days 5000 -out /etc/certs/ca.crt
root@kubernetes-master1:/# ls /etc/certs
ca.crt  ca.key

二、下载harbor离线安装包并解压

wget https://ghproxy.com/https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz
tar -zxvf harbor-offline-installer-v2.5.3.tgz -C /opt
cd /opt/harbor/
cp harbor.yml.tmpl harbor.yml

三、vim harbor.yml 修改如下几个地方

hostname: 192.168.247.110

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 8800

# https related config
https:
  # https port for harbor, default is 443
  port: 8443
  # The path of cert and key files for nginx
  certificate: /etc/certs/ca.crt
  private_key: /etc/certs/ca.key
......
下面还有

四、生成配置文件

root@kubernetes-master1:/opt/harbor# ./prepare
prepare base dir is set to /opt/harbor
Unable to find image 'goharbor/prepare:v2.5.3' locally
v2.5.3: Pulling from goharbor/prepare
cdd306291e3f: Pull complete
899708b6cf4a: Pull complete
5348cd9eea69: Pull complete
b26fbd0623df: Pull complete
8ef107bcedaf: Pull complete
45efdc863cd9: Pull complete
d109b36b1200: Pull complete
01920cccc2da: Pull complete
35df10b8b365: Pull complete
77422a9df465: Pull complete
Digest: sha256:1e3aae65de7a88dc0b541140940952657fdd1ab9b7bf64704d6b696b078dd1dc
Status: Downloaded newer image for goharbor/prepare:v2.5.3
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

五、安装

root@kubernetes-master1:/opt/harbor# ./install.sh

[Step 0]: checking if docker is installed ...

Note: docker version: 20.10.16

[Step 1]: checking docker-compose is installed ...

Note: docker-compose version: 1.21.2

[Step 2]: loading Harbor images ...
eb50d8bbd990: Loading layer [==================================================>]  7.668MB/7.668MB
04e75300c772: Loading layer [==================================================>]  7.362MB/7.362MB
e6830bb442bf: Loading layer [==================================================>]      1MB/1MB
Loaded image: goharbor/harbor-portal:v2.5.3
7e761f0c6325: Loading layer [==================================================>]  8.898MB/8.898MB
bea2d99bdd9a: Loading layer [==================================================>]  3.584kB/3.584kB
7635b8507a3f: Loading layer [==================================================>]   2.56kB/2.56kB
5374b1e2b14a: Loading layer [==================================================>]  78.75MB/78.75MB
3c111582434e: Loading layer [==================================================>]  5.632kB/5.632kB
c634a4d49b0c: Loading layer [==================================================>]  102.9kB/102.9kB
4edf106f0e4f: Loading layer [==================================================>]  15.87kB/15.87kB
732b0f7f2241: Loading layer [==================================================>]  79.66MB/79.66MB
8191a56b80ca: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v2.5.3
005d5db57e06: Loading layer [==================================================>]  119.7MB/119.7MB
0e3d87aacbc9: Loading layer [==================================================>]  3.072kB/3.072kB
b4e26556ed44: Loading layer [==================================================>]   59.9kB/59.9kB
55f587609a73: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v2.5.3
Loaded image: goharbor/prepare:v2.5.3
a86a26c0452a: Loading layer [==================================================>]  1.096MB/1.096MB
1025dfd257d2: Loading layer [==================================================>]  5.889MB/5.889MB
cd51e6d945dd: Loading layer [==================================================>]  168.8MB/168.8MB
c68c45fe177d: Loading layer [==================================================>]  16.58MB/16.58MB
fa18680022f9: Loading layer [==================================================>]  4.096kB/4.096kB
9f470cfcecff: Loading layer [==================================================>]  6.144kB/6.144kB
d9d256f40e6f: Loading layer [==================================================>]  3.072kB/3.072kB
f02862555d46: Loading layer [==================================================>]  2.048kB/2.048kB
8cc2449c3a33: Loading layer [==================================================>]   2.56kB/2.56kB
53e7545b8c1b: Loading layer [==================================================>]   2.56kB/2.56kB
62fbef76d294: Loading layer [==================================================>]   2.56kB/2.56kB
7e2d721c6c91: Loading layer [==================================================>]  8.704kB/8.704kB
Loaded image: goharbor/harbor-db:v2.5.3
7b5e699985f2: Loading layer [==================================================>]  5.755MB/5.755MB
17bb7303d841: Loading layer [==================================================>]  90.86MB/90.86MB
146be4872a18: Loading layer [==================================================>]  3.072kB/3.072kB
7f44df31c7df: Loading layer [==================================================>]  4.096kB/4.096kB
ec5f15201a56: Loading layer [==================================================>]  91.65MB/91.65MB
Loaded image: goharbor/chartmuseum-photon:v2.5.3
25ed0962037c: Loading layer [==================================================>]  8.898MB/8.898MB
96bf61ca4a6d: Loading layer [==================================================>]  3.584kB/3.584kB
faed05a35aaa: Loading layer [==================================================>]   2.56kB/2.56kB
6b2cce967e64: Loading layer [==================================================>]   90.8MB/90.8MB
47d73d2ec8c4: Loading layer [==================================================>]  91.59MB/91.59MB
Loaded image: goharbor/harbor-jobservice:v2.5.3
1b8a5b56dd8f: Loading layer [==================================================>]  5.755MB/5.755MB
ef6a1d16e324: Loading layer [==================================================>]  4.096kB/4.096kB
60cf083bf2b3: Loading layer [==================================================>]  17.34MB/17.34MB
54308a335bf1: Loading layer [==================================================>]  3.072kB/3.072kB
b507f0c5f1e1: Loading layer [==================================================>]  29.17MB/29.17MB
79b24972e581: Loading layer [==================================================>]  47.31MB/47.31MB
Loaded image: goharbor/harbor-registryctl:v2.5.3
35239a1e0d7a: Loading layer [==================================================>]  7.668MB/7.668MB
Loaded image: goharbor/nginx-photon:v2.5.3
e0776ca3d7c2: Loading layer [==================================================>]   5.75MB/5.75MB
c90a80564f89: Loading layer [==================================================>]  8.543MB/8.543MB
86c0504b8fcb: Loading layer [==================================================>]  14.47MB/14.47MB
abde74115d1a: Loading layer [==================================================>]  29.29MB/29.29MB
3ad37faaa958: Loading layer [==================================================>]  22.02kB/22.02kB
1d3c37158629: Loading layer [==================================================>]  14.47MB/14.47MB
Loaded image: goharbor/notary-signer-photon:v2.5.3
fa27c9d81dc3: Loading layer [==================================================>]    127MB/127MB
9ca66cb9252f: Loading layer [==================================================>]  3.584kB/3.584kB
09ce0e15f5ba: Loading layer [==================================================>]  3.072kB/3.072kB
d0ba49c5841f: Loading layer [==================================================>]   2.56kB/2.56kB
04623512f2e5: Loading layer [==================================================>]  3.072kB/3.072kB
083acf89058c: Loading layer [==================================================>]  3.584kB/3.584kB
5f2000f524c8: Loading layer [==================================================>]  20.99kB/20.99kB
Loaded image: goharbor/harbor-log:v2.5.3
425045210126: Loading layer [==================================================>]  8.898MB/8.898MB
a0ef3ff89e82: Loading layer [==================================================>]  21.05MB/21.05MB
7facb153a2bf: Loading layer [==================================================>]  4.608kB/4.608kB
ca36c2356dc0: Loading layer [==================================================>]  21.84MB/21.84MB
Loaded image: goharbor/harbor-exporter:v2.5.3
abd4886cf446: Loading layer [==================================================>]  5.755MB/5.755MB
a662294ced4c: Loading layer [==================================================>]  4.096kB/4.096kB
e1e02d95f798: Loading layer [==================================================>]  3.072kB/3.072kB
54535cb3135b: Loading layer [==================================================>]  17.34MB/17.34MB
a8556cd12eb5: Loading layer [==================================================>]  18.13MB/18.13MB
Loaded image: goharbor/registry-photon:v2.5.3
01427a3d3d67: Loading layer [==================================================>]   5.75MB/5.75MB
5cd7cb12cabb: Loading layer [==================================================>]  8.543MB/8.543MB
564dcad1be91: Loading layer [==================================================>]  15.88MB/15.88MB
b3020f432a85: Loading layer [==================================================>]  29.29MB/29.29MB
05bbf70fd214: Loading layer [==================================================>]  22.02kB/22.02kB
7cb2819f6977: Loading layer [==================================================>]  15.88MB/15.88MB
Loaded image: goharbor/notary-server-photon:v2.5.3
8cc02d219629: Loading layer [==================================================>]  6.283MB/6.283MB
09856854b73c: Loading layer [==================================================>]  4.096kB/4.096kB
c53bbce8e1c4: Loading layer [==================================================>]  3.072kB/3.072kB
ca0011850458: Loading layer [==================================================>]  91.21MB/91.21MB
0e7337dca995: Loading layer [==================================================>]  12.65MB/12.65MB
c1e6b3a22dfd: Loading layer [==================================================>]  104.6MB/104.6MB
Loaded image: goharbor/trivy-adapter-photon:v2.5.3


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /opt/harbor
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/jobservice/config.yml
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/registryctl/env
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir



[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating redis         ... done
Creating harbor-db     ... done
Creating registryctl   ... done
Creating registry      ... done
Creating harbor-portal ... done
Creating harbor-core   ... done
Creating harbor-jobservice ... done
Creating nginx             ... done
✔ ----Harbor has been installed and started successfully.----

六、打开

用户名admin 密码Harbor12345
k8s 部署Harbor_第1张图片

七、登录

root@kubernetes-master1:/opt/harbor# docker login 192.168.247.110:8443
Username: admin
Password:
Error response from daemon: Get "https://192.168.247.110/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

解决

mkdir -P /etc/docker/cert.d/192.168.247.110
cp /etc/certs/ca.crt /etc/docker/cert.d/192.168.247.110/
root@kubernetes-master1:/opt/harbor# docker login 192.168.247.110:8443
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
 docker tag calico/pod2daemon-flexvol:v3.8.9 192.168.247.110:8443/calico/pod2daemon-flexvol:v3.8.9

k8s 部署Harbor_第2张图片

在界面建一个仓库
k8s 部署Harbor_第3张图片
k8s 部署Harbor_第4张图片

参考

Harbor的安装和使用(最新版)-基于CentOS

你可能感兴趣的:(k8s学习总结,docker,go,kubernetes,docker,容器)