首页 > 其他分享 >今天在集群中创建yaml,使用create就创建成功,apply就创建失败原因分析。

今天在集群中创建yaml,使用create就创建成功,apply就创建失败原因分析。

时间:2024-04-17 12:12:01浏览次数:18  
标签:apiextensions monitoring 创建 create yaml coreos io k8s com

1. 背景:今天在集群中搭建 Prometheus 监控,在使用 kubectl apply -f [文件名] 时,出现了报错,我对集群资源、命名空间、权限等进行一系列排查,甚至在没部署任何服务新集群部署该服务依旧显示部署失败。

第一次使用 kubectl apply -f 文件命 显示报错。

#kubectl apply -f setup/
customresourcedefinition.apiextensions.k8s.io/alertmanagerconfigs.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/probes.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/scrapeconfigs.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
namespace/monitoring created
Error from server (Invalid): error when creating "setup/0alertmanagerCustomResourceDefinition.yaml": CustomResourceDefinition.apiextensions.k8s.io "alertmanagers.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
Error from server (Invalid): error when creating "setup/0prometheusCustomResourceDefinition.yaml": CustomResourceDefinition.apiextensions.k8s.io "prometheuses.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
Error from server (Invalid): error when creating "setup/0prometheusagentCustomResourceDefinition.yaml": CustomResourceDefinition.apiextensions.k8s.io "prometheusagents.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
Error from server (Invalid): error when creating "setup/0thanosrulerCustomResourceDefinition.yaml": CustomResourceDefinition.apiextensions.k8s.io "thanosrulers.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes

使用 kubectl delete -f setup/ --grace-period=0 --force 强制删除创建yaml。

kubectl delete -f setup/ --grace-period=0 --force
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
customresourcedefinition.apiextensions.k8s.io "alertmanagerconfigs.monitoring.coreos.com" force deleted
customresourcedefinition.apiextensions.k8s.io "podmonitors.monitoring.coreos.com" force deleted
customresourcedefinition.apiextensions.k8s.io "probes.monitoring.coreos.com" force deleted
customresourcedefinition.apiextensions.k8s.io "prometheusrules.monitoring.coreos.com" force deleted
customresourcedefinition.apiextensions.k8s.io "scrapeconfigs.monitoring.coreos.com" force deleted
customresourcedefinition.apiextensions.k8s.io "servicemonitors.monitoring.coreos.com" force deleted
namespace "monitoring" force deleted
Error from server (NotFound): error when deleting "setup/0alertmanagerCustomResourceDefinition.yaml": customresourcedefinitions.apiextensions.k8s.io "alertmanagers.monitoring.coreos.com" not found
Error from server (NotFound): error when deleting "setup/0prometheusCustomResourceDefinition.yaml": customresourcedefinitions.apiextensions.k8s.io "prometheuses.monitoring.coreos.com" not found
Error from server (NotFound): error when deleting "setup/0prometheusagentCustomResourceDefinition.yaml": customresourcedefinitions.apiextensions.k8s.io "prometheusagents.monitoring.coreos.com" not found
Error from server (NotFound): error when deleting "setup/0thanosrulerCustomResourceDefinition.yaml": customresourcedefinitions.apiextensions.k8s.io "thanosrulers.monitoring.coreos.com" not found

重新使用 kubectl create -f setup/ 显示成功。

#kubectl create -f setup/
customresourcedefinition.apiextensions.k8s.io/alertmanagerconfigs.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/probes.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusagents.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/scrapeconfigs.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/thanosrulers.monitoring.coreos.com created
namespace/monitoring created
2. 经过查询各种相关资讯,在知识星球有篇文章可以解释create与apply在创建yaml有很大区别。
1. kubectl create 命令只是简单地创建资源对象,它不会去检查或者处理对象的注解数据,所以它不会因为注解数据过大而报错。
2. kubectl apply 命令则会对资源对象进行更复杂的处理。在创建或者更新资源对象时,它会将整个资源对象的配置数据(包括注解数据)保存在 kubectl.kubernetes.io/last-applied-configuration 注解中。这样在以后的 apply 操作中,kubectl 就可以通过比较这个注解中的配置数据和当前的配置数据,来决定哪些字段需要更新,哪些字段不需要更新。由于这个原因,如果你的注解数据过大,超过了 Kubernetes 对注解数据大小的限制,那么 kubectl apply 就会报错。

总结,如果你的注解数据过大,你可以选择使用 kubectl create 命令来创建资源对象,但是你需要注意,这样做之后你就不能再使用 kubectl apply 命令来更新这个资源对象了,因为 apply 命令仍然会因为注解数据过大而报错。你需要使用其他的命令,比如 kubectl edit 或者 kubectl patch 来更新资源对象。

3. create与apply更详细区别请参考知识星球"云原生运维圈 ":https://wx.zsxq.com/dweb2/index/topic_detail/588548181528454

标签:apiextensions,monitoring,创建,create,yaml,coreos,io,k8s,com
From: https://www.cnblogs.com/huangjiabobk/p/18140282

相关文章

  • 4-01. 升级到 URP 并创建灯光数据结构
    安装URP安装URP创建Settings修改ProjectSettings让素材支持通用渲染管线如果Convert的时候出现报错,继续点击Convert即可注意,如果报错说场景没有加载,需要把场景加载好之后再转换实现全局光照新建Lights然后创建GlobalLight2D白天的灯光效果晚上......
  • 解决conda创建tf环境失败
    使用conda创建tf环境的时候老师报错: conda解决AnHTTPerroroccurredwhentryingtoretrievethisURL.(已经更新清华源但也无解的解决方法)-CSDN博客采用这个博主的方法成功了前几次改错的时候我感觉也可以成功但是少写了一部就是:condaclean-i导致前面的索引并没有被......
  • V4L2 - Pipeline_Define & Async_Register & Pipeline_Create
       异步注册存在的根本原因就是:    注册时一定要表明subdev之间的层级关系,所以存在两个注册方向    一是以当前节点寻找下一级节点,如果下一级具备注册条件,则注册下一级节点,并指明层级关系    二是一失败后,寻找上一级节点,如果上一级指明层级关系方法被......
  • IDEA2023版本创建Spring项目只能勾选17和21却无法使用Java8的完美解决方案
    参考:https://www.jb51.net/program/308256k4b.htm方案一:替换创建项目的源我们只知道IDEA页面创建Spring项目,其实是访问springinitializr去创建项目。故我们可以通过阿里云国服去间接创建Spring项目。将https://start.spring.io/或者http://start.springboot.io/替换为https://......
  • flutter 尝试创建第一个页面(三)
    新建目录assets 存放图片在pubspec..yaml中添加flutter:#ThefollowinglineensuresthattheMaterialIconsfontis#includedwithyourapplication,sothatyoucanusetheiconsin#thematerialIconsclass.uses-material-design:trueasset......
  • 【chatgpt】IoCreateDevice和IoCreateSymbolicLink是两个重要的函数
    在Windows设备驱动程序开发中,IoCreateDevice和IoCreateSymbolicLink是两个重要的函数,用于创建设备对象和符号链接,它们的作用如下:IoCreateDevice:作用:创建一个设备对象,驱动程序使用设备对象来与系统和其他驱动程序进行通信。参数:需要提供设备扩展名和设备的类型、特征以及......
  • docker使用centos镜像创建的容器内使用systemctl重启sshd服务报错或者无法使用
    问题是这样的:如果镜像是ubuntu系统的,创建容器后使用systemctl启动sshd没有什么问题,但是如果镜像是centos,那就会报错failedtoconnecttobusnosuch原因:centos系统的的安全性较高,相比ubuntu一些底层无法映射到容器中,即使在创建容器时加上--security-optseccomp:unconfined --......
  • 使用VBS创建快捷方式的代码
    <p>在网吧维护过程中经常要发送桌面快捷方式,有什么批处理的方式能便捷发送桌面快捷方式呢,就拿我这边网吧steam下发为例给大家一个参考,如果要使用直接复制下面代码改下具体参数就行了。代码如下:</p>@echooff::设置程序或文件的路径(必选)setProgram=D......
  • 2-81. 创建交易窗口 UI 并实现拖拽交易打开交易窗口
    关闭窗口修改EventHandler修改InventoryUI修改NPCFunction打开窗口人物无法移动修改Enums修改EventHandler修改NPCFunction修改Player打开对话框人物还可以移动修改DialogController打开商店的时候同时打开背包调整背包和商店锚点位置修改Inven......
  • 在CSS中创建一个鼠标悬停时弹出菜单
    要在CSS中创建一个鼠标悬停时弹出菜单,你可以使用HTML和CSS来实现。以下是一个简单的例子:HTML:<divclass="dropdown"><buttonclass="dropbtn">点击我</button><divclass="dropdown-content"><ahref="#">链接1</a>......