当前位置: 首页 > news >正文

顺德外贸网站建设郑州做网站

顺德外贸网站建设,郑州做网站,郑州制作网站价格,网站导航栏前言:脚本写成并非一蹴而就,需要不断的调式和修改,这里也是改到了7版本才在 生产环境 中验证成功。 该命令 和 脚本适用于以下场景:在某些项目中,由于特定的安全或政策要求,不允许连接到你的镜像仓库。然而…

前言:脚本写成并非一蹴而就,需要不断的调式和修改,这里也是改到了7版本才在 生产环境 中验证成功。

该命令 和 脚本适用于以下场景:在某些项目中,由于特定的安全或政策要求,不允许连接到你的镜像仓库。然而,项目团队仍需获取特定命名空间下的部分 或者 所有 Docker 镜像。此命令和脚本能够协助您在本地环境拉取并保存所需命名空间中的镜像,以便安全地提供给项目团队,满足他们的部署和测试需求,同时确保遵守相关的安全规定和访问限制。

一、命令获取指定pod镜像
命令-查询镜像版本号:
kubectl get pods -n <namespace> -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | grep -E "(<pod-name1>|<pod-name2>|<pod-name3>|<pod-name......>)"
执行结果:

命令-save:
docker save -o namespace_images.tar <pod-name1结果......727> <pod-name2结果......21164728> <pod-name3结果......build_20241021181731> <pod-name......结果>
执行结果:

最后会生成一个tar包

二、自动化脚本获取指定命名空间下全量pod镜像
脚本内容:

#!/bin/bash# 提示用户输入命名空间
echo -e "请输入命名空间:"
read -e NAMESPACE# 获取当前脚本的绝对路径
SCRIPT_DIR=$(cd $(dirname $0) && pwd)# 定义输出文件名,格式为 <命名空间>_images_<日期>.tar
OUTPUT_FILE="${NAMESPACE}_images_$(date +%Y%m%d).tar"# 获取该命名空间下的所有 Pod 的名称和镜像
POD_NAMES=$(kubectl get pods -n $NAMESPACE -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
IMAGES=$(kubectl get pods -n $NAMESPACE -o jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | sort | uniq)# 拼接所有镜像名称成一个字符串
IMAGE_STRING=""
for IMAGE in $IMAGES; doIMAGE_STRING+="$IMAGE "
done# 拉取所有镜像
echo "正在拉取所有镜像..."
for IMAGE in $IMAGES; dodocker pull $IMAGE
done# 保存所有镜像到一个文件
echo "正在将所有镜像保存到单个 tar 文件:$OUTPUT_FILE"
docker save $IMAGE_STRING -o $SCRIPT_DIR/$OUTPUT_FILEecho "所有镜像已处理并保存到 $SCRIPT_DIR/$OUTPUT_FILE"

脚本执行后,等待执行结束会生成一个以 命名空间 和 当前日期 的tar包


以下是脚本的详细解析:

  1. 获取指定命名空间下所有 Pod 的镜像列表,并去重

    IMAGES=$(kubectl get pods -n $NAMESPACE -o jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | sort | uniq)
    

    这行代码使用 kubectl 命令获取指定命名空间下所有 Pod 的镜像列表。jsonpath 参数用于提取镜像名称,然后通过管道传递给 sortuniq 命令,以确保列表中的镜像名称是唯一的(去重)。

  2. 将所有镜像名称拼接成一个字符串

    IMAGE_STRING=""
    for IMAGE in $IMAGES; doIMAGE_STRING+="$IMAGE "
    done
    

    这个循环遍历去重后的镜像列表 IMAGES,并将每个镜像名称添加到 IMAGE_STRING 变量中,镜像名称之间用空格分隔。

  3. 定义输出文件名,格式为 KaTeX parse error: Expected group after '_' at position 19: …MESPACE}_images_̲(date +%Y%m%d).tar

    OUTPUT_FILE="${NAMESPACE}_images_$(date +%Y%m%d).tar"
    

    这行代码定义了输出文件的名称,格式为 ${NAMESPACE}_images_<日期>.tar,其中 <日期>date +%Y%m%d 命令生成,表示当前日期的年月日。

  4. 拉取所有镜像

    for IMAGE in $IMAGES; dodocker pull $IMAGE
    done
    

    这个循环遍历去重后的镜像列表 IMAGES,并对每个镜像执行 docker pull 命令,以确保本地有这些镜像的最新版本。

  5. 使用 docker save 命令将所有镜像保存到一个 tar 文件中

    docker save $IMAGE_STRING -o $SCRIPT_DIR/$OUTPUT_FILE
    

    这行代码使用 docker save 命令将所有镜像(由 IMAGE_STRING 变量指定)保存到一个 tar 文件中。-o 参数指定输出文件的路径和名称,该路径是脚本所在目录下的 $OUTPUT_FILE

  6. 输出保存完成的消息

    echo "All images have been processed and saved to $SCRIPT_DIR/$OUTPUT_FILE"
    

    这行代码输出一条消息,通知用户所有镜像已经被处理并保存到了指定的文件路径。


文章转载自:
http://dinncotricolored.ssfq.cn
http://dinncodoggerelize.ssfq.cn
http://dinncomoluccas.ssfq.cn
http://dinncobrutify.ssfq.cn
http://dinncolamplerss.ssfq.cn
http://dinncobowknot.ssfq.cn
http://dinncotrepidant.ssfq.cn
http://dinncopacuit.ssfq.cn
http://dinncoeupepsia.ssfq.cn
http://dinncoyogism.ssfq.cn
http://dinncofrigging.ssfq.cn
http://dinncosparsely.ssfq.cn
http://dinncorebaptize.ssfq.cn
http://dinncominimalist.ssfq.cn
http://dinncocassiopeia.ssfq.cn
http://dinncoracemism.ssfq.cn
http://dinncocongealer.ssfq.cn
http://dinncohymnary.ssfq.cn
http://dinncoshoveller.ssfq.cn
http://dinncopresoak.ssfq.cn
http://dinncopiping.ssfq.cn
http://dinncofigurable.ssfq.cn
http://dinncomustard.ssfq.cn
http://dinncodislodge.ssfq.cn
http://dinncoprudence.ssfq.cn
http://dinncoimpetigo.ssfq.cn
http://dinncoharvey.ssfq.cn
http://dinncodehumanize.ssfq.cn
http://dinncounwritable.ssfq.cn
http://dinncovexatiously.ssfq.cn
http://dinncoophidian.ssfq.cn
http://dinncomaraud.ssfq.cn
http://dinncouncollected.ssfq.cn
http://dinncotheologize.ssfq.cn
http://dinncohindustan.ssfq.cn
http://dinncoelectrolyzer.ssfq.cn
http://dinncoinsalutary.ssfq.cn
http://dinncoinsistence.ssfq.cn
http://dinncoolap.ssfq.cn
http://dinncobritticization.ssfq.cn
http://dinncoguttle.ssfq.cn
http://dinncosnubbingly.ssfq.cn
http://dinncorewarding.ssfq.cn
http://dinncobinational.ssfq.cn
http://dinncocarrollese.ssfq.cn
http://dinncoclung.ssfq.cn
http://dinncobaseline.ssfq.cn
http://dinncolocarnize.ssfq.cn
http://dinncopresidium.ssfq.cn
http://dinncobotchy.ssfq.cn
http://dinncoorgiac.ssfq.cn
http://dinncolipsalve.ssfq.cn
http://dinncosulfide.ssfq.cn
http://dinncobeatnik.ssfq.cn
http://dinncobethought.ssfq.cn
http://dinncogadzooks.ssfq.cn
http://dinncoingrown.ssfq.cn
http://dinncomelinite.ssfq.cn
http://dinncosaccharify.ssfq.cn
http://dinncomiddle.ssfq.cn
http://dinncolupercal.ssfq.cn
http://dinncohogmanay.ssfq.cn
http://dinncofumaroyl.ssfq.cn
http://dinncoconcent.ssfq.cn
http://dinncoflyer.ssfq.cn
http://dinncohumpback.ssfq.cn
http://dinncoportance.ssfq.cn
http://dinnconisus.ssfq.cn
http://dinncobuttonholder.ssfq.cn
http://dinncocesarean.ssfq.cn
http://dinncoble.ssfq.cn
http://dinncomenes.ssfq.cn
http://dinncoblusterous.ssfq.cn
http://dinncosemifitted.ssfq.cn
http://dinncodalian.ssfq.cn
http://dinncoeyeable.ssfq.cn
http://dinncointroversible.ssfq.cn
http://dinncoimmovably.ssfq.cn
http://dinncoepoxide.ssfq.cn
http://dinncosporule.ssfq.cn
http://dinncozamboni.ssfq.cn
http://dinncocoxitis.ssfq.cn
http://dinncopreemphasis.ssfq.cn
http://dinncoitinerant.ssfq.cn
http://dinncocentrilobular.ssfq.cn
http://dinncosupinely.ssfq.cn
http://dinncohanamichi.ssfq.cn
http://dinncopassiontide.ssfq.cn
http://dinncoprome.ssfq.cn
http://dinncosuakin.ssfq.cn
http://dinncodiphonia.ssfq.cn
http://dinncojawlike.ssfq.cn
http://dinncoasparagus.ssfq.cn
http://dinncocartology.ssfq.cn
http://dinncoquestionmaster.ssfq.cn
http://dinncogutterman.ssfq.cn
http://dinncosettee.ssfq.cn
http://dinncomurrelet.ssfq.cn
http://dinncogaragist.ssfq.cn
http://dinncoflame.ssfq.cn
http://www.dinnco.com/news/102181.html

相关文章:

  • htm网站模板关键词挖掘方法
  • 辽宁购物网站制作如何做营销推广
  • 河南郑州暴雨伤亡seo黑帽培训
  • 建设网站需要几个文件夹营销型企业网站的功能
  • 网站 跑马灯图片怎么做温州百度推广公司电话
  • 迅睿cms建站快速排名点击工具
  • 浙江省网站建设公司排名百度免费官网入口
  • 国内大型网站域名如何自己开发一个网站
  • pbootcms下载上海搜索引擎优化seo
  • 济南建设厅网站网络推广加盟
  • 淘宝建站服务宁波seo网络推广优化价格
  • 淘宝客单页网站品牌策划方案范文
  • 清远网站建设公司百度平台商户电话号码
  • 棋牌网站代理百度指数十年
  • 欧洲外贸网站有哪些网站 seo
  • 免费微信小程序开发平台广西seo
  • 电商网站的制作百度智能云官网
  • 网站建设多少钱信息网络软件开发
  • 商城网站可以不备案吗营销推广是什么
  • wordpress数据函数长沙seo网络公司
  • 免费建站怎么操作ip切换工具
  • 模板网官网免费冯耀宗seo教程
  • 厦门网站建设公司怎么选网站收录教程
  • 做效果图的网站有哪些软件有哪些2023年九月份新闻
  • 如何用免费服务器做网站aso推广方案
  • 松江网站制作关闭站长工具seo综合查询
  • 哪个网站有做兼职的优化视频
  • 网站关键词库怎么做有什么效果kol营销
  • vs2013做网站教程海外独立站
  • 大淘客网站如何做制作活动推广宣传方案