资源对象

  1. workload:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob
  2. 服务发现及均衡:Service, Ingress
  3. 配置与存储:Volume,CSI,ConfigMap,Secret,DownwardAPI
  4. 集群级资源:Namespace,Node,Role,ClusterRole,RoleBinding,ClusterRoleBinding
  5. 元数据型资源:HPA,PodTemplate,LimitRange

创建资源的方法

apiserver:仅接受JSON格式的资源定义;

使用yaml格式提供配置清单,apiserver可自动将其转为JSON格式,而后再进行执行;

大部分资源的配置清单:

  1. apiVersion: group/version

$ kubectl api-versions

  1. kind 资源类别(pod,service,deployment等)
  2. metadata: 元数据

name 同一个namespace下name必须是唯一的

namespace 命名空间

labels 标签,每一种资源都可以有标签

annotations 资源注解

3.spec: 用户期望的目标状态,disired state

4.status: 当前状态,应无限向spec状态接近,current state,本字段由kubernetes集群维护;用户不能自定义;

清单帮助命令

可通过 kubectl explain 来查看清单中所需要的帮助

如:

[root@master ~]# kubectl explain pod
KIND: Pod
VERSION: v1 DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts. 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/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/api-conventions.md#types-kinds metadata <Object>( 元数据 )
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata spec <Object> (用户定义的所希望的目标状态==最重要的字段)
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status status <Object>(k8s集群当前所处状态,应无限向目标状态靠拢,只读的,不受人为控制)
Most recently observed status of the pod. This data may not be up to date.
Populated by the system. Read-only. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

这里是查看pod第一层,如想看 metadata 中的信息,直接使用 pod.metadata 继续查看

如:

[root@master ~]# kubectl explain pod.metadata
KIND: Pod
VERSION: v1 RESOURCE: metadata <Object> DESCRIPTION:
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata ObjectMeta is metadata that all persisted resources must have, which
includes all objects users must create. FIELDS:
annotations <map[string]string>
Annotations is an unstructured key value map stored with a resource that
may be set by external tools to store and retrieve arbitrary metadata. They
are not queryable and should be preserved when modifying objects. More
info: http://kubernetes.io/docs/user-guide/annotations clusterName <string>
The name of the cluster which the object belongs to. This is used to
distinguish resources with same name and namespace in different clusters.
This field is not set anywhere right now and apiserver is going to ignore
it if set in create or update request. creationTimestamp <string>
CreationTimestamp is a timestamp representing the server time when this
object was created. It is not guaranteed to be set in happens-before order
across separate operations. Clients may not set this value. It is
represented in RFC3339 form and is in UTC. Populated by the system.
Read-only. Null for lists. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
.......
.......
# 太多就不复制了

以此类推都是如此;

  • kubectl explain pod.spec
  • kubectl explain pod.status

分类:

在每个后们都会有 一个 相对应的字段,

类型 解释 举例
string 字符串 字符串
[]string 字符串列表 需要填写字符串类型的数组
map[string]string 视图字符串 需要有众多k: v类型的数据
Object 对象 说明有需要嵌套的下一级字段
[]Object 对象列表 说明可以有多个需要嵌套的下一级字段
- required - 必填项 当出现这个的时候,此项参数必须要填写

创建测试清单

创建一个pod-demo.yaml的文件,内容如下:

  • 注意事项

    • 注意大小写
    • 列表需要加“ - ”,一般同级使用
[root@master manifests]# cat pod-demo.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox:latest
command:
- "/bin/sh"
- "-c"
- "sleep 3600"

使用kubectl create 命令来对文件进行加载操作

[root@master manifests]# kubectl create -f pod-demo.yaml
pod/pod-demo created
[root@master manifests]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-demo 2/2 Running 0 20s 10.244.3.8 node01.kubernetes <none> <none>

可以看到已经正常启动了。

如要删除此pod,则使用kubectl delete 来对pod-demo.yaml进行操作也可以;

[root@master manifests]# kubectl delete -f pod-demo.yaml
pod "pod-demo" deleted

资源的三种创建方式

对于kubernetes中的资源,有三种创建方式

1、第一种是上一篇文章中的,使用命令创建

2、第二种是本文章中演示的,配置清单式用法。又称命令式资源清单

3、第三种是声明式资源清单,第三种是类似于第二种的清单方式。

使用声明式是可以确保资源尽可能的向我们声明的状态改变,而且我们随时能改变我们的声明,并随时应用。

四,k8s集群资源清单定义入门的更多相关文章

  1. k8s资源清单定义入门

    1.资源分类 a.workload型资源:service.pod.deployment.ReplicaSet.StatefulSet.Job.Cronjob; b.服务发现及服务均衡资源型资源:Ser ...

  2. Kubenetes 资源清单定义入门

    Kubernetes 常用资源 资源  对象 工作负载型资源对象(workload): Pod  Replicaset  ReplicationController  Deployments Stat ...

  3. 强大多云混合多K8S集群管理平台Rancher入门实战

    @ 目录 概述 定义 为何使用 其他产品 安装 简述 规划 基础环境 Docker安装 Rancher安装 创建用户 创建集群 添加Node节点 配置kubectl 创建项目和名称空间 发布应用 偏好 ...

  4. Prometheus 监控K8S集群资源监控

    Prometheus 监控K8S集群中Pod 目前cAdvisor集成到了kubelet组件内,可以在kubernetes集群中每个启动了kubelet的节点使用cAdvisor提供的metrics接 ...

  5. k8s学习笔记之四:资源清单定义入门

    第一章.k8s中的资源 1.什么叫资源? k8s中所有的内容都抽象为资源, 资源实例化之后,叫做对象 2.在k8s中有哪些资源? 工作负载型资源(workload): Pod ReplicaSet D ...

  6. Kubernetes 学习5 kubernetes资源清单定义入门

    一.kubernetes是有一个restful风格的 API,把各种操作对象都一律当做资源来管理.并且可通过标准的HTTP请求的方法 GET,PUT,DELETE,POST,等方法来完成操作,不过是通 ...

  7. 04-kubernetes 资源清单定义入门

    目录 资源对象 创建资源的方法 清单帮助命令 创建测试清单 资源的三种创建方式 资源对象 workload:Pod, ReplicaSet, Deployment, StatefulSet, Daem ...

  8. kubernetes 资源清单定义入门

    k8s中的资源 什么叫资源? k8s中所有的内容都抽象为资源, 资源实例化之后,叫做对象 在k8s中有哪些资源? 工作负载型资源(workload): Pod ReplicaSet Deploymen ...

  9. 5、kubernetes资源清单定义入门

    使用配置清单创建资源 定义pod时使用yaml格式 master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE client / Error 1 ...

随机推荐

  1. [Err] ORA-00942: table or view does not exist

    [Err] ORA-00942: table or view does not exist 当前用户加表明 例如:SCOTT."replyInfo"

  2. 阶段3 3.SpringMVC·_02.参数绑定及自定义类型转换_4 请求参数绑定集合类型

    jabaBean里面有集合的情况 把account里面的user对象先注释掉.get和set都注释掉.然后toString方法需要重写 List和Map这两种对象.生成get和set方法 toStri ...

  3. shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步

    shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...

  4. java中instanceof的基本使用

    java中的instanceof运算符是用于判断对象是否是指定类或这个指定类的子类的一个实例,返回值是布尔类型. 语法: boolean result = object instanceof clas ...

  5. Android开发实例 Unity显示Toast

    Android中的Toast是一种简易的消息提示框. 当视图显示给用户,在应用程序中显示为浮动.和Dialog不一样的是,它永远不会获得焦点,无法被点击.用户将可能是在中间键入别的东西.Toast类的 ...

  6. Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges)

    Leetcode之广度优先搜索(BFS)专题-994. 腐烂的橘子(Rotting Oranges) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ar ...

  7. python3.6调用c语言动态编译文件 c语言编译可执行文件和动态编译等

    1.c的代码 dfunc.c #include<stdio.h> int dgfunc(int n) { ){ ; }else{ )+dgfunc(n-); } } 2.动态编译 cmd ...

  8. 【VS开发】CTimeSpan类

    CTimeSpan类.        日期和时间类简介        CTime类的对象表示的时间是基于格林威治标准时间(GMT)的.CTimeSpan类的对象表示的是时间间隔.        CTi ...

  9. NoSQL--couchdb

    Couchdb CouchDB是Apache组织发布的一款开源的.面向文档类型的NoSQL数据库.由Erlang编写,使用json格式保存数据.CouchDB以RESTful的格式提供服务可以很方便的 ...

  10. 论文阅读 | Towards a Robust Deep Neural Network in Text Domain A Survey

    摘要 这篇文章主要总结文本中的对抗样本,包括器中的攻击方法和防御方法,比较它们的优缺点. 最后给出这个领域的挑战和发展方向. 1 介绍 对抗样本有两个核心:一是扰动足够小:二是可以成功欺骗网络. 所有 ...