• chart仓库之创建-入库-使用(helm,helm-push,chartmuseum)


    前言:

    使用helm管理chart包,需要三个部门协作完成,都有哪三个部门呢?
    1)  仓库, chartmuseum,  作为chart的存储仓库,一方面提供存储,一方面对外提供上传和下载, 其也包含两部分
                  服务器: 真正提供服务的;
                  客户端/命令行: 用来操作和设置服务器;
    2)helm-push,专门用作上传chart包到仓库中
    3)  helm,  一方面可以访问仓库并从仓库中下载chart包,另一方面可以与自己的实际服务器tiller交互渲染chart包

    一: chartmuseum的安装
    0. 前言
    chartmuseum的安装实际上是可以有多种方式的,常用的方式有
    1,CLI,包括两种个,一种是完全源码安装,一种是手动下载二进制程序,然后直接放到系统目录下(本文选择的)
    2,Docker镜像方式的安装
    3,chart包方式的安装。因为既然他最为一种自定义的chart包仓库,那么肯定是很helm合作的,所以他本身的安装也是可以利用helm安装
       即helm的stable仓库中,是由chartmuseum的chart包的....
       wxy:用这种方式的安装,应该就以为着是将其放到pod里面提供服务了吧....
    官网文档/源码:https://github.com/helm/chartmuseum
    目前可用的仓库地址为:
    http://192.168.48.82:8080/
    1. 安装chartmuseum的命令行客户端
    1),首先windows上通过迅雷下载
          https://s3.amazonaws.com/chartmuseum/release/latest/bin/linux/amd64/chartmuseum
    2),辗转拷贝到目标linux机器上
    3),安装
    chmod +x ./chartmuseum
    mv ./chartmuseum /usr/local/bin
    4), 验证
    chartmuseum --version

    2. 安装chartmuseum服务器
    1),创建system 服务文件,即用systemctl来方便管理,文件中指定chartmuseum的配置文件
           参考链接:https://www.jianshu.com/p/b31a091a4ef2
    # vi /etc/systemd/system/chartmuseum.service
    [Unit]
    Description=chartmuseum
    Requires=network-online.target
    After=network-online.target
    [Service]
    EnvironmentFile=/etc/chartmuseum/chartmuseum.config
    User=root
    Restart=allways
    ExecStart=/usr/local/bin/chartmuseum $ARGS
    ExecStop=/usr/local/bin/chartmuseum step-down
    [Install]
    WantedBy=multi-user.target
    2),配置启动参数
           包括提供服务的端口号; 使用的底层存储的方式以及底层存储的路径(主要是为他选择一块存储,好放置那些chart包呀,可以有多种选择,在这里我们选自本地);
           认证的账号和明码; 等等....
    # vi /etc/chartmuseum/chartmuseum.config
    ARGS=
    --port=8080
    --storage="local"
    --storage-local-rootdir="/var/lib/chartmuseum/chartstorage"
    --log-json
    --basic-auth-user=admin
    --basic-auth-pass="hengsheng123" 
    --auth-anonymous-get        可选,表示对于get操作,不需要认证
    3)启动chartmuseum服务
    # systemctl start chartmuseum
    # systemctl enable  chartmuseum
    # systemctl status chartmuseum

    4)向本地存储中添加chart包,创建索引,真正作为一个chart仓库对外提供服务
     (1)进入到存放chart包的路径下,可以手动放一些chart包,也可以通过某个helm-push工具(后面会说)
         # cd /var/lib/chartmuseum/chartstorage
     (2)添加或删除chart包---
     (3)使用chartmuseum命令工具生成索引文件,之后也可以使用该命令重新生成一个索引文件到指定目录下,
          helm客户端在访问仓库的时候就是使用改文件得到仓库中chart列表
         # chartmuseum --gen-index --storage="local" --storage-local-rootdir="/var/lib/chartmuseum/chartstorage"
     
       注: 目前还没确定这个命令是覆盖掉启动时配置的参数,还是增量设置,这个之后再研究
     (4) 验证,找一个添加本仓库的helm客户端设备将创建的,详见下一个章节
         # helm repo update
         # helm search repo chartmuseum

    5) 放开宿主机的安全策略
    使能网络中其他设置上访问,需要配置防火墙
    systemctl stop firewalld.service
    或者
    iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
    之后,远程访问成功
     
     
    chart仓库(chartmuseum)的工作原理
    存储库索引文件称为index.yaml, 是根据storage中的chart包动态生成的,如果你想使用自己创建该文件,则自动生成的将被忽略;
    注意:  storage中的chart包必须是.tgz格式,否则storage backend不识别,即不会生成到index.yaml中。
    chartmuseum缺省会在内存类型的cache中存储index.yaml文件的内容,也可以通过设置将其offload到外部cache中。
    一旦有index的请求过来,storage backend就会扫描当前storage中所有的chart包,然后和自己cache进行比对然后刷新并将内容返回给请求者。
    当然,你也可以通过设置缓存间隔来周期性刷新index。他会基于storage中的包动态的更新。
     --gen-index 这个命令参数可以扫描当前storage中的chart包,然后生成index.yaml并将其内容打印到标准输出上.
    一旦index 文件重新生成,chartmuseum会在storage中保存一个状态文件称为 index-cache.yaml,用于cache优化。这个文件只在内部使用,但可以用于向simple storage迁移使用。
    当有helm客户端执行 helm repo add chartmuseum http://localhost:8080 或者  helm repo update 时,实际都是向仓库发出了GET /index.yaml 请求
    所以当你手动 add/remove 一个 .tgz 包  from storage时,  他会直接反映给 GET /index.yaml 操作中。
     
    二。helm客户端的安装
    0. 这里安装的是helm v3
        # tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
        # mv linux-amd64/helm /usr/local/bin/helm
        # helm version
    1,查看当前helm客户端可以与哪些仓库连接
    [root@node213 helm-push-master]# helm repo list
    Error: no repositories to show
    2,将自建的chartmuseum仓库加入到helm的repo列表中
    [root@node213 helm-push-master]# helm repo add chartmuseum http://192.168.48.82:8080/ --username admin --password hengsheng123
    "chartmuseum" has been added to your repositories
    [root@node213 helm-push-master]# helm repo list
    NAME        URL                  
    chartmuseum http://192.168.48.82:8080/
    3. 更新远端仓库中的索引文件
    # helm repo update,
    注:
    helm的仓库信息缺省在:/root/.cache/helm/repository  目录下~
    一个xxx-index.yaml文件代表一个仓库,官方缺省仓库对应就是index.yaml文件
     
     
    三: helm-push工具的安装
    helm-push的安装包含两部分:
    1)负责安装的工具包(tar包),包含了安装脚本以及依赖,该脚本会去官方目录下载真正的源码进行呢编译然后安装;
    2)真正的的业务源码包;
    【方式一】
    1, 首先下载helm push的源码,直接在git hub上下载,下载地址是:
    https://github.com/chartmuseum/helm-push
    这里源码的版本是:v0.8.1,这个很重要,因为后面会用到
    2,找一个目录,然后解压,在这里,我的解压目录是/home/wxy/helm-push

    3,  在源码包路径下新建一个目录叫做download,用来放置工具包,并解压
          下载地址为:https://github.com/chartmuseum/helm-push/releases/download/v0.8.1/helm-push_0.8.1_linux_amd64.tar.gz
          0) # cd  /home/wxy/helm-push/download
          1) 解压工具包到目录下
              # tar -xf helm-push_0.8.1_darwin_amd64.tar.gz
           注意:这个注意工具包和源码包不是一回事,他的内容是一些脚本和执行文件,可以看做是安装源码的工具
    4,此时我的目录结构是这样的:
    [root@node213 helm-push]# pwd
    /home/wxy/helm-push
    [root@node213 helm-push]# ll
    ...
    drwxr-xr-x. 3 root root    93 4月  10 16:15 download
    ...
    drwxr-xr-x. 2 root root   100 4月  10 16:07 scripts
    ...
    [root@node213 helm-push]# ll download/
    drwxr-xr-x. 2 root root       22 4月  10 16:15 bin
    -rw-r--r--. 1 root root  9729851 4月  10 16:15 helm-push_0.8.1_linux_amd64.tar.gz
    -rw-r--r--. 1  501 games   11357 12月 17 11:36 LICENSE
    -rw-r--r--. 1  501 games     395 12月 17 11:52 plugin.yaml

    5,修改源码包中的安装脚本
    0) 因为helm安装插件的命令是:
         #helm plugin install /home/wxy/helm-push   ----注意,这个一定要是绝对路径,实际上一般情况下这个往往是git路径
         其原理是:
         首先拉取源码包,然后读取/script/install_plugin.sh文件,最后安装
         所以,因为网络的原因,为了让他不走寻常路,我们需要改一下这个文件
    1)修改/script/install_plugin.sh文件,需要删除:
    if [ "$(uname)" = "Darwin" ]; then
        ...
    fi
        和
    # Download with curl if possible
     ...
    需要增加:
    cp download/helm-push_${version}_linux_amd64.tar.gz releases/v${version}.tar.gz
       解析一下:原逻辑:  是构建一个下载路径,然后下载到releases目录下,再移动到对应的目录下
                         更改之后: 不再实时下载,而是将之前下载到本地的tar包直接复制到这条目录下
    6,正式安装插件
    #helm plugin install /home/wxy/helm-push
    坑:
    # helm push -h
    Error: fork/exec /root/.local/share/helm/plugins/helm-push/bin/helmpush: no such file or directory
    [root@node213 wxy]# cd /root/.local/share/helm/plugins
    [root@node213 plugins]# ll
    lrwxrwxrwx. 1 root root 19 4月  10 16:06 helm-push -> /home/wxy/helm-push
    原因: 因为之前有装过一回,但是安装后报错了,说tar包没获取到,但是软链接已经建立,所以再次安装说已经安装好了,就没理会
              但是,就出现了错误,后来讲链接删除,重新安装,成功了,
    另外,可以发现,helm的plugin目录对应的是/root/.local/share/helm/plugins,并不是网上有的说是/root/.helm/plugins/
               并且,因为这个链接的存在,初始/home/wxy/helm-push目录还不能删除,所以我建议还是按照方式二来安装
       
     
     
    7,使用插件将chart包push 到仓库
    # helm push argo chartmuseum
    Pushing argo-0.7.3.tgz to chartmuseum...
    Done.
     
    8,验证push结果
    1)http访问查看
    curl http://192.168.48.213:8080
    curl http://192.168.48.213:8080

    2)helm客户端查看(helm的安装见下另一个章节)
    helm-push到的是"远端"仓库,所以,如果想在本地看的到,还需要本地刷新一些,获取远端仓库的索引文件
    # helm repo update
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "chartmuseum" chart repository
    Update Complete. ⎈ Happy Helming!⎈
    # helm search repo chartmuseum
    NAME             CHART VERSION APP VERSION DESCRIPTION                   
    chartmuseum/argo 0.7.3         v2.6.1      A Helm chart for Argo Workflows
    wxy:搞了一下午,在没有网络的环境下,搭建了一个仓库,简直要喜极而泣了!!!!
     

    【方式二】
    https://www.cnblogs.com/Dev0ps/p/11258539.html
    尽管我最开始实验没成功,我估计是因为plugin目录不对,换成/root/.local/share/helm/plugins,应该是对的
    坑:
    # helm push xxx
    helm不认识push这个动作...
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    10个很有用的高级Git命令
    25套用于Web UI设计的免费PSD网页元素模板
    101个MySQL 的调节和优化的提示
    10款最新且超实用的开发框架
    30 个有用的 HTML5 和 CSS3 表单设计
    cetos7最小化安装设置网络启动和更新yum源
    百度地图api开发:根据坐标获得地理描述地址
    防止sql注入的函数addslashes()
    jquery使用ajax提交form表单
    Git常用命令
  • 原文地址:https://www.cnblogs.com/shuiguizi/p/14076631.html
Copyright © 2020-2023  润新知