[root@k8smaster node]# kubectl explain deployment
KIND: Deployment
VERSION: apps/v1
DESCRIPTION:
Deployment enables declarative updates for Pods and ReplicaSets.
FIELDS:
apiVersion #该资源使用的 api 版本
kind #创建的资源是什么?
metadata
查看 Deployment 下的 spec 字段
[root@xianchaomaster1 ~]# kubectl explain deployment.spec
[root@k8smaster node]# kubectl explain deployment.spec
KIND: Deployment
VERSION: apps/v1
RESOURCE: spec
DESCRIPTION:
Specification of the desired behavior of the Deployment.
DeploymentSpec is the specification of the desired behavior of the
Deployment.
FIELDS:
minReadySeconds
#Kubernetes 在等待设置的时间后才进行升级 如果没有设置该值,Kubernetes 会假设该容器启动起来后就提供服务了
paused
#暂停,当我们更新的时候创建 pod 先暂停,不是立即更新
progressDeadlineSeconds
#k8s 在升级过程中有可能由于各种原因升级卡住(这个时候还没有明确的升级失败),比如在拉取被墙的镜像,权限不够等错误。那么这个时候就需要有个 deadline ,在 deadline 之内如果还卡着,那么就上报这个情况,这个时候这个 Deployment 状态就被标记为 False,并且注明原因。但是它并不会阻止 Deployment 继续进行卡住后面的操作。完全由用户进行控制。
replicas
#副本数
revisionHistoryLimit
#保留的历史版本,默认是 10
selector -required-
#标签选择器,选择它关联的 pod
strategy
#更新策略
template -required-
#定义的 pod 模板
查看 Deployment 下的 spec.strategy 字段
[root@k8smaster node]# kubectl explain deploy.spec.strategy
KIND: Deployment
VERSION: apps/v1
RESOURCE: strategy
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
#支持两种更新,Recreate 和 RollingUpdate
#Recreate 是重建式更新,删除一个更新一个
#RollingUpdate 滚动更新,定义滚动更新方式,也就是 pod 能多几个,少几个
type
#查看 Deployment 下的 spec.strategy.rollingUpdate 字段
[root@k8smaster node]# kubectl explain deploy.spec.strategy.rollingUpdate
KIND: Deployment
VERSION: apps/v1
RESOURCE: rollingUpdate
DESCRIPTION:
Rolling update config params. Present only if DeploymentStrategyType =
RollingUpdate.
Spec to control the desired behavior of rolling update.
FIELDS:
maxSurge
#我们更新的过程当中最多允许超出的指定的目标副本数有几个,它有两种取值方式,第一种直接给定数量,第二种根据百分比,百分比表示原本是 5 个,最多可以超出 20%,那就允许多一个,最多可以超过 40%,那就允许多两个.
maxUnavailable
#最多允许几个不可用 假设有 5 个副本,最多一个不可用,就表示最少有 4 个可用
查看 Deployment 下的 spec.template 字段,template 为定义 Pod 的模板,Deployment 通过模板创建 Pod
[root@k8smaster node]# kubectl explain deploy.spec.template
KIND: Deployment
VERSION: apps/v1
RESOURCE: template
DESCRIPTION:
Template describes the pods that will be created.
PodTemplateSpec describes the data a pod should have when created from a
template
FIELDS:
metadata #定义模板的名字
spec
deployment.spec.template 为 Pod 定义的模板,和 Pod 定义不太一样,template 中不包含 apiVersion 和 Kind 属性,要求必须有 metadata。deployment.spec.template.spec 为容器的属性信息,其他定义内容和 Pod 一致。
查看 Deployment 下的 spec.template.spec 字段
[root@k8smaster node]# kubectl explain deploy.spec.template.spec
KIND: Deployment
VERSION: apps/v1
RESOURCE: spec
DESCRIPTION:
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
PodSpec is a description of a pod.
FIELDS:
activeDeadlineSeconds
#activeDeadlineSeconds 表示 Pod 可以运行的最长时间,达到设置的该值后,Pod 会自动停止。
affinity
#定义亲和性,跟直接创建 pod 时候定义亲和性类似
automountServiceAccountToken
#身份认证相关的
containers <[]Object> -required-
#定义容器属性
dnsConfig
#设置 Pod 的 DNS 和 host 对齐
dnsPolicy: None
dnsConfig:
nameservers:
- 192.168.11.141
- 192.168.11.140
searches:
- paopao.svc.cluster.local
- my.dns.search.paopao
dnsPolicy
1. dnsPolicy 决定 Pod 内预设的 DNS 配置策略
None 无任何策略:使用自定义的策略
Default 默认:使用宿主机的 dns 配置,/etc/resolv.conf
ClusterFirst 集群 DNS 优先,与 Default 相反,会预先使用 kube-dns (或 CoreDNS ) 的信息当预设置参数写入到该 Pod 内的 DNS 配置。
ClusterFirstWithHostNet 集群 DNS 优先,并伴随着使用宿主机网络:同时使用 hostNetwork 与 kube-dns 作为 Pod 预设 DNS 配置。
enableServiceLinks
ephemeralContainers <[]Object> #定义临时容器
临时容器与其他容器的不同之处在于,它们缺少对资源或执行的保证,并且永远不会自动重启,因此不适用于构建应用程序。临时容器使用与常规容器相同的 ContainerSpec 段进行描述,但许多字段是不相容且不允许的。
临时容器没有端口配置,因此像 ports,livenessProbe,readinessProbe 这样的字段是不允许的,Pod 资源分配是不可变的,因此 resources 配置是不允许的。
临时容器用途: 当由于容器崩溃或容器镜像不包含调试应用程序而导致 kubectl exec 无用时,临时容器对于交互式故障排查很有用。
hostAliases <[]Object> #在 pod 中增加域名解析的 和 containers 对齐
hostAliases:
– ip: "10.1.1.1"
hostnames:
– "mc.local"
– "rabbitmq.local"
- ip: "10.1.2.3"
hostnames:
– "redis.local"
– "mq.local"
hostIPC #使用主机 IPC
hostNetwork #是否使用宿主机的网络
hostPID #可以设置容器里是否可以看到宿主机上的进程。True 可以
hostname
imagePullSecrets <[]Object>
initContainers <[]Object> #定义初始化容器
nodeName #定义 pod 调度到具体哪个节点上
nodeSelector