理解 Kubernetes 对象
Kubernetes 对象是持久化的实体, 这些实体用于表示整个集群的状态, 描述了:
- 哪些容器化应用在运行(以及在哪些节点上)
- 可以被应用使用的资源
- 关于应用运行时表现的策略,比如重启策略、升级策略,以及容错策略
Kubernetes 集群的 期望状态(Desired State)
对象规约(Spec)与状态(Status)
对于具有 spec 的对象,你必须在创建对象时设置其内容,描述你希望对象所具有的特征: 期望状态(Desired State) 。
status 描述了对象的 当前状态(Current State),它是由 Kubernetes 系统和组件 设置并更新的。在任何时刻,Kubernetes 控制平面 都一直积极地管理着对象的实际状态,以使之与期望状态相匹配。
使 current status 与 spec 一致.
描述 Kubernetes 对象
示例:
- kubectl 使用 yaml
apiVersion: apps/v1kind: Deploymentmetadata:name: nginx-deploymentspec:selector:matchLabels:app: nginxreplicas: 2 # tells deployment to run 2 pods matching the templatetemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.14.2ports:- containerPort: 80
kubectl apply -f https://k8s.io/examples/application/deployment.yaml --record
