本文Harbor高可用依照Harbor官网部署,主要思路以下,你们能够根据具体状况选择搭建。node
部署Harbor高可用集群。(本文主要阐述Harbor的高可用部署,为《kubernetes搭建Harbor无坑及Harbor仓库同步》补充部分,请先行阅读)nginx
本文仅说明高可用配置,其他部署请查看《kubernetes搭建Harbor无坑及Harbor仓库同步》git
直接使用博主整理好的编排文件安装(经过Helm生成)github
安装Helm请查看《kubernetes搭建Harbor无坑及Harbor仓库同步》,其中包含Helm安装。redis
git clone https://github.com/goharbor/harbor-helm.git cd XXX/harbor-helm
database的Postgresql配置sql
database: # if external database is used, set "type" to "external" # and fill the connection informations in "external" section type: external internal: image: repository: goharbor/harbor-db tag: v1.8.2-dev # The initial superuser password for internal database password: "changeit" # resources: # requests: # memory: 256Mi # cpu: 100m nodeSelector: {} tolerations: [] affinity: {} external: host: "stolon-proxy-service" #管理postgresql的stolon的service,由于都在Pod中可相互访问 port: "5432" username: "postgres" password: "password1" coreDatabase: "registry" clairDatabase: "clair" notaryServerDatabase: "notaryserver" notarySignerDatabase: "notarysigner" sslmode: "disable" ## Additional deployment annotations podAnnotations: {}
redis的配置docker
redis: # if external Redis is used, set "type" to "external" # and fill the connection informations in "external" section type: external internal: image: repository: goharbor/redis-photon tag: v1.8.2-dev # resources: # requests: # memory: 256Mi # cpu: 100m nodeSelector: {} tolerations: [] affinity: {} external: host: "10.8.4.133" #haproxy的地址经过haproxy管理redis集群 port: "6379" # The "coreDatabaseIndex" must be "0" as the library Harbor # used doesn't support configuring it coreDatabaseIndex: "0" jobserviceDatabaseIndex: "1" registryDatabaseIndex: "2" chartmuseumDatabaseIndex: "3" password: ""
修改Harbor其余组件replicas(副本数)数据库
# 例如nginx的副本数更改 nginx: image: repository: goharbor/nginx-photon tag: v1.8.2-dev replicas: 3
执行sql语句脚本,供stolon-init-database-job.yaml使用vim
cat <<EOF > ./postgresql.sh #!/bin/bash host="stolon-proxy-service" user="postgres" db="postgres" export PGPASSWORD="password1" args=( # force postgres to not use the local unix socket (test "external" connectibility) --host "$host" --username "$user" --dbname "$db" --quiet --no-align --tuples-only ) if select="$(echo 'SELECT 1' | psql "${args[@]}")" && [ "$select" = '1' ]; then echo "====notaryserver==database==creating====" psql -h stolon-proxy-service -p 5432 -U postgres -f "/docker-entrypoint-initdb.d/initial-notaryserver.sql" echo "====notarysigner==database==creating====" psql -h stolon-proxy-service -p 5432 -U postgres -f "/docker-entrypoint-initdb.d/initial-notarysigner.sql" echo "====registry==database==creating====" psql -h stolon-proxy-service -p 5432 -U postgres -f "/docker-entrypoint-initdb.d/initial-registry.sql" echo "====clair==database==creating====" psql -h stolon-proxy-service -p 5432 -U postgres -f "/docker-entrypoint-initdb.d/initial-clair.sql" exit 0 fi exit 1 EOF
建立registry数据库api
cat <<EOF > ./initial-registry.sql CREATE DATABASE registry ENCODING 'UTF8'; \c registry; CREATE TABLE schema_migrations(version bigint not null primary key, dirty boolean not null); EOF
建立notaryserver数据库
cat <<EOF > ./initial-notaryserver.sql CREATE DATABASE notaryserver; CREATE USER server; alter user server with encrypted password 'password'; GRANT ALL PRIVILEGES ON DATABASE notaryserver TO server; EOF
建立notarysigner数据库
cat <<EOF > ./initial-notarysigner.sql CREATE DATABASE notarysigner; CREATE USER signer; alter user signer with encrypted password 'password'; GRANT ALL PRIVILEGES ON DATABASE notarysigner TO signer; EOF
建立clair数据库
cat <<EOF > ./initial-clair.sql CREATE DATABASE clair; EOF
建立一个job的yaml(stolon-init-database-job.yaml),用于建立数据库,注意更改脚本的挂载位置,并复制脚本到各个节点或为node和yaml加上nodeselect标签,只在当前标签node下复制脚本
apiVersion: batch/v1 kind: Job metadata: name: stolon-init-database-job spec: template: spec: containers: - name: stolon-proxy image: sorintlab/stolon:master-pg10 command: - "/bin/bash" - "/docker-entrypoint-initdb.d/postgresql.sh" volumeMounts: - mountPath: /docker-entrypoint-initdb.d name: database restartPolicy: OnFailure #失败重启 volumes: - name: database hostPath: path: /root/tmp/harbor/stolon/examples/kubernetes/sql activeDeadlineSeconds: 600 #10分钟没有complete,再也不重启并移除Pod
yum -y install haproxy
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg-back
vim /etc/haproxy/haproxy.cfg
defaults REDIS mode tcp timeout connect 1m timeout server 6m timeout client 6m frontend ft_redis bind 0.0.0.0:6379 name redis default_backend bk_redis backend bk_redis option tcp-check tcp-check connect tcp-check send PING\r\n tcp-check expect string +PONG tcp-check send info\ replication\r\n tcp-check expect string role:master tcp-check send QUIT\r\n tcp-check expect string +OK server R1 redis-0.redis-headless.default.svc.cluster.local:6379 check inter 1s server R2 redis-1.redis-headless.default.svc.cluster.local:6379 check inter 1s server R3 redis-2.redis-headless.default.svc.cluster.local:6379 check inter 1s listen admin_stats stats enable bind *:9090 mode http option httplog log global maxconn 10 stats refresh 30s stats uri /admin stats realm haproxy stats auth admin:admin stats hide-version stats admin if TRUE
systemctl start haproxy && systemctl enable haproxy && systemctl status haproxy
访问 harbor节点Ip:9090/admin
如图所示,便成功
⚠️k8s master节点高可用可阅读《haproxy+keepalive实现master集群高可用》
安装harbor并将日志写入文件,可编辑文件保留.yaml编排文件,以便之后使用
helm install . --debug --name hub |sed 'w harbor.yaml'
或执行如下命令,编排chart不执行,做用生成编排文件,删除多余部分,进行使用
helm install . --debug --dry-run --name hub |sed 'w harbor.yaml'
连接:https://pan.baidu.com/s/1cr1fnWGHc-70HAxx1YH4kg 密码:21a8 直接使用这个编排文件可能会有问题,最好勤劳如下使用helm跑,也可避免更改配置遗漏或错误的问题,适用用于实验,如若搭建请注意修改Volum、requestsource等Pod设置