前言

公有仓库用于企业外部公有 Docker 镜像的存储。

能够将公有仓库装置到 K8S 集群中。

Harbor 镜像仓库是由 VMware 开源的一款企业级镜像仓库零碎。

更新历史

  • 20200719 - 初稿 - 左程立
  • 原文地址 - https://blog.zuolinux.com/2020/07/19/harbor.html

自定义证书

openssl genrsa -out ca.key 4096openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=zuolinux.com" -key ca.key -out ca.crtopenssl genrsa -out harbor.zuolinux.com.key 4096openssl req -sha512 -new -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=zuolinux.com"  -key harbor.zuolinux.com.key -out harbor.zuolinux.com.csr
cat > v3.ext <<-EOFauthorityKeyIdentifier=keyid,issuerbasicConstraints=CA:FALSEkeyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEnciphermentextendedKeyUsage = serverAuthsubjectAltName = @alt_names[alt_names]DNS.1=harbor.zuolinux.comDNS.2=*.harbor.zuolinux.comDNS.3=hostnameEOF
openssl x509 -req -sha512 -days 3650 \    -extfile v3.ext \    -CA ca.crt -CAkey ca.key -CAcreateserial \    -in harbor.zuolinux.com.csr \    -out harbor.zuolinux.com.crt
openssl x509 -inform PEM -in harbor.zuolinux.com.crt -out harbor.zuolinux.com.cert

装置 harbor

helm install nginx-ingress --set "rbac.create=true,controller.service.externalIPs[0]=192.168.10.15" apphub/nginx-ingress
kubectl create ns harborkubectl create secret tls harbor.zuolinux.com --key harbor.zuolinux.com.key --cert harbor.zuolinux.com.crt -n harborhelm repo add harbor https://helm.goharbor.iohelm repo updatehelm install harbor --namespace harbor harbor/harbor \  --set expose.ingress.hosts.core=core.harbor.zuolinux.com \  --set expose.ingress.hosts.notary=notary.harbor.zuolinux.com \  --set expose.tls.secretName=harbor.zuolinux.com \  --set persistence.enabled=false \  --set externalURL=https://core.harbor.zuolinux.com \  --set harborAdminPassword=明码

查看装置状况和服务地址

# helm status harbor# kubectl get pod# kubectl get pv# kubectl get pvc# kubectl get service

拜访 harbor

本地配置 HOSTS

192.168.10.15   core.harbor.zuolinux.com

浏览器拜访 https://core.harbor.zuolinux.com

Docker 镜像仓库治理

拷贝证书至 Docker 的证书配置目录

mkdir -p /etc/docker/certs.d/core.harbor.zuolinux.com/cp harbor.zuolinux.com.cert /etc/docker/certs.d/core.harbor.zuolinux.com/cp harbor.zuolinux.com.key /etc/docker/certs.d/core.harbor.zuolinux.com/cp ca.crt /etc/docker/certs.d/core.harbor.zuolinux.com/

推送镜像

docker tag nginx core.harbor.zuolinux.com/library/nginx:latestdocker push core.harbor.zuolinux.com/library/nginx:latest

浏览器登录 harbor 能够看到曾经有镜像了

下载镜像

docker rmi core.harbor.zuolinux.com/library/nginx:latestdocker pull core.harbor.zuolinux.com/library/nginx:latest 

Helm Chart 仓库治理

Helm Push 插件

helm plugin install https://github.com/chartmuseum/helm-push

创立 Repo

WEB 页面中创立我的项目 myrepo

增加仓库到本地,留神 chartrepo 是关键字,要保留不能批改

helm repo add myrepo https://core.harbor.zuolinux.com/chartrepo/myrepo --ca-file /root/harbor/ca.crt --username=admin --password=明码

本地创立一个测试 Chart

helm create testapp

推送到仓库

helm push --ca-file /root/harbor/ca.crt --username=admin --password=明码 testapp myrepo

在 WEB 页面上 chartrepo 我的项目下的 Helm Chats 中能够看到推送上来的 Chart 包

结束语

Harbor 使集体和企业领有了自主创立和治理公有仓库的能力。

分割我

微信公众号:zuolinux_com