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相关文章:
kubernetes调试利器——kubectl debug工具
通常情况下,业务容器所使用的镜像是非常精简的,而一旦业务容器出现问题,通过kubectl exec进入到容器时,我们会发现自己需要使用的工具都没有,也无法通过apt, apt-get, yum等包管理工具下载需要的工具。 想要解决这个尴…...
浅谈es5如何保证并发请求的返回顺序
最近在公司实习写的是es5,在和回调地狱经过一番拉扯之后写下这篇文章,也算是体验了一把没有promise的时代 假设我们的div有一个日历列表,但是由于大小关系只能每次显示2天的信息,项目限制只能使用es5,不能使用es6的pro…...
深入浅出Pytorch函数——torch.squeeze
分类目录:《深入浅出Pytorch函数》总目录 相关文章: 深入浅出Pytorch函数——torch.squeeze 深入浅出Pytorch函数——torch.unsqueeze 将输入张量形状为1的维度去除并返回。比如输入向量的形状为 A 1 B 1 C 1 D A\times1\times B\times1\times C…...
【LeetCode】121.买卖股票的最佳时机
题目 给定一个数组 prices ,它的第 i 个元素 prices[i] 表示一支给定股票第 i 天的价格。 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。 返回你可以从这笔交易中获取的最大…...
【力扣】74. 搜索二维矩阵 <二分法>
【力扣】74. 搜索二维矩阵 给你一个满足下述两条属性的 m x n 整数矩阵: 每行中的整数从左到右按非递减顺序排列。每行的第一个整数大于前一行的最后一个整数。 给你一个整数 target ,如果 target 在矩阵中,返回 true ;否则&am…...
Spring Task+Cron表达式
不需要导入坐标spring-context(包含在了spring-boot-starter) 在启动类添加EnableScheduleing开启任务调度 单独建个定时任务包task,创建定时任务类MyTask 在定时任务类添加Component 在类的方法上添加Scheduled(cron “cron表达…...
你们公司的【前端项目】是如何做测试的?字节10年测试经验的我这样做的...
前端项目也叫web端项目(通俗讲就是网页上的功能)是我们能够在屏幕上看到并产生交互的体验。 前端项目如何做测试? 要讲清楚这个问题,先需要你对测试流程现有一个全局的了解,先上一张测试流程图: 测试流程…...
华为战略方法论:BLM模型之关键任务与依赖关系
内容简介 在 BLM 模型中,执行部分包括四个模块,分别是: 关键任务与依赖关系;组织与绩效;人才;氛围与文化。 详细内容,大家可以参看下面这张图。 这四个模块其实是可以进一步划分成两个关键点…...
django的ORM模板的fake更新
django存量数据表的migraions记录丢失,若要更新表结构,则需用到fake,否则报错: 解决步骤如下: 1)同步存量表结构,生成伪表 --fake sudo python3 manage.py makemigrations appname sudo pyt…...
239.滑动窗口最大值
leetcode原题链接 题目描述: 给你一个整数数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。 返回 滑动窗口中的最大值 。 示例1: 输入:nums [1,…...
Redis基础原理
1 概念 1.1 关系型数据库与非关系型数据库对比 关系型数据库Mysql、Oralce特点数据之间有关联;数据存储在硬盘上效率操作关系型数据库非常耗时 非关系型数据库redis、hbase存储key:value特点数据之间没有关联关系;数据存储在内存中缓存思想从缓存中获…...
.NET 5 Web API 中JWT详细教程:保护你的Web应用
第一部分: 理解JWT JSON Web Token(JWT)是一种在不同系统之间传递信息的安全方式。它由三部分组成:头部(Header)、载荷(Payload)和签名(Signature)。头部包…...
MyBatis-Plus自动填充
文章目录 一、前言二、MyBatis-Plus自动填充功能实现2.1、实体类上增加注解2.2、自定义填充类编写 一、前言 我们在建表的时候,所有的表都会有create_id(创建人id)、create_time(创建时间)、update_id(更新…...
Dubbo服务提供者失效踢出原理解析
Dubbo服务提供者失效踢出原理解析 在分布式系统中,服务提供者的失效是一个常见而且重要的问题。Dubbo作为一款优秀的分布式服务框架,提供了失效踢出机制来及时剔除不可用的服务提供者,确保系统的稳定性和可用性。本文将深入探讨Dubbo服务提供…...
el-select下拉框处理分页数据,触底加载更多
1、声明自定义指令: directives: {loadmore: {inserted(el, binding) {const SELECTWRAP_DOM el.querySelector(.el-select-dropdown .el-select-dropdown__wrap);SELECTWRAP_DOM.addEventListener(scroll, function() {const condition this.scrollHeight - thi…...
如何设计自动化测试脚本?一文5个步骤带你从0到1设计
企业中如何设计自动化测试脚本呢?今天我们就来为大家分享一些干货。 一、线性设计 线性脚本设计方式是以脚本的方式体现测试用例,是一种非结构化的编码方式,多数采用录制回放的方式,测试工程师通过录制回访的访问对被测系统进行自…...
PostgreSQL实战-数据库迁移部署
PostgreSQL实战-数据库迁移部署 介绍 根据项目需求,我们需要将现有的PostgreSQL数据库重新部署到新的服务器上。由于项目本身就是基于PostgreSQL数据库构建的,因此数据库迁移将变得十分便捷。接下来,我将简要介绍我们的迁移步骤。 迁移步骤…...
PHP数据库
PHP MySQL 连接数据库 MySQL 简介MySQL Create 免费的 MySQL 数据库通常是通过 PHP 来使用的。 连接到一个 MySQL 数据库 在您能够访问并处理数据库中的数据之前,您必须创建到达数据库的连接。 在 PHP 中,这个任务通过 mysql_connect() 函数完成。 …...
Mybatis的基本操作--增删改查
目录 查看数据 无参数 一个参数 多个参数 添加数据 修改数据 删除数据 注释的方式进行查找数据 查看数据 分三种情况:无参,有一个参数,有多个参数的情况。 (这里的详细操作步骤是博主的上一篇博客写的:初识My…...
Qt简单实现密码器控件
本文实例为大家分享了Qt自定义一个密码器控件的简单实现代码,供大家参考,具体内容如下 实现构思: 密码器的功能可以看成是计算器和登陆界面的组合,所以在实现功能的过程中借鉴了大神的计算器的实现代码和登陆界面实现的代码。 …...
Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility
Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility 1. 实验室环境1.1 实验室环境1.2 小测试 2. The Endor System2.1 部署应用2.2 检查现有策略 3. Cilium 策略实体3.1 创建 allow-all 网络策略3.2 在 Hubble CLI 中验证网络策略源3.3 …...
【磁盘】每天掌握一个Linux命令 - iostat
目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat(I/O Statistics)是Linux系统下用于监视系统输入输出设备和CPU使…...
生成 Git SSH 证书
🔑 1. 生成 SSH 密钥对 在终端(Windows 使用 Git Bash,Mac/Linux 使用 Terminal)执行命令: ssh-keygen -t rsa -b 4096 -C "your_emailexample.com" 参数说明: -t rsa&#x…...
跨链模式:多链互操作架构与性能扩展方案
跨链模式:多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈:模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展(H2Cross架构): 适配层…...
【C语言练习】080. 使用C语言实现简单的数据库操作
080. 使用C语言实现简单的数据库操作 080. 使用C语言实现简单的数据库操作使用原生APIODBC接口第三方库ORM框架文件模拟1. 安装SQLite2. 示例代码:使用SQLite创建数据库、表和插入数据3. 编译和运行4. 示例运行输出:5. 注意事项6. 总结080. 使用C语言实现简单的数据库操作 在…...
Swagger和OpenApi的前世今生
Swagger与OpenAPI的关系演进是API标准化进程中的重要篇章,二者共同塑造了现代RESTful API的开发范式。 本期就扒一扒其技术演进的关键节点与核心逻辑: 🔄 一、起源与初创期:Swagger的诞生(2010-2014) 核心…...
AI+无人机如何守护濒危物种?YOLOv8实现95%精准识别
【导读】 野生动物监测在理解和保护生态系统中发挥着至关重要的作用。然而,传统的野生动物观察方法往往耗时耗力、成本高昂且范围有限。无人机的出现为野生动物监测提供了有前景的替代方案,能够实现大范围覆盖并远程采集数据。尽管具备这些优势…...
【Android】Android 开发 ADB 常用指令
查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...
实战三:开发网页端界面完成黑白视频转为彩色视频
一、需求描述 设计一个简单的视频上色应用,用户可以通过网页界面上传黑白视频,系统会自动将其转换为彩色视频。整个过程对用户来说非常简单直观,不需要了解技术细节。 效果图 二、实现思路 总体思路: 用户通过Gradio界面上…...
五子棋测试用例
一.项目背景 1.1 项目简介 传统棋类文化的推广 五子棋是一种古老的棋类游戏,有着深厚的文化底蕴。通过将五子棋制作成网页游戏,可以让更多的人了解和接触到这一传统棋类文化。无论是国内还是国外的玩家,都可以通过网页五子棋感受到东方棋类…...
