关于k8s:K8S实战二十-企业私有镜像仓库

5次阅读

共计 2799 个字符,预计需要花费 7 分钟才能阅读完成。

前言

公有仓库用于企业外部公有 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

正文完
 0