首页 > 其他分享 >Kubernetes脚本——检查K8S组件/服务/配置/POD

Kubernetes脚本——检查K8S组件/服务/配置/POD

时间:2024-05-07 23:27:09浏览次数:21  
标签:txt Kubernetes echo hosts result POD k8s check K8S

#!/bin/bash

#echo "运维账号是否有执行常用kubectl运维命令的权限,期望结果:输出/apps/bin/kubelet-----------------------------------------" >k8s_check_result.txt
#ansible -i ./hosts k8s -m shell -a "for i in \`sudo -l\`;do echo \$i|grep -Ei kubectl;done" >> k8s_check_result.txt
#echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s集群kubectl客户端版本检查,期望结果:版本要1.13.2以上-------------------------------------------------------------">k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl version -o yaml|grep server -A 5 |grep -i gitVersion|awk -F ':' '{print \$2}'" >> k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s集群组件状态是否正常检查,期望结果:输出数值5---------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a 'sudo /apps/bin/kubectl get cs |grep -i health |wc -l'>>k8s_check_result.txt
echo -e "-----------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "etcd的配置文件检查,期望结果:输出etcd-------------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a 'ls /apps/conf/ |grep etcd'>>k8s_check_result.txt
echo -e "-----------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "etcd的数据目录检查,期望结果:输出etcd-------------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "ls /apps/data/ |grep etcd">>k8s_check_result.txt
echo -e "-----------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "etcd集群状态检查,期望结果:集群状态返回健康-------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/etcdctl --endpoint 'https://127.0.0.1:2379' --ca-file /apps/conf/kubernetes/ssl/etcd/ca.pem --cert-file \`sudo cat /apps/conf/etcd/etcd.env|grep -i etcd_cert_file|awk -F '=' '{print \$2}'\`  --key-file \`sudo cat /apps/conf/etcd/etcd.env|grep -i etcd_key_file|awk -F '=' '{print \$2}'\`  cluster-health |grep 'cluster is healthy'">>k8s_check_result.txt
echo -e "-----------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "etcd是否配置开机自启动检查,期望结果:enabled------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "systemctl list-unit-files |grep etcd.service  |awk '{print \$2}'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s管理集群的pod是否正常检查,期望结果:返回为空,则正常-------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a 'sudo /apps/bin/kubectl get pod -n kube-system -o wide |grep -v  Running'>>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s管理集群的deployment是否正常检查,期望结果:当前运行实例数量(AVAILABLE)符合预期数量(ready)--------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a 'sudo /apps/bin/kubectl get deploy -n kube-system'>>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s管理集群的ds是否正常检查,期望结果:输出为0,当前运行实例数量(AVAILABLE)符合预期数量(DESIRED)--------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl get ds -n kube-system|awk '{print \$2,\$6}'|awk 'NR>1{a+=\$1;b+=\$2};END {print a-b}'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "kubelet状态检查,期望结果:active(running)---------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "systemctl status kubelet|grep -i active |awk  '{print \$2\$3}'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "metrics是否正常检查,期望结果:1 输出均为running;2 输出200-----------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl get pod -n kube-system|grep metrics">>k8s_check_result.txt
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "curl -i -k --tlsv1 https://localhost:6443/apis/autoscaling/ -o /dev/null -s -w '%{http_code}\n'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s node节点检查,期望结果:redady状态是正常状态,notready表示状态异常-----------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl get nodes">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "k8s配置文件检查,期望结果:检查采用的配置文件以及启动服务所需要的YAML配置文件统一存在此目录下------------------------">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "sudo ls -trl /apps/conf/kubernetes">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "节点coredns组件运行状态检查,期望结果:状态正常----------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl get pod -n kube-system |grep coredns">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "节点calico组件运行状态及其控制器运行状态检查,期望结果:输出均为running----------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8smaster -m shell -a "sudo /apps/bin/kubectl get po -n kube-system |grep calico">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "隧道接口与cni配置的mtu值检查,期望结果:mtu值为1420------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "/usr/sbin/ip a |grep tunl0@|awk '{print \$4,\$5}'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

#echo "kube-system域下pod的健康检查,期望结果:所有pod都添加基础探针:livenessProbe、readnessProbe--------------------------">>k8s_check_result.txt
#for i in `sudo /apps/bin/kubectl get po -n kube-system |awk '{print $1}'|sed -n '2,50p'`; do echo $i ;  sudo /apps/bin/kubectl get po $i -n kube-system -o yaml|grep -Ei 'readnessprobe|livenessprobe';done >> k8s_check_result.txt
#echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "联通性检查,期望结果:200--------------------------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "curl -i -k --tlsv1 https://localhost:6443/apis/autoscaling/ -o /dev/null -s -w '%{http_code}\n'">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

echo "kubelet开机自启动检查,期望结果:enabled------------------------------------------------------------------------------">>k8s_check_result.txt
ansible -i ./hosts k8s -m shell -a "systemctl list-unit-files |grep kubelet">>k8s_check_result.txt
echo -e "------------------------------------------------------------------------------------------------------------------\n\n">>k8s_check_result.txt

 

标签:txt,Kubernetes,echo,hosts,result,POD,k8s,check,K8S
From: https://www.cnblogs.com/gkhost/p/18178667

相关文章

  • Kubernetes脚本——K8s日志检查
    #!/bin/bashecho"docker日志采用建议的syslog收集检查,期望结果:1---------------------------------------------------------------------">log_check_result.txtansible-i./hostsall-mshell-a'sudofind/apps/logs/docker/-namedockerd.log|wc-l'&......
  • Kubernetes脚本——检查K8s基础信息
    #!/bin/sh#version#node,master,slave#arch#kernelversion#dockerversion#image#cpu,memandusage#pod,podlimit#service,nodeport,lb#deploy,statefulset,deamonset#cm,secret#namespaces#set-xecho_left(){if["$2&q......
  • k8s常见安装方式 rancher kubespray kops kubeadm对比
    Kubernetes(K8s)的常见安装方式包括Rancher、Kubespray、kops和kubeadm,它们各自具有不同的特点和适用场景。以下是这四种安装方式的对比:Rancher:Rancher是一个开源的企业级Kubernetes管理平台,它简化了Kubernetes的部署、扩展和管理。通过Rancher,用户可以轻松地在各种基础设施上部......
  • 非k8s Etcd集群单个实例无法连上其他2个后反复重启
    通过kind部署3个etcd实例构成的k8s集群。cat<<EOF|kindcreatecluster--nametest--config-kind:ClusterapiVersion:kind.x-k8s.io/v1alpha4networking:kubeProxyMode:ipvsipFamily:ipv4apiServerAddress:127.0.0.1apiServerPort:0podSubnet:"......
  • k8s——搭建集群环境
    服务器要求(三台都要操作)一台master两台node能连外网关闭防火墙关闭selinux设置主机名,域名解析关闭swap(记得关完之后重启)swapoff-a//临时关闭vim/etc/fstab//把swap分区挂载部分注释掉将桥接的ipv4流量传递到iptables上,修改linux内核参数,添加网桥过滤和地址转......
  • k8s - ERROR: image can't be pulled
       Testedtheimage:zzh@ZZHPC:/zdata/Github/zgrpc-go-professionals$kubectlrunmytest--image=zgrpc-go-professionals:serverpod/mytestcreatedzzh@ZZHPC:/zdata/Github/zgrpc-go-professionals$kubectlgetpodsNAMEREADYSTATUSRESTART......
  • k8s核心组件详解和分层架构
    k8s核心组件master中的核心组件api-server(接口服务,基于rest风格开放k8s接口的服务)kube-controller-manager(管理各个类型的控制器,针对k8s中的各种资源进行管理)cloud-controller-manager(云控制管理器,第三方云平台提供的控制器,api对接管理功能)kube-scheduler(调度器,负责将po......
  • kind部署k8s集群和kube-ovn
    #docker容器作为k8snode,容器里面通过containerd拉起Pod。cat<<EOF|kindcreatecluster--namekube-ovn--config-kind:ClusterapiVersion:kind.x-k8s.io/v1alpha4networking:kubeProxyMode:ipvsdisableDefaultCNI:trueipFamily:ipv4apiServerAddress......
  • K8S 创建Spring-boot项目并进行项目启动与访问
     ##Spring-boot 的helloworld项目packagecom.example.demo;importjava.time.LocalDateTime;importjava.time.format.DateTimeFormatter;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.RequestMappi......
  • Kubernetes源码二次开发系列(一到三),玩转高阶K8s开发
    Kubernetes源码二次开发通常涉及以下步骤:环境准备:安装和配置Go环境,确保Go版本与Kubernetes项目兼容。获取源码:从GitHub克隆Kubernetes仓库到本地。设置工作环境:通过make命令设置编译环境。修改源码:根据需求修改Kubernetes源码。编译:使用makeall编译所有组......