前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kubernetes五个实用的自动化运维脚本 -香~

Kubernetes五个实用的自动化运维脚本 -香~

作者头像
公众号: 云原生生态圈
发布2020-11-02 11:23:05
1.6K3
发布2020-11-02 11:23:05
举报
文章被收录于专栏:云原生生态圈

五个常用的Kubernetes运维脚本

findEmptyNamespaces.sh

遍历集群中的所有名称空间并找到空的namespace

代码语言:javascript
复制
? ? ./findEmptyNamespaces.sh default
kube-public
online
test

getPodsTopCSV.sh

获取以CSV格式文件编写的Pod的cpu和内存使用情况

代码语言:javascript
复制
? ? ./getPodsTopCSV.sh --help
./getPodsTopCSV.sh - Get formatted results of kubectl top pod in a Kubernetes cluster for a selected namespace and pod in a CSV format

Usage: ./getPodsTopCSV.sh <options>

-n | --namespace <name>                : Namespace to analyse.      Default: default
-p | --pod <name>                      : Pod to analyse.
-d | --duration <seconds>              : Duration of sampling.      Default: 0 (infinite)
-i | --interval <seconds>              : Interval between samples.  Default: 5
-o | --output <name>                   : Output file.               Default: top-<timestamp>.csv
-c | --containers                      : Output per container.      Default: off
-q | --quite                           : Don't output to screen.    Default: Output to screen
-h | --help                            : Show this usage
--no-headers                           : Don't print headers line

Examples:
========
Get for pod foo in namespace bar:                                $ ./getPodsTopCSV.sh --namespace bar --pod foo
Get for pod foo in namespace bar and output to file foo.csv :    $ ./getPodsTopCSV.sh --namespace bar --pod foo --output foo.csv

getResourcesCSV.sh

以CSV格式获取每个容器的所有容器资源请求和限制,并对其值进行标准化。CSV格式非常易于自动化,非常适合粘贴到Excel进行进一步处理。

代码语言:javascript
复制
? ? ./getResourcesCSV.sh --help

./getResourcesCSV.sh - Extract resource requests and limits in a Kubernetes cluster for a selected namespace or all namespaces in a CSV format

Usage: ./getResourcesCSV.sh <options>

-n | --namespace <name>                : Namespace to analyse.    Default: --all-namespaces
-o | --output <name>                   : Output file.             Default: resources.csv
-q | --quite                           : Don't output to screen.  Default: Output to screen
-h | --help                            : Show this usage
--no-headers                           : Don't print headers line

Examples:
========
Get all:                                                  $ ./getResourcesCSV.sh
Get for namespace foo:                                    $ ./getResourcesCSV.sh --namespace foo
Get for namespace foo and use output file bar.csv :       $ ./getResourcesCSV.sh --namespace foo --output bar.csv

getRestartingPods.sh

获取在一个或多个容器中检测到重新启动的所有Pod(全部或单个命名空间)。格式为CSV。

代码语言:javascript
复制
? ? ./getRestartingPods.sh --help
./getRestartingPods.sh - Extract resource requests and limits in a Kubernetes cluster for a selected namespace or all namespaces in a CSV format

Usage: ./getRestartingPods.sh <options>

-n | --namespace <name>                : Namespace to analyse.    Default: --all-namespaces
-o | --output <name>                   : Output file.             Default: restarting.csv
-q | --quite                           : Don't output to screen.  Default: Output to screen
-h | --help                            : Show this usage
--no-headers                           : Don't print headers line

Examples:
========
Get all:                                                  $ ./getRestartingPods.sh
Get for namespace foo:                                    $ ./getRestartingPods.sh --namespace foo
Get for namespace foo and use output file bar.csv :       $ ./getRestartingPods.sh --namespace foo --output bar.csv

podReady.sh

检查Pod是否真的准备就绪的简单脚本。检查状态为“正在运行”,并且所有容器均已准备就绪。如果准备就绪,则返回0。如果尚未准备就绪,则返回1。

代码语言:javascript
复制
? ? ./podReady.sh kube-flannel-ds-lf87p kube-system

脚本下载地址请在订阅号【云原生生态圈】后台回复k8s脚本即可获取。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-10-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 云原生生态圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • findEmptyNamespaces.sh
  • getPodsTopCSV.sh
  • getResourcesCSV.sh
  • getRestartingPods.sh
  • podReady.sh
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档