云服务器内容精选

  • 镜像迁移操作步骤 准备镜像仓库访问权限文件:auth.json。 新建一个auth.json文件,并按照格式修改,如果是匿名访问仓库,则不需要填写用户名、密码等信息。将文件放置在image-migrator所在目录下。 示例: { "quay.io/coreos": { }, "swr.cn-north-4.myhuaweicloud.com": { "username": "cn-north-4@RVHVMX******", "password": "***************", "insecure": true } } 详细的参数说明请参见“auth.json”文件。 准备镜像列表文件:images.json。 通过kubectl连接源集群。具体方法可参考使用kubectl连接集群。 执行镜像迁移config子命令,生成images.json文件。 您可以参考image-migrator config使用方法中的方法和示例,不指定命名空间,或者指定一个、多个命名空间来获取源集群应用中使用的镜像。 根据需求调整images.json文件内容,但要遵循“images.json”文件中所讲的八项要求。 镜像迁移。 您可以执行默认的./image-migrator-linux-amd64命令进行镜像迁移,也可以根据需要设置image-migrator的参数。 例如以下命令: ./image-migrator-linux-amd64 --workers=5 --auth=./auth.json --images=./images.json --namespace=test --registry=swr.cn-north-4.myhuaweicloud.com --retries=2 示例: $ ./image-migrator-linux-amd64 Start to generate images tasks, please wait ... Start to handle images tasks, please wait ... Images(38) migration finished, 0 images tasks failed, 0 tasks generate failed 结果查看。 上述命令执行完毕后,回显如下类似信息: Images(38) migration finished, 0 images tasks failed, 0 tasks generate failed 表示按照配置,成功将38个镜像迁移到SWR仓库中。
  • image-migrator工作原理 图1 image-migrator工作原理 使用image-migrator工具将镜像迁移到SWR时,需要准备两个文件,一个为镜像仓库访问权限文件“auth.json”,该文件中的两个对象分别为源镜像仓库和目标镜像仓库(即Registry)的账号和密码;另一个为镜像列表文件“images.json”,文件内容由多条镜像同步规则组成,每一条规则包括一个源镜像仓库(键)和一个目标镜像仓库(值)。将这两个文件准备好以后,放在image-migrator工具所在目录下,执行一条简单的命令,就可以完成镜像的迁移。关于两个文件的详细介绍如下: “auth.json”文件 “auth.json”为镜像仓库访问权限文件,其中每个对象为一个registry的用户名和密码。通常源镜像仓库需要具有pull以及访问tags权限,目标镜像仓库需要拥有push以及创建仓库权限。如果是匿名访问镜像仓库,则不需要填写用户名、密码等信息。“auth.json”文件的结构如下: { "源镜像仓库地址": { }, "目标镜像仓库地址": { "username": "xxxxxx", "password": "***************", "insecure": true } } 其中, “源镜像仓库地址”和“目标镜像仓库地址”支持“registry”和“registry/namespace”两种形式,需要跟下述“images.json”中的registry或registry/namespace对应。images中被匹配到的url会使用对应用户名密码进行镜像同步,优先匹配“registry/namespace”的形式。 目标镜像仓库地址如果为“registry”形式,可以从SWR控制台页面获取,具体方法如下:在“总览”页面单击右上角“登录指令”,登录指令末尾的域名即为SWR镜像仓库地址,例如swr.cn-north-4.myhuaweicloud.com。注意每个Region的地址不同,请切换到对应Region获取。如果为“registry/namespace”形式,还要将namespace替换为SWR的组织名称。 username:(可选)用户名,values可以填写具体取值,也可以使用“${env}”或者“$env”类型的字符串引用环境变量。 password:(可选)密码,values可以填写具体取值,也可以使用“${env}”或者“$env”类型的字符串引用环境变量。 insecure:(可选)registry是否为http服务,如果是,insecure为true;默认是false。 目标镜像仓库SWR的用户名形式为:区域项目名称@AK;密码为AK和SK经过加密处理后的登录密钥,详细指导请参考获取长期有效登录指令。 示例: { "quay.io/coreos": { }, "swr.cn-north-4.myhuaweicloud.com": { "username": "cn-north-4@RVHVMX******", "password": "***************", "insecure": true } } “images.json”文件 该文件本质上是一个待迁移的镜像清单,由多条镜像同步规则组成,每一条规则包括一个源镜像仓库(键)和一个目标镜像仓库(值)。具体的要求如下: 同步的最大单位是仓库(repository),不支持通过一条规则同步整个namespace以及registry。 源仓库和目标仓库的格式与docker pull/push命令使用的镜像url类似(registry/namespace/repository:tag)。 源仓库和目标仓库(如果目标仓库不为空字符串)都至少包含registry/namespace/repository。 源仓库字段不能为空,如果需要将一个源仓库同步到多个目标仓库需要配置多条规则。 目标仓库名可以和源仓库名不同,此时同步功能类似于:docker pull + docker tag + docker push。 当源仓库字段中不包含tag时,表示将该仓库所有tag同步到目标仓库,此时目标仓库不能包含tag。 当源仓库字段中包含tag时,表示只同步源仓库中的一个tag到目标仓库,如果目标仓库中不包含tag,则默认使用源tag。 当目标仓库为空字符串时,会将源镜像同步到默认registry的默认namespace下,并且repository以及tag与源仓库相同,默认registry和默认namespace可以通过命令行参数以及环境变量配置。 示例如下: { "quay.io/coreos/etcd:1.0.0": "swr.cn-north-4.myhuaweicloud.com/test/etcd:1.0.0", "quay.io/coreos/etcd": "swr.cn-north-4.myhuaweicloud.com/test/etcd", "quay.io/coreos/etcd:2.7.3": "swr.cn-north-4.myhuaweicloud.com/test/etcd" } 使用image-migrator工具的config子命令可自动获取集群中工作负载正在使用的镜像,具体用法请参见image-migrator config使用方法。得到images.json文件后,您还可以根据需要进行修改、添加或删除。
  • image-migrator使用方法 image-migrator工具支持在Linux(x86、arm)和Windows环境中运行,使用方法相似。本文将以Linux(x86)环境为例进行介绍。 若使用Linux(arm)或Windows环境,请将下述命令中的image-migrator-linux-amd64分别替换为image-migrator-linux-arm64或image-migrator-windows-amd64.exe。 在image-migrator工具所在目录下执行./image-migrator-linux-amd64 -h,可以查看image-migrator工具的使用方法。 --auth:指定auth.json的路径,默认在image-migrator所在目录下。 --images:指定images.json的路径,默认在image-migrator所在目录下。 --log:指定image-migrator生成日志的路径,默认是image-migrator当前目录下的image-migrator.log。 --namespace:默认的目标仓库的namespace,也就是说,如果images.json中没有指定目标仓库中的namespace,可以在执行迁移命令时指定。 --registry:默认的目标仓库的registry,也就是说,如果images.json中没有指定目标仓库中的registry,可以在执行迁移命令时指定。 --retries:迁移失败时的重试次数,默认为3。 --workers:镜像搬迁的worker数量(并发数),默认是7。 $ ./image-migrator-linux-amd64 -h A Fast and Flexible docker registry image images tool implement by Go. Usage: image-migrator [flags] Aliases: image-migrator, image-migrator Flags: --auth string auth file path. This flag need to be pair used with --images. (default "./auth.json") -h, --help help for image-migrator --images string images file path. This flag need to be pair used with --auth (default "./images.json") --log string log file path (default "./image-migrator.log") --namespace string default target namespace when target namespace is not given in the images config file, can also be set with DEFAULT_NAMESPACE environment value --registry string default target registry url when target registry is not given in the images config file, can also be set with DEFAULT_REGISTRY environment value -r, --retries int times to retry failed tasks (default 3) -w, --workers int numbers of working goroutines (default 7) $./image-migrator --workers=5 --auth=./auth.json --images=./images.json --namespace=test \ --registry=swr.cn-north-4.myhuaweicloud.com --retries=2 $ ./image-migrator Start to generate images tasks, please wait ... Start to handle images tasks, please wait ... Images(38) migration finished, 0 images tasks failed, 0 tasks generate failed 示例如下: ./image-migrator --workers=5 --auth=./auth.json --images=./images.json --namespace=test --registry=swr.cn-north-4.myhuaweicloud.com --retries=2 该命令表示将“images.json”文件中的镜像迁移至“swr.cn-north-4.myhuaweicloud.com/test”镜像仓库下,迁移失败时可以重试2次,一次可以同时搬迁5个镜像。
  • image-migrator config使用方法 image-migrator工具的config子命令可用于获取集群应用中使用的镜像,在工具所在目录下生成images.json。执行./image-migrator-linux-amd64 config -h命令可以查看config子命令的使用方法。 -k, --kubeconfig:指定kubectl的kubeConfig位置,默认是$HOME/.kube/config。kubeConfig文件:用于配置对Kubernetes集群的访问,KubeConfig文件中包含访问注册Kubernetes集群所需要的认证凭据以及Endpoint(访问地址),详细介绍可参见Kubernetes文档。 -n, --namespaces:指定获取镜像的命名空间,多个命名空间用逗号分隔(如:ns1,ns2,ns3),默认是"",表示获取所有命名空间的镜像。 -t, --repo:指定目标仓库的地址(registry/namespace)。 $ ./image-migrator-linux-amd64 config -h generate images.json Usage: image-migrator config [flags] Flags: -h, --help help for config -k, --kubeconfig string The kubeconfig of k8s cluster's. Default is the $HOME/.kube/config. (default "/root/.kube/config") -n, --namespaces string Specify a namespace for information collection. If multiple namespaces are specified, separate them with commas (,), such as ns1,ns2. default("") is all namespaces -t, --repo string target repo,such as swr.cn-north-4.myhuaweicloud.com/test 示例如下: 指定一个命名空间 ./image-migrator-linux-amd64 config -n default -t swr.cn-north-4.myhuaweicloud.com/test 指定多个命名空间 ./image-migrator-linux-amd64 config -n default,kube-system -t swr.cn-north-4.myhuaweicloud.com/test 不指定命名空间(表示获取所有命名空间的镜像) ./image-migrator-linux-amd64 config -t swr.cn-north-4.myhuaweicloud.com/test
  • k8clone备份使用方法 k8clone工具支持在Linux(x86、arm)和Windows环境中运行,使用方法相似。本文将以Linux(x86)环境为例进行介绍。 若使用Linux(arm)或Windows环境,请将下述命令中的k8clone-linux-amd64分别替换为k8clone-linux-arm64或k8clone-windows-amd64.exe。 在k8clone工具所在目录下执行./k8clone-linux-amd64 backup -h,可以查看k8clone工具备份的使用方法。 -k, --kubeconfig:指定kubectl的KubeConfig位置,默认是$HOME/.kube/config。kubeConfig文件:用于配置对Kubernetes集群的访问,KubeConfig文件中包含访问注册kubernetes集群所需要的认证凭据以及Endpoint(访问地址),详细介绍可参见Kubernetes文档。 -s, --api-server:Kubernetes API Server URL,默认是""。 -q, --context:Kubernetes Configuration Context,默认是""。 -n, --namespace:备份指定命名空间的云原生应用,多个命名空间用逗号分隔(如:ns1,ns2,ns3),默认是"",表示备份整个集群。 -e, --exclude-namespaces:排除指定命名空间对象的备份,不能和--namespace一起使用。 -x, --exclude-kind:排除指定资源类型的备份。 -y, --exclude-object:排除指定资源对象的备份。 -w, --exclude-having-owner-ref:排除拥有ownerReferences资源对象的备份,默认是false。 -d, --local-dir:备份数据放置的路径,默认是当前目录下k8clone-dump文件夹。 $ ./k8clone-linux-amd64 backup -h Backup Workload Data as yaml files Usage: k8clone backup [flags] Flags: -s, --api-server string Kubernetes api-server url -q, --context string Kubernetes configuration context -w, --exclude-having-owner-ref Exclude all objects having an Owner Reference -x, --exclude-kind strings Ressource kind to exclude. Eg. 'deployment' -e, --exclude-namespaces strings Namespaces to exclude. Eg. 'temp.*' as regexes. This collects all namespaces and then filters them. Don't use it with the namespace flag. -y, --exclude-object strings Object to exclude. Eg. 'configmap:kube-system/kube-dns' -h, --help help for backup -k, --kubeconfig string The kubeconfig of k8s cluster's. Default is the $HOME/.kube/config. -d, --local-dir string Where to dump yaml files (default "./k8clone-dump") -n, --namespace string Only dump objects from this namespace 示例如下: 整个集群对象的备份,默认路径为当前目录下“k8clone-dump”文件夹 ./k8clone-linux-amd64 backup 整个集群对象的备份,并指定备份数据路径 ./k8clone-linux-amd64 backup -d ./xxxx 指定命名空间对象的备份 ./k8clone-linux-amd64 backup -n default 排除命名空间对象的备份 ./k8clone-linux-amd64 backup -e kube-system,kube-public,kube-node-lease 排除指定资源类型的备份 ./k8clone-linux-amd64 backup -x endpoints,endpointslice 排除指定资源对象的备份 ./k8clone-linux-amd64 backup -y configmap:kube-system/kube-dns 排除拥有ownerReferences资源对象的备份 ./k8clone-linux-amd64 backup -w true