第5章:kubernetes资源清单定义入门

Kubernetes常用资源类型如下:(注意大小写!!!)
命令空间级别的资源类型:(注意资源名称仅在资源类型下唯一)
(1)Workload:Pod,ReplicaSet,Deployment,StatefulSet,DaemonSet,Job,Cronjob等;
(2)Service Discovery:Service,Ingress等;
(3)Config&Storage:
Configmap,Secret
Storage: Volume(PersistentVolume,PersistentVolumeClaim),StorageClass,CSI,Cloud Storage,分布式存储(Ceph,GlusterFS,NFS),Hostpath,emptyDir;
DownwardAPI
集群级别的资源类型:
Namespace,Node,Role,ClusterRole,RoleBinding,ClusterRoleBinding等
元数据型资源类型:
HPA,PodTemplate,LimitRange等

注意:apiserver仅接收JSON格式的资源定义;(因为JSON较重,因此一种常用方式是让yaml格式提供配置清单,apiserver可自动将其无损转为JSON格式后再执行。)

大部分资源对象的配置清单构成如下:(这里以pod为例)
apiVersion: v1
#这里v1是group/version,可通过kubectl api-versions查看获取;
kind: Pod
#Pod指的是资源类别,一定要注意区分大小写;
metadata:
name:
namespace:
labels:
annotations:
selfLink: /api/v1/namespaces/default/pods/name
#这个资源的引用方式;
spec:
#这一部分最为重要,是Kubernetes给用户自定义所期望的状态信息(desired state)
containers:

  • image: nginx
    imagePullPolicy: Always
    name: nginx-test
    resources: {}
    status:
    #这里是当前状态(current state),本字段由Kubernetes自身维护,用户无法进行删除或维护等操作;
    conditions:
    containerStatuses:

kubectl explain 资源类别
#该命令可以让Kubernetes告诉用户该资源包含哪些信息;
这里以Pod为例;
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
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
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
#这里表示会嵌套很多字段;可以使用kubectl explain Pod.metadata向下钻取详细信息;
Standard object’s metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

spec
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

status
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/sig-architecture/api-conventions.md#spec-and-status

实操:
mkdir test-manifest
#用于创建一个文件夹;
cd test-manifest
#用于进入该文件夹;
vim test-manifest-demo.yaml
#用于进入编辑该yaml文件;
简单举例如下:
apiVersion: v1
kind: Pod
metadata:
name: test-manifest-demo
namespace: default
labels:
app: nginx
tier: frontend
annotations:
spec:
containers:

  • name: nginx-test
    image: nginx

kubectl create -f test-manifest-demo.yaml
#用test-manifest-demo.yaml文件创建资源对象名为test-manifest-demo的pod;

kubectl delete -f test-manifest-demo.yaml
#用于删除资源对象名为test-manifest-demo的pod;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Davidwatt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值