K8S通过yaml格式的声明式API与资源对象交互
API版本由apiVersion
字段指定,API对象类型由kind
字段指定
除此之外,每个API对象有三大类属性:
metadata
:元数据spec
:规范status
:状态
Pod
一般很少单独定义Pod,字段如下:
apiVersion: v1
kind: pod
metadata
namespace
:非必须,默认为"default"
name
:必须指定,命名空间内唯一
spec
containers
:Pod内的容器,数组类型,每个元素以-
开头
Containers元素字段:
args
:<[]string>
,entrypoint的参数,$()
取变量,$$
表$
command
:<[]string>
,entrypoint数组image
:<string>
,容器镜像名imagePullPolicy
:<string>
,镜像拉取策略Always
(默认)Never
IfNotPresent
workingDir
:容器工作目录volumeMounts
:数据卷挂载ports
:暴露端口,不阻止未指定的端口的暴露readinessProbe
:就绪探头livenessProbe
:存活探头
Deployment
Deployment定义如下:
apiVersion: apps/v1
kind: Deployment
metadata
namespace
name
spec
replicas
:期望的pod数,默认为1strategy
:pod替换策略(非必需)type
:Recreate
:创建新pod前删除所有旧podRollingUpdate
:默认,使rollingUpdate
字段生效,滚动更新策略
rollingUpdate
:指定滚动更新的参数maxSurge
:最大的可以存在的pod超出replicas
的数量maxUnavailable
:最大的不可用pod数量
selector
:pod的标签选择器matchLabels
:键值对map,逻辑与相连
template
:描述创建pod的模板matadata
:pod.metadata
spec
:pod.spec