当前位置: 首页 > news >正文

huangSir-devops

前言

在使用 kubectl get $KIND -o yaml 查看 k8s 资源时,输出结果中包含大量由集群自动生成的元数据(如 managedFields、resourceVersion、uid 等)。这些信息在实际复用 yaml 清单时需要手动清理,增加了额外的工作量。

使用 kubectl-neat 插件,可以自动移除这些由集群生成的冗余字段,仅保留有意义的内容,使 yaml 更加简洁,方便复用。

安装

插件方式安装

kubectl krew install neat

## 作为 kubectl 插件安装,使用方式为:

kubectl neat

二进制方式安装

## 版本选择:

## https://github.com/itaysk/kubectl-neat/releases

## 当前环境为 ubuntu 2404 LTS

wget https://github.com/itaysk/kubectl-neat/releases/download/v2.0.4/kubectl-neat_linux_amd64.tar.gz

tar xf kubectl-neat_linux_amd64.tar.gz

mv ./kubectl-neat /usr/local/bin/

## 创建别名(这里看个人习惯)

vim /root/.bashrc

alias kneat='kubectl-neat'

使用

本次使用二进制方式部署,实际上参数是相同的,没区别

root@network-demo:~# kubectl-neat help

Usage:

kubectl-neat [flags]

kubectl-neat [command]

## 示例是通过 kubectl plugin 方式安装,使用二进制安装改成 kubectl-neat 就好

Examples:

kubectl get pod mypod -o yaml | kubectl neat

kubectl get pod mypod -oyaml | kubectl neat -o json

kubectl neat -f - <./my-pod.json

kubectl neat -f ./my-pod.json

kubectl neat -f ./my-pod.json --output yaml

Available Commands:

## 自动补全命令用的

completion Generate the autocompletion script for the specified shell

get

help Help about any command

version Print kubectl-neat version

Flags:

-f, --file string file path to neat, or - to read from stdin (default "-")

-h, --help help for kubectl-neat

-o, --output string output format: yaml or json (default "yaml")

命令补全

简单来说就是按两下 tab 后自动补充没拼完的参数

?? 注:其实没啥用...他只能补全命令本身的参数,并不能补全 k8s 相关信息

root@network-demo:~# kubectl-neat completion --help

Generate the autocompletion script for kubectl-neat for the specified shell.

See each sub-command's help for details on how to use the generated script.

Usage:

kubectl-neat completion [command]

Available Commands:

bash Generate the autocompletion script for bash

fish Generate the autocompletion script for fish

powershell Generate the autocompletion script for powershell

zsh Generate the autocompletion script for zsh

Flags:

-h, --help help for completion

Global Flags:

-o, --output string output format: yaml or json (default "yaml")

## 当前环境使用 bash

root@network-demo:~# hostnamectl

Static hostname: network-demo

Icon name: computer-vm

Chassis: vm

Virtualization: kvm

Operating System: Ubuntu 24.04.3 LTS

Kernel: Linux 6.8.0-88-generic

Architecture: x86-64

## 添加命令补全

echo "source <(kneat completion bash)" >> ~/.bashrc && source ~/.bashrc

## 查看效果

## 上面说没啥用的地方就在这...实际上能用的参数只有 get(kubectl-neat 自己的参数)

## 当你补全 get 后就会发现他无法识别 k8s 资源

root@network-demo:~# kubectl-neat

completion (Generate the autocompletion script for the specified shell) help (Help about any command)

get version (Print kubectl-neat version)

使用方式

## 这里我直接将 kubectl get -o yaml 与 kubectl-neat get -o yaml 输出对比

kubectl-neat get -- pods -n deepflow deepflow-server-fc484c85-p67gl -o yaml > deepflow-kneat.yaml

kubectl get pods -n deepflow deepflow-server-fc484c85-p67gl -o yaml > deepflow-kubectl.yaml

## 通过 icdiff 输出两个文件的对比结果,这里为了方便大家看,只把删除的内容放上来了

root@network-demo:~# icdiff deepflow-kubectl.yaml deepflow-kneat.yaml

creationTimestamp: "2026-01-23T02:24:57Z"

generateName: deepflow-server-fc484c85-

generation: 1

ownerReferences:

- apiVersion: apps/v1

blockOwnerDeletion: true

controller: true

kind: ReplicaSet

name: deepflow-server-fc484c85

uid: 528ab77f-67ba-4099-8771-bfe06ca9ce2f

resourceVersion: "4864722"

uid: 0d5ff97b-9c48-4abf-be8b-d2b76f7a14d2

nodeAffinity: {}

apiVersion: v1

apiVersion: v1

apiVersion: v1

apiVersion: v1

apiVersion: v1

scheme: HTTP

successThreshold: 1

timeoutSeconds: 1

protocol: TCP

protocol: TCP

protocol: TCP

protocol: TCP

scheme: HTTP

periodSeconds: 10

successThreshold: 1

timeoutSeconds: 1

resources: {}

securityContext: {}

terminationMessagePath: /dev/termination-log

terminationMessagePolicy: File

dnsConfig: {}

dnsPolicy: ClusterFirst

enableServiceLinks: true

nodeName: network-demo

restartPolicy: Always

schedulerName: default-scheduler

securityContext: {}

serviceAccount: deepflow-server

terminationGracePeriodSeconds: 30

defaultMode: 420

defaultMode: 420

apiVersion: v1

status:

## 下面是所有 status 内容...构梢殴牢

http://www.jsqmd.com/news/761301/

相关文章:

  • 如何防范模型安全威胁:对抗性攻击与防御机制终极指南
  • 让AI看懂数据流:在快马平台智能解析sscom捕获的未知设备协议
  • ComfyUI Essentials终极指南:如何用3分钟补齐ComfyUI缺失的核心功能
  • Happy Island Designer三部曲:从零到90%效率提升的岛屿设计秘籍
  • 从MoCo到SimCLR:我如何用8块GPU复现顶会对比学习实验(附完整代码与踩坑记录)
  • iOS 15-16激活锁绕过终极指南:让你的闲置iPhone重获新生
  • 基于JSON Schema的OpenClaw Web配置面板设计与实现
  • 2026北京灭火器回收指南:北京七氟丙烷回收/北京七氟丙烷检测/北京七氟丙烷灭火器回收/北京七氟丙烷灭火器检测/选择指南 - 优质品牌商家
  • 嵌入式开发依赖管理革命:Zephyr专用包管理器OpenManager详解
  • 猫抓Cat-Catch:终极浏览器资源嗅探与下载完整指南
  • UML模型到嵌入式代码的优化转换原理与实践
  • 从ELF文件‘减肥’说起:手把手教你用readelf和objdump分析strip前后的动态库变化
  • DXY-COVID-19-Crawler开发者指南:深入理解爬虫架构与数据存储
  • 效率提升:用快马智能生成java八股文知识卡片与测试代码库
  • 2026年4月咸蛋黄产品推荐,咸蛋黄咸香与奶香结合 - 品牌推荐师
  • 低查重AI教材写作:实用工具推荐,快速生成专业教材!
  • STM32F103——超声波模块
  • 在Node.js后端服务中集成Taotoken调用多模型AI功能的实践
  • 如何用Pipenv简化生物信息学项目配置:基因数据分析的完整指南
  • 终极Wireshark网络嗅探工具:如何在Docker容器中快速构建完整代码质量分析环境
  • 基于Next.js构建私有ChatGPT Web应用:从部署到安全加固全指南
  • PHP调用AI模型做表单校验太慢?3步压测优化,TPS从23提升至847(附性能对比热力图)
  • SimpleMem内存池:C++高性能内存管理库的设计与实战
  • Modern JavaScript Cheatsheet包管理终极指南:npm和yarn最佳实践
  • EasyML自定义算法开发:如何扩展平台支持新的机器学习算法
  • 7个终极NW.js应用市场推广技巧:从开发到爆发式增长的完整指南
  • 替代claude code安装实战:基于快马平台开发全功能个人博客系统
  • 终极指南:CookieCutter缓存机制如何实现项目模板重复生成的极速加速
  • 基于WebView的ChatGPT桌面客户端开发:从原理到实践
  • 为什么你的Windows电脑越用越慢?3个简单步骤让Mem Reduct帮你解决内存管理难题