K8S实战(二十)| 企业私有镜像仓库

码农天地 -
K8S实战(二十)| 企业私有镜像仓库
前言

私有仓库用于企业内部私有 Docker 镜像的存储。

可以将私有仓库安装到 K8S 集群中。

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

更新历史20200719 - 初稿 - 左程立原文地址 - https://blog.zuolinux.com/2020/07/19/harbor.html自定义证书
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
安装 harbor
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=密码

查看安装情况和服务地址

# 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:latest
docker push core.harbor.zuolinux.com/library/nginx:latest

浏览器登录 harbor 可以看到已经有镜像了

下载镜像

docker rmi core.harbor.zuolinux.com/library/nginx:latest
docker 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

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

加个好友,技术交流

1628738909466805.jpg