私有仓库用于企业内部私有 Docker 镜像的存储。html
能够将私有仓库安装到 K8S 集群中。node
Harbor 镜像仓库是由 VMware 开源的一款企业级镜像仓库系统。linux
openssl genrsa -out ca.key 4096 openssl 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.crt openssl genrsa -out harbor.zuolinux.com.key 4096 openssl 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 <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1=harbor.zuolinux.com DNS.2=*.harbor.zuolinux.com DNS.3=hostname EOF
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
helm install nginx-ingress --set "rbac.create=true,controller.service.externalIPs[0]=192.168.10.15" apphub/nginx-ingress
kubectl create ns harbor kubectl create secret tls harbor.zuolinux.com --key harbor.zuolinux.com.key --cert harbor.zuolinux.com.crt -n harbor helm repo add harbor https://helm.goharbor.io helm repo update helm 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=密码
查看安装状况和服务地址nginx
# helm status harbor # kubectl get pod # kubectl get pv # kubectl get pvc # kubectl get service
本地配置 HOSTSgit
192.168.10.15 core.harbor.zuolinux.com
浏览器访问 https://core.harbor.zuolinux.comgithub
拷贝证书至 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:latest docker push core.harbor.zuolinux.com/library/nginx:latest
浏览器登陆 harbor 能够看到已经有镜像了微信
下载镜像app
docker rmi core.harbor.zuolinux.com/library/nginx:latest docker pull core.harbor.zuolinux.com/library/nginx:latest
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