K8S kubectl 常用命令 - 升级回滚,弹性伸缩

# yaml文件内容
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: xxxxxxxxxxx
  name: xxxxxxxxxxx
spec:
  replicas: 2                    # 2 副本
  selector:
    matchLabels:                # controller匹配pod标签
      app: xxxxxxxxxxx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:                    # 标签
        app: xxxxxxxxxxx
    spec:
      containers:
      - image: nginx:1.14        # 1.14版本nginx
        name: nginx
        resources: {}
status: {}

# 应用升级nginx到1.15
kubectl set image deployment xxxxxxxxxxx nginx=nginx:1.15

 

# 查看升级状态
kubectl rollout status deployment xxxxxxxxxxx

# 查看历史版本
kubectl rollout history deployment xxxxxxxxxxx

# 回滚,还原到上一个版本
kubectl rollout undo deployment xxxxxxxxxxx


# 回滚到指定版本
kubectl rollout undo deployment xxxxxxxxxxx --to-revision=2
# 2 表示版本?


# 弹性伸缩
kubectl scale deployment xxxxxxxxxxx --replicas=5

 

posted on 2021-02-27 22:03  五月の花  阅读(173)  评论(0编辑  收藏  举报

导航