04-kubernetes 资源清单定义入门
资源对象
- workload:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob
- 服务发现及均衡:Service, Ingress
- 配置与存储:Volume,CSI,ConfigMap,Secret,DownwardAPI
- 集群级资源:Namespace,Node,Role,ClusterRole,RoleBinding,ClusterRoleBinding
- 元数据型资源:HPA,PodTemplate,LimitRange
创建资源的方法
apiserver:尽接受JSON格式的资源定义;
使用yaml格式提供配置清单,apiserver可自动将其转为JSON格式,而后再进行执行;
大部分资源的配置清单:
- apiVersion: group/version
$ kubectl api-versions
- kind 资源类别
- metadata: 元数据
name
名称必须是唯一的
namespace
命名空间
labels
标签
annotations 注解
- spec: 用户期望的状态,disired state
- status: 当前状态,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>
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
.......
.......
# 太多就不复制了
以此类推都是如此;
分类:
在每个后们都会有 一个 相对应的字段,
类型 | 解释 | 举例 |
---|---|---|
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、第三种是类似于第二种的清单方式,但不同的是,第二种是命令式资源清单,第三种是声明式资源清单。
使用声明式是可以确保资源尽可能的向我们声明的状态改变,而且我们随时能改变我们的声明,并随时应用。
04-kubernetes 资源清单定义入门的更多相关文章
- kubernetes系列06—kubernetes资源清单定义入门
本文收录在容器技术学习系列文章总目录 1.认识kubernetes资源 1.1 常用资源/对象 workload工作负载型资源:pod,ReplicaSet,Deployment,StatefulSe ...
- Kubernetes 学习5 kubernetes资源清单定义入门
一.kubernetes是有一个restful风格的 API,把各种操作对象都一律当做资源来管理.并且可通过标准的HTTP请求的方法 GET,PUT,DELETE,POST,等方法来完成操作,不过是通 ...
- kubernetes 资源清单定义入门
k8s中的资源 什么叫资源? k8s中所有的内容都抽象为资源, 资源实例化之后,叫做对象 在k8s中有哪些资源? 工作负载型资源(workload): Pod ReplicaSet Deploymen ...
- 5、kubernetes资源清单定义入门
使用配置清单创建资源 定义pod时使用yaml格式 master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE client / Error 1 ...
- 04 . kubernetes资源清单YAML入门
YAML 通过k8s操作yaml配置文件在node上创建资源,yaml配置文件就像船垛,用来操控docker这艘大船 yam是专门用来写配置文件的语言,非常简洁和强大.而实际上使用yaml配置文件创建 ...
- 4、kubernetes资源清单快速入门190625
一.资源清单概念 资源/对象的类型 工作负载型资源:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob, ... 服务发 ...
- Kubenetes 资源清单定义入门
Kubernetes 常用资源 资源 对象 工作负载型资源对象(workload): Pod Replicaset ReplicationController Deployments Stat ...
- k8s学习笔记之四:资源清单定义入门
第一章.k8s中的资源 1.什么叫资源? k8s中所有的内容都抽象为资源, 资源实例化之后,叫做对象 2.在k8s中有哪些资源? 工作负载型资源(workload): Pod ReplicaSet D ...
- (四)Kubernetes 资源清单定义
Kubernetes常用资源对象 依据资源的主要功能作为分类标准,Kubernetes的API对象大体可分为五个类别,如下: 类型 名称 工作负载(Workload) Pod.ReplicaSet.D ...
随机推荐
- Windows 10 中CPU虚拟化已开启,但是docker无法运行
在管理员模式下的PowerShell中执行: bcdedit /set hypervisorlaunchtype Auto 然后重启电脑即可
- Java HashSet对txt文本内容去重(统计小说用过的字或字数)
Java HashSet对txt文本内容去重(统计小说用过的字或字数) 基本思路: 1.字节流读需要去重的txt文本.(展示demo为当前workspace下名为utf-8.txt的文本) 2.对读取 ...
- 心脏滴血漏洞复现(CVE-2014-0160)
心脏滴血漏洞简述 2014年4月7日,OpenSSL发布安全公告,在OpenSSL1.0.1版本至OpenSSL1.0.1f Beta1版本中存在漏洞,该漏洞中文名称为心脏滴血,英文名称为HeartB ...
- CheckStyle,定制属于自己的Java编码规范
前言 如今,代码规范几乎是当下稍有追求的团队都要求做到的,但是对于Java编码规范,不同的公司或团队却有着不同的标准.尽管官方提供了一些标准,但是在基本规则的基础上,各大公司又有自己的规范,比如Sun ...
- 从壹开始【NetCore3.0】 46 ║ 授权认证:自定义返回格式
前言 哈喽大家好,马上就要年末了,距离新的一年,只有50天了,春节是75天. 在这个时节内,天气逐渐变凉,但是大家的心肯定很热吧,因为发生了两件大事: 1.双十一买买买,在这个让人激动又纠结的一天,大 ...
- 小白学 Python(19):基础异常处理
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...
- 使用vue-cookies操作cookie
1.前言 在vue中如果想要操作cookie,除了使用之前我们自己封装好的操作cookie的方法之外,我们还可以使用vue-cookies插件,这是一个简单的Vue.js插件,专门用于在vue中处理浏 ...
- .netcore之DI批量注入(支持泛型) - xms
一旦系统内模块比较多,按DI标准方法去逐个硬敲AddScoped/AddSingleton/AddTransient缺乏灵活性且效率低下,所以批量注入提供了很大的便捷性,特别是对于泛型的服务类,下面介 ...
- 使用Bootstrap制作简单的旅游主页
页面效果 代码: 需要导入bootstrapt文件,解压至项目中. 下载地址:https://v3.bootcss.com/getting-started/#download <!DOCTYPE ...
- PHP导出成PDF你用哪个插件
准备工作 首先查询了相关的类库,有FPDF,zendPDF,TcPDF等等.首先看了下先选择了FPDF,可以说除了中文字符以外没有什么问题,中文乱码而且看了下最新版本没有很好的解决方案,所以只能放弃. ...