kubernetes调试利器——kubectl debug工具

  通常情况下,业务容器所使用的镜像是非常精简的,而一旦业务容器出现问题,通过kubectl exec进入到容器时,我们会发现自己需要使用的工具都没有,也无法通过apt, apt-get, yum等包管理工具下载需要的工具。

  想要解决这个尴尬的窘境,有两种手段,其一是提前把需要使用的工具打入到镜像当中,除了问题我们可以随时进行debug。其二是利用kubectl debug工具。显然,第一种方式有很多弊端,譬如业务容器镜像过大,占用磁盘空间更多;另外每个人使用的工具可能会不同,我们不可能把所有的工具都打入到镜像当中,这是极不合理的。 而如果我们能够把需要的工具打入到一个debug镜像当中,需要的时候如果能把这个debug镜像跑起来,并且attach到我们需要排查问题的业务容器上,同时这两个容器可以共享network, pid名称空间的话,就能很好的解决这个问题。而恰好kubectl debug就有这样的功能

  kubectl debug命令的帮助文档如下

root@k8s-master1:~# kubectl debug --help
Debug cluster resources using interactive debugging containers.'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will
be used by default if no resource is specified.The action taken by 'debug' varies depending on what resource is specified. Supported actions include:*  Workload: Create a copy of an existing pod with certain attributes changed, for example changing the image tag to a
new version.*  Workload: Add an ephemeral container to an already running pod, for example to add debugging utilities without
restarting the pod.*  Node: Create a new pod that runs in the node's host namespaces and can access the node's filesystem.Examples:# Create an interactive debugging session in pod mypod and immediately attach to it.kubectl debug mypod -it --image=busybox# Create an interactive debugging session for the pod in the file pod.yaml and immediately attach to it.# (requires the EphemeralContainers feature to be enabled in the cluster)kubectl debug -f pod.yaml -it --image=busybox# Create a debug container named debugger using a custom automated debugging image.kubectl debug --image=myproj/debug-tools -c debugger mypod# Create a copy of mypod adding a debug container and attach to itkubectl debug mypod -it --image=busybox --copy-to=my-debugger# Create a copy of mypod changing the command of mycontainerkubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh# Create a copy of mypod changing all container images to busyboxkubectl debug mypod --copy-to=my-debugger --set-image=*=busybox# Create a copy of mypod adding a debug container and changing container imageskubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug# Create an interactive debugging session on a node and immediately attach to it.# The container will run in the host namespaces and the host's filesystem will be mounted at /hostkubectl debug node/mynode -it --image=busyboxOptions:--arguments-only=false:If specified, everything after -- will be passed to the new container as Args instead of Command.--attach=false:If true, wait for the container to start running, and then attach as if 'kubectl attach ...' were called.Default false, unless '-i/--stdin' is set, in which case the default is true.-c, --container='':Container name to use for debug container.--copy-to='':Create a copy of the target Pod with this name.--env=[]:Environment variables to set in the container.-f, --filename=[]:identifying the resource to debug--image='':Container image to use for debug container.--image-pull-policy='':The image pull policy for the container. If left empty, this value will not be specified by the client anddefaulted by the server.--profile='legacy':Debugging profile. Options are "legacy", "general", "baseline", "netadmin", or "restricted".-q, --quiet=false:If true, suppress informational messages.--replace=false:When used with '--copy-to', delete the original Pod.--same-node=false:When used with '--copy-to', schedule the copy of target Pod on the same node.--set-image=[]:When used with '--copy-to', a list of name=image pairs for changing container images, similar to how 'kubectlset image' works.--share-processes=true:When used with '--copy-to', enable process namespace sharing in the copy.-i, --stdin=false:Keep stdin open on the container(s) in the pod, even if nothing is attached.--target='':When using an ephemeral container, target processes in this container name.-t, --tty=false:Allocate a TTY for the debugging container.Usage:kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] [options]Use "kubectl options" for a list of global command-line options (applies to all commands).

  想要完成上述功能,主要是利用--target参数,这个参数主要用于指定debug Pod中的哪个容器;--image参数就是用于指定使用哪个镜像来debug,这个镜像包含我们需要使用的工具即可。用法如下:

root@k8s-master1:~# kubectl get pods
NAME                                READY   STATUS    RESTARTS       AGE
mysql-5578b9475d-5fc8d              1/1     Running   1 (130m ago)   156m
nginx-deployment-775b6549b5-bgdfp   1/1     Running   2 (130m ago)   3h39m
nginx-deployment-775b6549b5-ghz9t   1/1     Running   2 (130m ago)   3h39m
nginx-deployment-775b6549b5-pcw82   1/1     Running   1 (130m ago)   167m
root@k8s-master1:~#
root@k8s-master1:~# kubectl debug mysql-5578b9475d-5fc8d --image=ubuntu:20.04 -it --target=mysql
Targeting container "mysql". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
Defaulting debug container name to debugger-jlw5l.
If you don't see a command prompt, try pressing enter.
root@mysql-5578b9475d-5fc8d:/#
root@mysql-5578b9475d-5fc8d:/# ps -aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
999            1  0.0  4.8 1163028 195532 ?      Ssl  03:26   0:07 mysqld
root         128  0.0  0.0   4248  3256 pts/0    Ss   05:40   0:00 bash
root         136  0.0  0.0   5900  2780 pts/0    R+   05:41   0:00 ps -aux
root@mysql-5578b9475d-5fc8d:/#
root@mysql-5578b9475d-5fc8d:/#
root@mysql-5578b9475d-5fc8d:/# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st1  0      0 1111892   2120 1823828    0    0    42   346  696 1192  1  4 95  0  0
root@mysql-5578b9475d-5fc8d:/# pidstt

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/10917.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【NLP】语音识别 — GMM, HMM

一、说明 在语音识别的深度学习(DL)时代之前,HMM和GMM是语音识别的两项必学技术。现在,有将HMM与深度学习相结合的混合系统,并且有些系统是免费的HMM。我们现在有更多的设计选择。然而,对于许多生成模型来说…

C语言---每天小练习,从大到小输出

题目&#xff1a;从大到小输出 写代码将三个整数数按从大到小输出。 例如&#xff1a; 输入&#xff1a;2 3 1 输出&#xff1a;3 2 1 int main() {// 初始化int a 0;int b 0;int c 0;int d 0;scanf("%d %d %d", &a, &b, &c);if (a < b) {…

力扣算法数学类—剑指 Offer 16. 数值的整数次方

目录 剑指 Offer 16. 数值的整数次方 题解&#xff1a; 知识点&#xff1a; 代码&#xff1a; 结果&#xff1a; 实现 pow(x, n) &#xff0c;即计算 x 的 n 次幂函数&#xff08;即&#xff0c;xn&#xff09;。不得使用库函数&#xff0c;同时不需要考虑大数问题。 示例…

【Matplotlib 绘制直方图】

使用 Matplotlib 绘制直方图 在数据分析和数据可视化中&#xff0c;直方图是一种常见的图表类型&#xff0c;用于展示数据的分布情况。Python 的 Matplotlib 库为我们提供了方便易用的功能来绘制直方图。 绘制直方图 下面的代码展示了如何使用 Matplotlib 绘制一个直方图&am…

UE使用UnLua(二)

1.前言 最近也是比较忙&#xff0c;忘了来更新了&#xff0c;好多都是开了头断更的&#xff08;狗头&#xff09;&#xff0c;今天抽空再更一篇&#xff01;&#xff01; 这篇讲一下在UnLua中覆盖蓝图事件&#xff08;函数&#xff09;&#xff0c;及按钮、文本控件的一些使用…

Node.js 安装与版本管理(nvm 的使用)

安装 Node.js Node.js 诞生于 2009 年 5 月&#xff0c;截至今天&#xff08;2022 年 3 月 26 号&#xff09;的最新版本为 16.14.2 LTS 和 17.8.0 Current&#xff0c;可以去官网下载合适的版本。 其中&#xff0c;LTS&#xff08;Long Term Support&#xff09; 是长期维护…

3的幂,给定一个整数,写一个函数来判断它是否是 3 的幂次方。如果是,返回 true ;否则,返回 false。

题记&#xff1a; 给定一个整数&#xff0c;写一个函数来判断它是否是 3 的幂次方。如果是&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 整数 n 是 3 的幂次方需满足&#xff1a;存在整数 x 使得 n 3^x 示例 1&#xff1a; 输入&#xff1a;n 27 输出…

四元数

public static Quaternion Euler(Vector3 euler); 传入一个向量&#xff0c;使物体旋转&#xff0c;如&#xff1a; cube.transform.rotationQuaternion.Euler(new Vector3(0,30,0)); 值得注意的是&#xff1a;Unity中组件Transform的Rotation实际上是Quaternion类型的 publ…

【雕爷学编程】MicroPython动手做(02)——尝试搭建K210开发板的IDE环境

知识点&#xff1a;简单了解K210芯片 2018年9月6日,嘉楠科技推出自主设计研发的全球首款基于RISC-V的量产商用边缘智能计算芯片勘智K210。该芯片依托于完全自主研发的AI神经网络加速器KPU,具备自主IP、视听兼具与可编程能力三大特点,能够充分适配多个业务场景的需求。作为嘉楠科…

详解Mybatis之动态sql问题

编译软件&#xff1a;IntelliJ IDEA 2019.2.4 x64 操作系统&#xff1a;win10 x64 位 家庭版 Maven版本&#xff1a;apache-maven-3.6.3 Mybatis版本&#xff1a;3.5.6 文章目录 一. 在sql映射文件中如何写注释&#xff1f;二. 什么是动态sql&#xff1f;三. 动态sql常用标签有…

Android Studio 中使用 FlutterJsonBeanFactory

1、创建entity 安装FlutterJsonBeanFactory插件&#xff0c;在文件夹下右键 New -> JsonDartBeanAction 2、删除entity&#xff0c;直接右键删除entity&#xff0c;然后到generated/json/base/json_convert_content.dart文件&#xff0c;按下快捷键altj即可 参考文章 ht…

VBA操作WORD(六)另存为不含宏的文档

Sub 另存为不含宏的文档()Application.DisplayAlerts False Application.ScreenUpdating FalseDim oDoc As DocumentSet oDoc Word.ActiveDocumentDim oRng As RangeSet oRng oDoc.ContentDim sPath As String默认存储路径&#xff0c;当前用户桌面&#xff0c;注释掉的是当…

pycharm 使用远程服务器 jupyter (本地jupyter同理)

1. 远程服务器miniconda 环境中创建jupyter环境 # 1. 激活环境 conda activate envname#2. 在环境中安装jupyter pip install jupyter # 或者 conda install jupyter#3. 生成jupyter_notebook_config.py文件 jupyter notebook --generate-config#4. 设置密码 jupyter noteboo…

Spark编程-SparkSQL

SparkSql能做些啥 Spark SQL的核心概念是DataFrame&#xff0c;它是一个分布式的数据集合&#xff0c;类似于关系数据库中的表。支持使用SQL语言直接对DataFrame进行查询,提供了丰富的内置函数和表达式&#xff0c;可以用于数据的转换、过滤和聚合等操作,支持多种数据源&#…

功能测试也可以发现数据库相关的性能问题

很多同学认为功能测试和性能测试是严格分开的&#xff0c;功能测试人员无法发现性能问题。其实不是这样的&#xff0c;功能测试人员在验证功能时也可以发现性能问题&#xff1b;一些功能反而在功能测试环境不好验证&#xff0c;需要在性能环境上测试。 今天咱们就说一下测试涉及…

Leetcode 滑动窗口题目总结

(Leetcode 滑动窗口题目总结) 1&#xff1a; 3.无重复字符的最长子串 https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/子串 和 子序列的区别&#xff1a;字串是连续的&#xff0c;子序列是非连续的。快慢指针 i 和 j&#xff0c;…

前端面试题 —— React (二)

目录 一、React 组件中怎么做事件代理&#xff1f;它的原理是什么&#xff1f; 二、React.Component 和 React.PureComponent 的区别 三、Component, Element, Instance 之间有什么区别和联系&#xff1f; 四、React声明组件有哪几种方法&#xff0c;有什么不同&#xff1f…

QT项目代码去UI界面常用开发步骤

QT项目代码去UI界面常用开发步骤 因项目开发需求&#xff0c;领导要求整个QT项目中不要用UI方式来实现界面&#xff0c;这样能保障程序运行稳定性以及代码的逻辑和可读性,先记录具体操作步骤如下&#xff1a; 1、首先我们通过拖控件的方式来实现界面的设计效果&#xff0c…

【Docker】安全及日志管理

目录 一、Docker 安全及日志管理1.1 Docker 容器与虚拟机的区别1. 隔离与共享2. 性能与损耗 1.2Docker 存在的安全问题1.Docker 自身漏洞2.Docker 源码问题 1.3 Docker 架构缺陷与安全机制1. 容器之间的局域网攻击2. DDoS 攻击耗尽资源3. 有漏洞的系统调用4. 共享root用户权限 …

DEVICENET转ETHERNET/IP网关devicenet协议

捷米JM-EIP-DNT&#xff0c;你听说过吗&#xff1f;这是一款自主研发的ETHERNET/IP从站功能的通讯网关&#xff0c;它能够连接DEVICENET总线和ETHERNET/IP网络&#xff0c;从而解决生产管理系统中协议不同造成的数据交换互通问题。 这款产品在工业自动化领域可谓是一大利器&…