harbor1.7.5部署 软清理和硬清理 + helm3.5

Centos7安装harbor+ssl登录测试(亲测可用)_ccren的专栏-CSDN博客_harbor ssl

helm3使用入门 - —八戒— - 博客园

Harbor 1.7部署_HF的博客-CSDN博客

Harbor私有镜像仓库搭建https_HF的博客-CSDN博客

Harbor集成Clair镜像安全扫描并手动导入漏洞数据_arnolan的博客-CSDN博客_clair_vuln_timestamp

证书生成脚本https://blog.csdn.net/Michaelwubo/article/details/122215570icon-default.png?t=LBL2https://blog.csdn.net/Michaelwubo/article/details/122215570

这个是自签名

$ mkdir -p /data/cert
$ cd /data/cert/

创建CA证书


$ openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt
 
Generating a 4096 bit RSA private key
..........................................++
........++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:superred
Organizational Unit Name (eg, section) []:Linux
Common Name (eg, your name or your server's hostname) []:harbor.superred.com
Email Address []:wubo@superred.com

生成证书签名请求

openssl req -newkey rsa:4096 -nodes -sha256 -keyout superred.com.key -out superred.com.csr
 
Generating a 4096 bit RSA private key
....++
...................................................................................++
writing new private key to 'sunline.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:superred
Organizational Unit Name (eg, section) []:HaiTeng
Common Name (eg, your name or your server's hostname) []:harbor.superred.com
Email Address []:wubo@superred.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

生成注册表主机的证书

openssl x509 -req -days 365 -in superred.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out superred.com.crt
 
Signature ok
subject=/C=CN/ST=beijing/L=beijing/O=superred/OU=HaiTeng/CN=harbor.superred.com/emailAddress=wubo@superred.com

如果你使用的是IP,比如10.10.3.104(本机主机IP地址)连接你的注册表主机,你可以运行下面的命令

echo subjectAltName = IP:10.10.3.104 > extfile.cnf
$ openssl x509 -req -days 365 -in superred.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out superred.com.crt

也可以用nginx+https+自签名+各种云dns解析+浏览器安全可用include相对路径和绝对路径 _码农崛起-CSDN博客 浏览器可人的签名

下载离线文件:https://github.com/goharbor/harbor/releases 

修改配置文件

[root@localhost harbor1.7.5]# ls
common  createproject.json  docker-compose.chartmuseum.yml  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  harbor.cfg  harbor.v1.7.5.tar.gz  install.sh  LICENSE  open_source_license  prepare

$ cd  harbor
 
total 590236
 
drwxr-xr-x. 3 root root        23 Jan 29 21:26 common
 
-rw-r--r--. 1 root root       946 Jan 29 21:38 docker-compose.chartmuseum.yml
 
-rw-r--r--. 1 root root       975 Jan 29 21:36 docker-compose.clair.yml
 
-rw-r--r--. 1 root root      1434 Jan  4 06:23 docker-compose.notary.yml
 
-rw-r--r--. 1 root root      5692 Jan 29 21:39 docker-compose.yml
 
-rw-r--r--. 1 root root      8040 Jan 29 21:30 harbor.cfg
 
-rw-r--r--. 1 root root 603562385 Jan  4 06:24 harbor.v1.7.1.tar.gz
 
-rwxr-xr-x. 1 root root      5739 Jan  4 06:23 install.sh
 
-rw-r--r--. 1 root root     11347 Jan  4 06:23 LICENSE
 
-rw-r--r--. 1 root root    748160 Jan  4 06:23 open_source_license
 
-rwxr-xr-x. 1 root root     36351 Jan 29 21:46 prepare
 
  
 
# 修改配置文件
 
    ## 修改配置文件harbor.cfg参数
 
    sed -i "s#hostname = reg.mydomain.com#hostname = harbor.suprered.com#g"  harbor.cfg 
    ## 可以是主机IP,或者是以后要用的域名
 
    sed -i "s#ui_url_protocol = http#ui_url_protocol = https#g"  harbor.cfg 
    ## 使用的协议,此处用的是https,后面安装的时候,再添加漏洞检查的时候需要https的支持
 
    sed -i "s#ssl_cert = /data/cert/server.crt#ssl_cert = /data/harbor/cert/suprered.com.crt#g"  harbor.cfg
    ## 证书的路径必须先创建好,并把秘钥放入配置文件
 
    sed -i "s#ssl_cert_key = /data/cert/server.key#ssl_cert_key = /data/harbor/cert/suprered.com.key#g"  harbor.cfg
 
    sed -i "s#secretkey_path = /data#secretkey_path = /data/harbor#g"  harbor.cfg
 
 
    ## 可以使用默认的路径
   ## 由于指定安装路径需求,需要修改一下所有部署相关文件的指定路径()
 
sed -i "s#/data/registry#/data/harbor/registry#g" docker-compose.yml
 
sed -i "s#/data/ca_download#/data/harbor/ca_download#g" docker-compose.yml
 
sed -i "s#/data/config#/data/harbor/config#g" docker-compose.yml
 
sed -i "s#/data/database#/data/harbor/database#g" docker-compose.yml
 
sed -i "s#/data/job_logs#/data/harbor/job_logs#g" docker-compose.yml
 
sed -i "s#/data/psc#/data/harbor/psc#g" docker-compose.yml
 
sed -i "s#/data/redis#/data/harbor/redis#g" docker-compose.yml
 
sed -i "s#/data/registry#/data/harbor/registry#g" docker-compose.yml
 
sed -i "s#/data/secretkey#/data/harbor/secretkey#g" docker-compose.yml
 
sed -i "s#/data/clair-db#/data/harbor/clair-db#g" docker-compose.clair.yml
 
sed -i "s#/data/notary-db#/data/harbor/notary-db#g" docker-compose.yml
 
sed -i "s#/data/:/data/:z#/data/harbor/:/data/:z#g" docker-compose.yml
 
sed -i "s#/data/chart_storage#/data/harbor/chart_storage#g" docker-compose.chartmuseum.yml
 
sed -i "s#"/data"#/data/harbor#"  prepare

安装Harbor

更新

./prepare --with-clair --with-notary  --with-chartmuseum

安装,(helm3)目前尝试过推送到harbor中,首先harbor要支持charts,需要在安装时添加参数–with-chartmuseum,

这样在harbor的项目详情页面就会有个叫 Helm Charts 的标签

./install.sh --with-notary --with-clair --with-chartmuseum
 
# 如果需要在Harbor中启用Notary,请设置--with-notary,并在harbor.cfg中设置ui_url_protocol/ssl_cert/ssl_cert_key,因为公证必须在https下运行。
 
# 如果需要启用Clair in Harbour,请设置--with-clair
 
# 如果需要在Harbor启用Chartmuseum,请设置--with-chartmuseum

重启容器

docker-compose down -v
vi harbor.cfg                            ## 修改要更新的配置
vi docker-compose.yml          ## 修改要更新的配置
./prepare
docker-compose up -d

清理

可以在web页面删除此时是软清理物理磁盘还在

harbor仓库完全清理方式_leoss的博客-CSDN博客_harbor 清理

Harbor镜像清理 - breezey - 博客园

博客园

Harbor私有仓库中删除镜像释放存储空间 - Cslc-DaweiJ - 博客园

硬清理 尝试:

docker run -it --name gc  --rm --volumes-from registry registry.cn-hangzhou.aliyuncs.com/jonny/registry-photon:v2.6.2-v1.5.0 garbage-collect  --dry-run /etc/registry/config.yml

真硬清理 去掉 --dry-run 即可

1.docker-compose stop

2.docker run -it --name gc  --rm --volumes-from registry registry.cn-hangzhou.aliyuncs.com/jonny/registry-photon:v2.6.2-v1.5.0 garbage-collect   /etc/registry/config.yml

3.docker-compose start

#进入导harbor yaml文件所在目录
cd /usr/local/src/harbor 
#停止harbor
docker-compose stop 
#使用清理镜像进行垃圾回收
#使用--dry-run 参数进行预览,不使用则进行清理
docker run -it --name gc --rm --volumes-from registry vmware/registry:2.6.2-photon garbage-collect  /etc/registry/config.yml 
#重新启动harbor
docker-compose start

对比删除后的目录大小

du -sh /data/registry/docker/registry/v2/blobs
du -sh /data/registry/docker/registry/v2/repositories
api: 很多功能https://www.jianshu.com/p/bfa4d1436a07
curl  -k -u "admin:Harbor12345"  -X GET -H "Content-Type: application/json"  "https://harbor.superred.com/api/repositories?project_id=2&id=18"

helm3

1、新的功能
    1.版本以新格式存储

    2.没有群集内(分iller)组件

    3.Helm 3包括对新版Helm图表的支持(图表v2)

    4.Helm 3还支持库图表-图表主要用作其他图表的资源。

    5.用于在OCI注册表中存储Helm图表的实验支持(例如Docker Distribution)可以进行测试。

    6.现在在升级Kubernetes资源时将应用3向战略合并补丁。

    7.现在可以根据JSON模式验证图表提供的值

    8.为了使Helm更安全,可用和健壮,已进行了许多小的改进。

2、 Helm3的内部实现已从 Helm2发生了很大变化,使其与 Helm2不兼容

该版本主要变化如下

1、最明显的变化是 Tiller的删除640.png

2、Release 不再是全局资源,而是存储在各自命名空间内

3、Values 支持 JSON Schema校验器,自动检查所有输入的变量格式

4、移除了用于本地临时搭建 Chart Repository 的 helm serve 命令。

5、helm install 不再默认生成一个 Release 的名称,除非指定了 --generate-name。

6、Helm CLI 个别更名

1

2

3

<code class="language-bash hljs">helm delete更名为 helm uninstall

helm inspect更名为 helm show

helm fetch更名为 helm pull</code>

3、先决条件

要成功且正确地确保使用Helm,必须满足以下先决条件。

  1. Kubernetes集群

  2. 确定要应用于安装的安全性配置(如果有)

  3. 安装和配置Helm。

4、安装Kubernetes或有权访问集群

  • 必须安装Kubernetes。对于Helm的最新版本,我们建议使用Kubernetes的最新稳定版本,在大多数情况下,它是第二最新的次要版本。

  • 还应该具有的本地配置副本kubectl。

注意:1.6之前的Kubernetes版本对基于角色的访问控制(RBAC)的支持有限或不支持。

5、 从二进制版本

每一个[版本](Releases · helm/helm · GitHub)helm提供多种操作系统的二进制版本。这些二进制版本可以手动下载和安装。

1 下载[所需版本]
root@koji:~ # wget  https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz

2. 打开包装
root@koji:~ # tar -zxvf helm-v3.0.0-linux-amd64.tgz
  
3.helm在解压后的目录中找到二进制文件,然后将其移至所需的目标位置
root@koji:~ # mv linux-amd64/helm /usr/local/bin/helm

4 在客户端运行:
root@koji:~ #  helm help

或 

6、从脚本

Helm现在具有一个安装程序脚本,该脚本将自动获取最新版本的Helm并将[其本地安装]

1 . Helm现在具有一个安装程序脚本,该脚本将自动获取最新版本的Helm并将[其本地安装] 
https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
2 可以获取该脚本,然后在本地执行它。它有充分的文档记录,因此您可以在运行它之前通读它并了解它在做什么。

3.root@koji:~ #   curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm/ get_helm.sh
4.root@koji:~ #   chmod 700 get_helm.sh
5. root@koji:~ #   ./get_helm.sh

查看配置信息

[root@i-pcwovafu bin]# helm env
HELM_NAMESPACE="default"
HELM_KUBECONTEXT=""
HELM_BIN="helm"
HELM_DEBUG="false"
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"

添加公用的仓库

helm repo add stable http://mirror.azure.cn/kubernetes/charts
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts 
helm repo update

指定对应的k8s集群

这一步非常关键,它是helm与k8s通讯的保证,这一步就是把k8s环境变量KUBECONFIG进行配置

注:v3版本不再需要Tiller,而是通过ApiServer与k8s交互,可以设置环境变量KUBECONFIG来指定存有ApiServre的地址与token的配置文件地址,默认为~/.kube/config

export KUBECONFIG=/root/.kube/config #可以写到/etc/profile里

helm push 插件 helm(3.0.3)现在默认不支持推送到charts库,需要安装插件helm-push

一,helm增加helm push插件

如果可以连网
1)root@koji:~ # helm plugin install https://github.com/chartmuseum/helm-push

2) root@koji:~ git clone https://github.com/chartmuseum/helm-push.git
   2.1 helm plugin install .  #下载太慢了 可以先下载
[root@localhost helm-push]# cp ../helm-push_0.9.0_linux_amd64.tar.gz releases/v0.9.0.tar.gz
vim scripts/install_plugin.sh
注释  不让下载了
# Download with curl if possible.
#if [ -x "$(which curl 2>/dev/null)" ]; then
#    curl -sSL "${url}" -o "releases/v${version}.tar.gz"
#else
#    wget -q "${url}" -O "releases/v${version}.tar.gz"
#fi


[root@localhost helm-push]# helm plugin list
NAME	VERSION	DESCRIPTION                      
push	0.9.0  	Push chart package to ChartMuseum


[root@localhost helm-push]# helm push help
Error: This command needs 2 arguments: name of chart, name of chart repository (or repo URL)
Usage:
  helm push [flags]

Flags:
      --access-token string             Send token in Authorization header [$HELM_REPO_ACCESS_TOKEN]
      --auth-header string              Alternative header to use for token auth [$HELM_REPO_AUTH_HEADER]
      --ca-file string                  Verify certificates of HTTPS-enabled servers using this CA bundle [$HELM_REPO_CA_FILE]
      --cert-file string                Identify HTTPS client using this SSL certificate file [$HELM_REPO_CERT_FILE]
      --check-helm-version              outputs either "2" or "3" indicating the current Helm major version
      --context-path string             ChartMuseum context path [$HELM_REPO_CONTEXT_PATH]
      --debug                           Enable verbose output
  -d, --dependency-update               update dependencies from "requirements.yaml" to dir "charts/" before packaging
  -f, --force                           Force upload even if chart version exists
  -h, --help                            help for helm
      --home string                     Location of your Helm config. Overrides $HELM_HOME (default "/root/.helm")
      --host string                     Address of Tiller. Overrides $HELM_HOST
      --insecure                        Connect to server with an insecure way by skipping certificate verification [$HELM_REPO_INSECURE]
      --key-file string                 Identify HTTPS client using this SSL key file [$HELM_REPO_KEY_FILE]
      --keyring string                  location of a public keyring (default "/root/.gnupg/pubring.gpg")
      --kube-context string             Name of the kubeconfig context to use
      --kubeconfig string               Absolute path of the kubeconfig file to be used
  -p, --password string                 Override HTTP basic auth password [$HELM_REPO_PASSWORD]
      --tiller-connection-timeout int   The duration (in seconds) Helm will wait to establish a connection to Tiller (default 300)
      --tiller-namespace string         Namespace of Tiller (default "kube-system")
  -u, --username string                 Override HTTP basic auth username [$HELM_REPO_USERNAME]
  -v, --version string                  Override chart version pre-push

Error: plugin "push" exited with error

如果不能连网
3)root@koji:~ # wget https://github.com/chartmuseum/helm-push/releases/download/v0.9.0/helm-push_0.9.0_linux_amd64.tar.gz
root@koji:~ # helm plugin install helm-push_0.9.0_linux_amd64.tar.gz

4)或是直接把helm-push_0.9.0_linux_amd64.tar.gz里的文件cp到$HELM_PLUGINS目录(此目录可以通过helm env命令获得)。

 push charts 先要添加repo(其实不加好像直接url也行,我这里先加上)

root@koji:~ # helm repo add myharborlib  https://[harbor-domain-name]/chartrepo/chart_repo --ca-file /root/helm/ca/newca/ca.crt

[root@localhost app]#  helm repo add superred https://harbor.cclinux.com.cn/chartrepo/charts 
[root@localhost app]# helm repo list
NAME    	URL                                           
aliyuncs	https://apphub.aliyuncs.com                   
superred	https://harbor.cclinux.com.cn/chartrepo/charts

因为harbor默认是带ssl认证的所以得需要上harbor上找到之前的证书,这里是自签的证书/root/helm/ca/newca/ca.crt   浏览器可人的签名就不用加/root/helm/ca/newca/ca.crt了

root@koji:~ #  helm repo list
NAME       	URL                                                         
harbor     	https://helm.goharbor.io                                    
myharborlib	https://[harbor-domain-name]/chartrepo/chart_repo

然后push,这里有个坑,我这项目chart_repo是公共项目,按理说公共项目是不要用户名密码的,但是不添加报错,加了就好了

root@koji:~ # helm push mychart/ myharborlib --ca-file /root/helm/ca/newca/ca.crt -u admin -p Harbor12345

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值