_index
weight: 10
title: Kubernetes 中的资源对象
linkTitle: 资源对象
date: “2022-05-21T00:00:00+08:00”
type: book
以下列举的内容都是
- Pod
- Node
- Namespace
- Service
- Volume
- PersistentVolume
- Deployment
- Secret
- StatefulSet
- DaemonSet
- ServiceAccount
- ReplicationController
- ReplicaSet
- Job
- CronJob
- SecurityContext
- ResourceQuota
- LimitRange
- HorizontalPodAutoscaling
- Ingress
- ConfigMap
- Label
- CustomResourceDefinition
- Role
- ClusterRole
我将它们简单的分类为以下几种资源对象:
类别 | 名称 |
---|---|
资源对象 | Pod、ReplicaSet、ReplicationController、Deployment、StatefulSet、DaemonSet、Job、CronJob、HorizontalPodAutoscaling、Node、Namespace、Service、Ingress、Label、CustomResourceDefinition |
存储对象 | Volume、PersistentVolume、Secret、ConfigMap |
策略对象 | SecurityContext、ResourceQuota、LimitRange |
身份对象 | ServiceAccount、Role、ClusterRole |
理解Kubernetes 中的对象
在
- 什么容器化应用在运行(以及在哪个
Node 上) - 可以被应用使用的资源
- 关于应用如何表现的策略,比如重启策略、升级策略,以及容错策略
与kubectl
命令行接口时,比如,golang
客户端库 ,其它语言库(例如Python)也正在开发中。
对象Spec 与状态
每个
例如,
关于对象
描述Kubernetes 对象
当创建kubectl
kubectl
在执行
这里有一个 .yaml
示例文件,展示了
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
一种创建.yaml
文件,是使用 kubectl
命令行接口(CLI)中的 kubectl create
命令,传递 .yaml
作为参数。下面是一个示例:
$ kubectl create -f docs/user-guide/nginx-deployment.yaml --record
输出类似如下这样:
deployment "nginx-deployment" created
必需字段
在想要创建的.yaml
文件中,需要配置如下的字段:
apiVersion
- 创建该对象所使用的Kubernetes API 的版本kind
- 想要创建的对象的类型metadata
- 帮助识别对象唯一性的数据,包括一个name
字符串、UID 和可选的namespace
也需要提供对象的 spec
字段。对象 spec
的精确格式对每个