有时候我们需要从一个环境中,把当前的Helm-Charts、对应docker镜像文件,甚至有一些通过其他手段搞出来的POD的yaml导出来,然后在另一个环境中使用
这里面就是一些我们自己用到的工具,分享出来,自愿使用或修改。
有问题不负责 ^_^。
所有内容都在 https://github.com/wangxi83/migration_util
1- 导出镜像
File: ./save-images-to-tar/save-images.sh
Usage:
1) list your images docker images | grep|awk '{printf("%s:%sn",$1,$2)}' >> images.txt docker images | grep |awk '{printf("%s:%sn",$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 ' save charts listed in rancher Apps from helm-repo to dir charts-out-put '
echo ' --rancher-server: must,rancher server address'
echo ' --rancher-api-key: must。rancher apikey for Bearer Token'
echo ' --rancher-project-id:must。rancher project's id from browser address'
echo ' --harbor-server: must。harbor server address'
echo ' 使用示例:'
echo ' ./getcharts.sh --rancher-server=dbu.rancher.com --rancher-api-key=token-9zqtt:lj2j78jqjcqmgdx8n4kftn5j79rmq99j7hn548q8jc54shw9t8v2bm --rancher-project-id=c-bsv8l:p-rcv69 --harbor-server=harbor.sobey.com'
echo ' ================================================================'
}
after this, all charts will downloaded to dir ./charts-out-put
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



