zoukankan      html  css  js  c++  java
  • kubernetes资源导出小脚本

    批量导出deploy、svc、ingress等信息

    #!/bin/bash
    #Auth: zisefeizhu  Time: 20210609 Version: v1
     
    DEPLOY=`/usr/local/bin/kubectl get deployment -n zisefeizhu | awk '{print $1}'|grep -E "service|server" ` 
    SVC=`/usr/local/bin/kubectl get svc -n zisefeizhu | awk '{$1=""; print $1}'`
    INGRESS=`/usr/local/bin/kubectl get ingress -n zisefeizhu | awk '{$1=""; print $1}'`
    
    pwd
    
    if [ ! -d "$PWD/zisefeizhu" ]; then
      mkdir -p /Users/edz/test/zisefeizhu
    else
      echo "/zisefeizhu 目录已经存在"
    fi
    
    mkdir -p $PWD/zisefeizhu/deploy
    mkdir -p $PWD/zisefeizhu/svc
    mkdir -p $PWD/zisefeizhu/ingress
    
    for deploy in $DEPLOY
    do
      /usr/local/bin/kubectl get deployment $deploy -n zisefeizhu -o yaml  > $PWD/zisefeizhu/deploy/"${deploy}".yaml;  
    done
    
    
    for svc  in $SVC
    do
      /usr/local/bin/kubectl get svc $svc -n zisefeizhu -o yaml  > $PWD/zisefeizhu/svc/"${svc}".yaml;    
    done
    
    
    for ingress  in $INGRESS
    do
      /usr/local/bin/kubectl get ingress $ingress -n zisefeizhu -o yaml  > $PWD/zisefeizhu/ingress/"${ingress}".yaml;             
    done
    

    删除一些附加字段

    for object in $(find . -name '*.yaml')
    do
      objectName=$object
      /usr/local/bin/yq eval 'del(.metadata.annotations)'  $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.metadata.creationTimestamp)' $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.metadata.generation)' $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.metadata.resourceVersion)' $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.metadata.selfLink)' $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.metadata.uid)' $object > ${object}.1
      object=${object}.1
      /usr/local/bin/yq eval 'del(.status)' $object > $objectName
      #sed -i '' 's/namespace: zisefeizhu/namespace: stage-zisefizhu/g' $objectName
      rm -rf *.1
    done
    
    过手如登山,一步一重天
  • 相关阅读:
    112、TensorFlow初始化变量
    111、TensorFlow 初始化变量
    110、TensorFlow张量值的计算
    109、TensorFlow计算张量的值
    108、TensorFlow 类型转换
    107、TensorFlow变量(三)
    106、TensorFlow变量 (二) reshape
    105、TensorFlow的变量(一)
    104、Tensorflow 的变量重用
    103、Linux 编译 Kaldi 语音识别工具
  • 原文地址:https://www.cnblogs.com/zisefeizhu/p/14874888.html
Copyright © 2011-2022 走看看