【K8S】集群中部署nginx应用 运行手写yaml文件报错排查过程

news2024/10/2 12:21:07

文章目录

    • ❌报错信息
    • 🔎排查过程
    • ✅问题解决

❌报错信息

提取报错信息【 unknown field “spec.selector.replicas”】【 unknown field “spec.selector.template”

[root@master ~]# kubectl apply -f nginx-deployment.yaml
Error from server (BadRequest): error when creating "nginx-deployment.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.selector.replicas", unknown field "spec.selector.template"

image-20231013140232174

🔎排查过程

根据报错信息,排查一下nginx-deployment YAML文件。

  • 原nginx-deployment.yaml文件(编写有误)
# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: nginx-deploy
  namespace: default
  labels:
    chapter: first-app
spec: 
  selector: 
    matchLabels: 
      app: nginx
    replicas: 2
    template:
      metadata: 
        labels: 
          app: nginx
      spec: 
        containers: 
          - name: nginx
            image: nginx:1.7.9
            ports: 
              - containerPort: 80

首先,使用YAML、YML在线编辑(校验)器校对一下此YAML文件格式是否正确。未发现异常。

image-20231013142058090

其次,根据报错信息,定位到【unknown field “spec.selector.replicas”】【unknown field “spec.selector.template”】这两处的字段中的replicastemplate这两个关键字。提示的大概意思是在spec.selector字段值里未找到这两个属性,属于未知属性。

通过运行kubectl explain deployment 查看其中字段属性位置包含关系情况。

[root@master ~]# kubectl explain deployment
KIND:     Deployment
VERSION:  apps/v1

DESCRIPTION:
     Deployment enables declarative updates for Pods and ReplicaSets.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata     <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec <Object>
     Specification of the desired behavior of the Deployment.

   status       <Object>
     Most recently observed status of the Deployment.

查看replicas层级关系kubectl explain deployment.spec

replicas这一字段属于spec下一级。不应该在selector这一字段的下级。

同理,template这一字段也属于spec下一级,不应该在selector这一字段的下级。

[root@master ~]# kubectl explain deployment.spec
KIND:     Deployment
VERSION:  apps/v1

RESOURCE: spec <Object>

DESCRIPTION:
     Specification of the desired behavior of the Deployment.

     DeploymentSpec is the specification of the desired behavior of the
     Deployment.

FIELDS:
   minReadySeconds      <integer>
     Minimum number of seconds for which a newly created pod should be ready
     without any of its container crashing, for it to be considered available.
     Defaults to 0 (pod will be considered available as soon as it is ready)

   paused       <boolean>
     Indicates that the deployment is paused.

   progressDeadlineSeconds      <integer>
     The maximum time in seconds for a deployment to make progress before it is
     considered to be failed. The deployment controller will continue to process
     failed deployments and a condition with a ProgressDeadlineExceeded reason
     will be surfaced in the deployment status. Note that progress will not be
     estimated during the time a deployment is paused. Defaults to 600s.

   replicas     <integer>
     Number of desired pods. This is a pointer to distinguish between explicit
     zero and not specified. Defaults to 1.

   revisionHistoryLimit <integer>
     The number of old ReplicaSets to retain to allow rollback. This is a
     pointer to distinguish between explicit zero and not specified. Defaults to
     10.

   selector     <Object> -required-
     Label selector for pods. Existing ReplicaSets whose pods are selected by
     this will be the ones affected by this deployment. It must match the pod
     template's labels.

   strategy     <Object>
     The deployment strategy to use to replace existing pods with new ones.

   template     <Object> -required-
     Template describes the pods that will be created.

🕹️修改完成后的nginx-deployment.yaml,如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  namespace: default
  labels:
    chapter: first-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.7.9
          ports:
            - containerPort: 80

✅问题解决

重新运行该YAML文件,运行成功🎇。

[root@master ~]# kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deploy created
[root@master ~]# kubectl get deployment
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deploy   0/2     2            0           26s
[root@master ~]# kubectl get pods
NAME                            READY   STATUS    RESTARTS   AGE
nginx-deploy-7759cfdc55-q4622   1/1     Running   0          33s
nginx-deploy-7759cfdc55-skcgp   1/1     Running   0          33s
🎇🎇🎇完结🎉🎉🎉

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

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

相关文章

CCF CSP认证 历年题目自练Day30

题目一 试题编号&#xff1a; 202203-1 试题名称&#xff1a; 未初始化警告 时间限制&#xff1a; 1.0s 内存限制&#xff1a; 512.0MB 问题描述&#xff1a; 题目背景 一个未经初始化的变量&#xff0c;里面存储的值可能是任意的。因此直接使用未初始化的变量&#xff0c;比…

通过API接口进行商品价格监控,可以按照以下步骤进行操作

要实现通过API接口进行商品价格监控&#xff0c;可以按照以下步骤进行操作&#xff1a; 申请平台账号并选择API接口&#xff1a;根据需要的功能&#xff0c;选择相应的API接口&#xff0c;例如商品API接口、店铺API接口、订单API接口等&#xff0c;这一步骤通常需要我们在相应…

MyBatis(中)

1、动态sql&#xff1a; 1、if标签&#xff1a; mapper接口: //if 标签 多条件查询List<Car> selectByMultiConditional(Param("brand") String brand,Param("guidePrice") Double guidePrice,Param("carType") String carType); map…

ATF(TF-A)之UBSAN动态代码分析

安全之安全(security)博客目录导读 目录 一、UBSAN简介 二、TF-A中UBSAN配置选项 一、UBSAN简介 未定义行为消毒器(Undefined Behavior Sanitizer&#xff0c;UBSAN)是Linux内核的未定义行为动态检测器。 详细信息可参考&#xff1a;https://github.com/google/kernel-sanit…

3D 生成重建007-Fantasia3D和Magic3d两阶段玩转文生3D

3D生成重建3D 生成重建007-Fantasia3D和magic3d 文章目录 0 论文工作1 论文方法1.1 magic3d1.2 Fantasia3D 2 效果2.1 magic3d2.2 fantasia3d 0 论文工作 两篇论文都是两阶段法进行文生3d&#xff0c;其中fantasia3D主要对形状和外表进行解耦&#xff0c;然后先对geometry进行…

第五章 图

第五章 图 图的基本概念图的应用背景图的定义和术语 图的存储结构邻接矩阵邻接表 图的遍历连通图的深度优先搜索连通图的广度优先搜索 图的应用最小生成树拓扑排序 小试牛刀 图的基本概念 图结构中&#xff0c;任意两个结点之间都可能相关&#xff1b;而在树中&#xff0c;结点…

接口自动化测试,完整入门篇

1. 什么是接口测试 顾名思义&#xff0c;接口测试是对系统或组件之间的接口进行测试&#xff0c;主要是校验数据的交换&#xff0c;传递和控制管理过程&#xff0c;以及相互逻辑依赖关系。其中接口协议分为HTTP,WebService,Dubbo,Thrift,Socket等类型&#xff0c;测试类型又主…

Web安全基础:常见的Web安全威胁及防御方法 |青训营

Web安全基础&#xff1a;常见的Web安全威胁及防御方法 在现代Web开发中&#xff0c;安全性至关重要。Web应用面临各种潜在的威胁&#xff0c;包括跨站脚本&#xff08;XSS&#xff09;、跨站请求伪造&#xff08;CSRF&#xff09;等。了解这些威胁以及如何防御它们&#xff0c…

c语言练习87:合并两个有序数组

合并两个有序数组 合并两个有序数组https://leetcode.cn/problems/merge-sorted-array/ 给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2&#xff0c;另有两个整数 m 和 n &#xff0c;分别表示 nums1 和 nums2 中的元素数目。 请你 合并 nums2 到 nums1 中&#xff…

Excel 自动提取某一列不重复值

IFERROR(INDEX($A$1:$A$14,MATCH(0,COUNTIF($C$1:C1,$A$1:$A$14),0)),"")注意&#xff1a;C1要空置&#xff0c;从C2输入公式 参考&#xff1a; https://blog.csdn.net/STR_Liang/article/details/105182654 https://zhuanlan.zhihu.com/p/55219017?utm_id0

超越平凡:Topaz Photo AI for Mac带您领略人工智能降噪的魅力

在这个充满噪点和高频信息的时代&#xff0c;照片和视频的降噪成为了一个重要而迫切的需求。Mac用户现在有了一个强大的新工具——Topaz Photo AI for Mac&#xff0c;这是一款利用人工智能技术进行降噪和优化的软件。通过这款软件&#xff0c;您可以轻松地改善图像质量&#x…

呈现高效的软件测试技术 助力软件研发提升10倍质量

像大多数软件工程一样&#xff0c;软件测试是一门艺术。在过去十年中&#xff0c;自动化测试是测试软件的最佳方式。计算机可在瞬间运行数百个测试&#xff0c;而这样的测试集使公司能自信地每天发布数十个版本的软件。有大量资源(书籍、教程和在线课程)可用于解释如何进行自动…

金蝶EAS代码执行漏洞

【漏洞概述】 金蝶 EAS 及 EAS Cloud 是金蝶软件公司推出的一套企业级应用软件套件&#xff0c;旨在帮助企业实现全面的管理和业务流程优化。 【漏洞介绍】 金蝶 EAS 及 EAS Cloud 存在远程代码执行漏洞 【影响版本】 金蝶 EAS 8.0&#xff0c;8.1&#xff0c;8.2&#xf…

【Java学习之道】Java常用集合框架

引言 在Java中&#xff0c;集合框架是一个非常重要的概念。它提供了一种方式&#xff0c;让你可以方便地存储和操作数据。Java中的集合框架包括各种集合类和接口&#xff0c;这些类和接口提供了不同的功能和特性。通过学习和掌握Java的集合框架&#xff0c;你可以更好地管理和…

【python】anaconda中创建虚拟环境

创建虚拟环境 查看当前所有环境 首先打开Anaconda Prompt 初始进入的是base环境&#xff0c;如下。但是我们需要创建一个新的虚拟环境。 查看当前所有虚拟环境 conda env list 创建虚拟环境 conda create -n 虚拟环境名称 python3.10.1 这里使用conda create -n test python…

opencv dnn模块 示例(18) 目标检测 object_detection 之 pp-yolo、pp-yolov2和pp-yolo tiny

文章目录 1、PP-YOLO1.1、网络架构1.1.1、BackBone骨干网络1.1.2、DetectionNeck1.1.3、DetectionHead 1.2、Tricks的选择1.2.1、更大的batchsize1.2.2、滑动平均1.2.3、DropBlock1.2.4、IOU Loss1.2.5、IOU Aware1.2.6、GRID Sensitive1.2.7、Matrix NMS1.2.8、CoordConv1.2.9…

出差学知识No3:ubuntu查询文件大小|文件包大小|磁盘占用情况等

1、查询单个文件占用内存大小2、显示一个目录下所有文件和文件包的大小3、显示ubuntu所有磁盘的占用情况4、查看ubuntu单个包的占用情况 1、查询单个文件占用内存大小 使用指令&#xff1a;ls -lh 文件 2、显示一个目录下所有文件和文件包的大小 指令&#xff1a;du -sh* 3…

FastAdmin表格添加统计信息

如上图&#xff0c;在列表顶部添加订单统计信息&#xff0c;统计符合当前筛选条件的记录。 列表页html中&#xff1a; <div class"panel-body"><div id"myTabContent" class"tab-content"><div class"tab-pane fade active…

vue绑定style和class 对象写法

适用于&#xff1a;要绑定多个样式&#xff0c;个数确定&#xff0c;名字也确定&#xff0c;但不确定用不用。 绑定 class 样式【对象写法】&#xff1a; .box{width: 100px;height: 100px; } .aqua{background-color: aqua; } .border{border: 20px solid red; } .radius{bor…

vue单页面应用使用 history模式路由时刷新页面404的一种可能性

原先使用的是 hash模式路由&#xff0c;因为要结合qiankun进行微前端改造&#xff0c;改成了 history模式&#xff0c;结果页面刷新之后没有正确渲染组件。按照一般思路检查 nginx配置 try_files $uri $uri/ /index.html;也配置上了&#xff0c;还是有问题。 页面异常显示 问题…