基于Rancher+K3S(K8S)环境导出Charts(需要helm)、docker镜像、POD的yaml

有时候我们需要从一个环境中,把当前的Helm-Charts、对应docker镜像文件,甚至有一些通过其他手段搞出来的POD的yaml导出来,然后在另一个环境中使用

这里面就是一些我们自己用到的工具,分享出来,自愿使用或修改。

有问题不负责 ^_^。

所有内容都在 https://github.com/wangxi83/migration_util


1- 导出镜像(特别说明:“2”中更新了在获取charts的同时导出charts对应的镜像的方法

File: ./save-images-to-tar/save-images.sh

Usage:

1) list your images
docker images | grep <some grep>|awk '{printf("%s:%s\n",$1,$2)}'  >> images.txt
docker images | grep <some grep>|awk '{printf("%s:%s\n",$1,$2)}'  >> images.txt
.... and more images 

2) save them to a single tar file
./save-images-to-tar/save-images.sh --image-list ./images.txt

a all-images.tar.gz file will craete. We can docker load from it

Fearther, you can use ‘./save-images-to-tar/load-images-registry.sh’ to upload images to a registry


2- helm-charts

File: ./getcharts.sh

Usage:

help ()
{
    echo  ' ================================================================ '
    echo  ' 在当前目录的 charts-out-put 目录中,创建rancher中特定的charts最新版本 '
    echo  ' --rancher-server: 必选,rancher的访问地址'
    echo  ' --rancher-api-key: 必须。从rancher的api&key中获取的apikey'
    echo  ' --rancher-project-id:必须。在rancher上点击一个项目,从地址栏中取得的项目id'
    echo  ' --harbor-server: 必须。harbor的地址'
    echo  ' --save-image:可选,默认false,设置chats里面对应的docker镜像输出目录。如果设定,则会把images导出到charts-out-put/images '
    echo  ' 使用示例,导出project-id=c-bsv8l:p-rcv69的所有charts,并且把镜像输出到images目录'
    echo  ' ./getcharts.sh --rancher-server=dbu.rancher.com --rancher-api-key=token-9zqtt:lj2j78jqjcqmgdx8n4kftn5j79rmq99j7hn548q8jc54shw9t8v2bm \'
    echo  ' --rancher-project-id=c-bsv8l:p-rcv69  --harbor-server=harbor.sobey.com --save-image=true'
    echo  ' ================================================================'
}


after this, all charts will downloaded to dir ./charts-out-put ,如果传入了–save-image=true,则会导出所有对应的镜像到 ./charts-out-out/images中


3- pod-yamls

File: ./getyaml.sh

Usage:

help ()
{
    echo  ' ================================================================ '
    echo  ' --kubectl:optional。the path to kubectl '
    echo  ' --type: must。k8s resourcetype,ex. pods。'
    echo  ' --ns:must。k8s namespace'
    echo  ' --kubeconfig:optional。Kubeconfig file'
    echo  ' --grep: optional。some grep workds '
    echo  ' 使用示例:'
    echo  ' ./getyaml.sh --type=pods --ns=sobeyficus '
    echo  ' ================================================================'
}

after this, all yamls will download to ./getyamlout. And then we can kubectl apply -f ./getyamlout to apply them to another cluster

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值