__director

kubernetes 获取deployment在使用的镜像(不全)

for i in `kubectl  get   deployments.apps    |  awk 'NR>1{print $1}'`;do
  kubectl  get  deployment  $i -o jsonpath="{.spec.template.spec.containers[0].image}" ;
  echo ""
done |awk '!($1 in a){a[$1];print $1}'

 默认为 default    namespace

其他namespce 

for i in `kubectl  get   deployments.apps -n namespace | awk 'NR>1{print $1}'`;do
  kubectl  get -n namespace deployment  $i -o jsonpath="{.spec.template.spec.containers[0].image}" ;
  echo ""
done |awk '!($1 in a){a[$1];print $1}'

 

#!/usr/bin/env bash
# Author: 原件
# Date: 2021/2/26
# Description: 只适用于pod里面仅有单个容器场景。initcontainer 不会显示。

echo "start get deployment control images, namespace is default, if need other namespces, please use getimages yournamespace"
echo ""

ns=$1
if [ -z $ns ];then
  ns=default
fi

for i in `kubectl  get   deployments.apps  -n $ns  |  awk 'NR>1{print $1}'`;do
  kubectl  get  deployment -n $ns $i -o jsonpath="{.spec.template.spec.containers[0].image}" ;
  echo ""
done |awk '!($1 in a){a[$1];print $1}'

 

posted on 2021-02-22 20:06  __director  阅读(643)  评论(0编辑  收藏  举报

导航