Deployment

Deployment为了解决ReplicaSet和Pods更新的问题

第一个Deployment清单文件

清单文件内容

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 2
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: myapp
      release: canary
      environment: qa
  strategy:
    type: RollingUpdate
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      name: myapp-container
      labels:
        app: myapp
        release: canary
        environment: qa
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: app-port
          containerPort: 80
        livenessProbe:
          tcpSocket:
            port: app-port
          timeoutSeconds: 1
        readinessProbe:
          httpGet:
            scheme: HTTP
            port: app-port
            path: /index.html

这个清单文件中,有几个关键的字段

关键字段注释

更新策略相关字段

  • .spec.strategy.rollingUpdate.maxSurge: 最大同时更新的Pod粒度,可以是整数,也可以是百分比
  • .spec.strategy.rollingUpdate.maxUnavailable: 最大处于不可用的Pod粒度,可以是整数,也可以是百分比
  • PS: 需要注意的是两个字段,两个值不能同时等于0

存活/就绪性状态检测

  • .spec.template.spec.container.livenessProbe: 存货性状态检测
  • .spec.template.spec.containers.readinessProbe: 就绪性状态检测

两种检测都支持三种检测方式

  • exec: 执行命令检测判断返回码是否为0
  • tcpSocket: 检测TCP套接字
  • httpGet: Get方式检测URL

还有其他检测相关参数

  • successThreshold: 检测几次算成功
  • failureThreshold: 检测几次算失败
  • periodSeconds: 检测频率

测试滚动更新

新建两个窗口,一个执行更新,一个观察更新细节

更新镜像

# kubectl set image deployment myapp-deploy myapp=ikubernetes/myapp:v2

观察更新细节 命令一:

# kubectl rollout status -w deployment/myapp-deploy

命令二:

# kubectl get pods -w -o wide

回滚更新

# kubectl rollout undo deploy myapp-deploy

results matching ""

    No results matching ""