kubernetes deployment

语法
1 matedata
2 kind:固定为Deployment
3 apiVersion
4 spec

  • template:和pod template一致
  • metadata
    labels
  • spec
    containers
    • name: nginx
      image: nginx:1.7.9
      ports:
      - containerPort: 80

replicas:
selector: .spec.selector must match .spec.template.metadata.labels, or it will be rejected by the API.

  • matchLabels:
  • matchExpressions selector创建后不允许修改,除非删除后重建,原因是:This could be because
    of the kubernetes service and you are trying to do a rolling upgrade,
    once deployed the label selectors of kubernetes service can not be
    updated until you decide to delete the existing deployment so that
    the services have new label selectors to point to new pods with the
    updated label.

如果修改apply时候提示:invalid spec.selector field is immutable
状态
1 desired
2 current
3 up-to-date:要求版本数量
4 available

  • 运行并可以对外使用
  • 可能要求启动一段时间,健康可用

Ali CNCF kubernetes deployment
POD名称
1 {deployment-name}-{tempalte-hash}-{random-suffix}
2 template hash 与版本有关

image update and rollout
1 kubectl set image deployment nginx=‘new version image’
2 kubectl rollout undo deployment --to-revision=2
3 kubectl rollout history deployment-name
4 kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1
5 用kubectl rollout undo命令回滚Deployment,不会创建新的ReplicaSet
status

release policy
1 revisionHistoryLimit:specify how many old ReplicaSets for this Deployment you want to retain
2 By default, it is 10

canary release
If you want to roll out releases to a subset of users or servers using the Deployment, you can create multiple Deployments, one for each release

Strategy
Recreate Deployment
All existing Pods are killed before new ones are created when .spec.strategy.type==Recreate,(default )Rolling Update Deployment

Max Unavailable
The value cannot be 0 if .spec.strategy.rollingUpdate.maxSurge is 0

Max Surge
.spec.strategy.rollingUpdate.maxSurge ,the maximum number of Pods that can be created over the desired number of Pods

.spec.progressDeadlineSeconds
number of seconds you want to wait for your Deployment to progress before the system reports back that the Deployment has failed progressing

.spec.minReadySeconds
1 specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing, for it to be considered available
2 see Container Probes
3 大于时间才进行健康检查,才可能available

.spec.paused
管理模式
只负责管理不同版本的ReplicaSet
Ali CNCF kubernetes deployment
控制和生成ReplicaSetAli CNCF kubernetes deployment

发布(回滚)新版本时候会同时存在2个replicasset

相关文章: