[root@master2 ~]# kubectl explain rs KIND: ReplicaSet VERSION: apps/v1 DESCRIPTION: ReplicaSet ensures that a specified number of pod replicas are running at any given time. FIELDS: apiVersion <string> #当前资源使用的api版本,跟VERSION: apps/v1保持一致 kind <string> #资源类型,跟KIND: ReplicaSet保持一致 metadata <Object> #元数据,定义Replicaset名字的 spec <Object> ##定义副本数、定义标签选择器、定义Pod模板 status <Object> #状态信息,不能改
查看replicaset的spec字段如何定义
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@master2 ~]# kubectl explain rs.spec KIND: ReplicaSet VERSION: apps/v1 RESOURCE: spec <Object> DESCRIPTION: Spec defines the specification of the desired behavior of the ReplicaSet. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status ReplicaSetSpec is the specification of a ReplicaSet. FIELDS: minReadySeconds <integer> replicas <integer> #定义的pod副本数,根据我们指定的值创建对应数量的pod selector <Object> -required- #用于匹配pod的标签选择器 template <Object> #定义Pod的模板,基于这个模板定义的所有pod是一样的
查看replicaset的spec.template字段如何定义
1 2 3 4 5 6 7 8 9 10 11
[root@master2 ~]# kubectl explain rs.spec.template KIND: ReplicaSet VERSION: apps/v1 RESOURCE: template <Object> DESCRIPTION: Template is the object that describes the pod that will be created if insufficient replicas are detected。PodTemplateSpec describes the data a pod should have when created from a template FIELDS: metadata <Object> spec <Object>
KIND: Deployment VERSION: apps/v1 DESCRIPTION: Deployment enables declarative updates for Pods and ReplicaSets. FIELDS: apiVersion <string> #该资源使用的api版本 kind <string> #创建的资源是什么? metadata <Object> #元数据,包括资源的名字和名称空间 spec <Object> #定义容器的 status <Object> #状态,不可以修改
查看Deployment下的spec字段
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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> #Kubernetes在等待设置的时间后才进行升级,默认时间是0秒 #如果没有设置该值,Kubernetes会假设该容器启动起来后就提供服务了 paused <boolean> #暂停,当我们更新的时候创建pod先暂停,不是立即更新 progressDeadlineSeconds <integer> # k8s 在升级过程中有可能由于各种原因升级卡住(这个时候还没有明确的升级失败),比如在拉取被墙的镜像,权限不够等错误。那么这个时候就需要有个 deadline ,在 deadline 之内如果还卡着,那么就上报这个情况,这个时候这个 Deployment 状态就被标记为 False,并且注明原因。但是它并不会阻止 Deployment 继续进行卡住后面的操作。完全由用户进行控制。 replicas <integer> #副本数 revisionHistoryLimit <integer> #保留的历史版本,默认是10 selector <Object> -required- #标签选择器,选择它关联的pod strategy <Object> #更新策略 template <Object> -required #定义的pod模板
查看Deployment下的spec.strategy字段
1 2 3 4 5 6 7 8 9 10 11 12 13 14
KIND: Deployment VERSION: apps/v1 RESOURCE: strategy <Object> DESCRIPTION: The deployment strategy to use to replace existing pods with new ones. DeploymentStrategy describes how to replace existing pods with new ones. FIELDS: rollingUpdate <Object> type <string> Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate. #支持两种更新,Recreate和RollingUpdate #Recreate是重建式更新,删除一个更新一个 #RollingUpdate滚动更新,定义滚动更新方式,也就是pod能多几个,少几个
查看Deployment下的spec.strategy.rollingUpdate字段
1 2 3 4 5 6 7 8 9 10 11 12 13 14
KIND: Deployment VERSION: apps/v1 RESOURCE: rollingUpdate <Object> DESCRIPTION: Rolling update config params. Present only if DeploymentStrategyType = RollingUpdate. Spec to control the desired behavior of rolling update. FIELDS: maxSurge <string> #我们更新的过程当中最多允许超出的指定的目标副本数有几个; #它有两种取值方式,第一种直接给定数量,第二种根据百分比,百分比表示原本是5个,最多可以超出20%,那就允许多一个,最多可以超过40%,那就允许多两个 maxUnavailable <string> #最多允许几个不可用 #假设有5个副本,最多一个不可用,就表示最少有4个可用
查看Deployment下的spec.template字段
1 2 3 4 5 6 7 8 9 10 11
#template为定义Pod的模板,Deployment通过模板创建Pod KIND: Deployment VERSION: apps/v1 RESOURCE: template <Object> DESCRIPTION: Template describes the pods that will be created. PodTemplateSpec describes the data a pod should have when created from a template FIELDS: metadata <Object> #定义模板的名字 spec <Object> #deployment.spec.template为Pod定义的模板,和Pod定义不太一样,template中不包含apiVersion和Kind属性,要求必须有metadata。#deployment.spec.template.spec为容器的属性信息,其他定义内容和Pod一致。
DESCRIPTION: Rolling update config params. Present only if DeploymentStrategyType = RollingUpdate.
Spec to control the desired behavior of rolling update.
FIELDS: maxSurge <string> The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to 25%. Example: when this is set to 30%, the new ReplicaSet can be scaled up immediately when the rolling update starts, such that the total number of old and new pods do not exceed 130% of desired pods. Once old pods have been killed, new ReplicaSet can be scaled up further, ensuring that total number of pods running at any time during the update is at most 130% of desired pods.
maxUnavailable <string> The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is set to 30%, the old ReplicaSet can be scaled down to 70% of desired pods immediately when the rolling update starts. Once new pods are ready, old ReplicaSet can be scaled down further, followed by scaling up the new ReplicaSet, ensuring that the total number of pods available at all times during the update is at least 70% of desired pods.