1.利用deployment创建pods

创建deployment_nginx.yml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.12.2
        ports:
        - containerPort: 80

2.创建deployment

kubectl create -f deployment_nginx.yml

3.查看创建的deployment

4.查看deployment更多信息

kubectl get deployment -o wide

5.对deployment升级

将上面的 nginx:1.12.2进行升级至nginx:1.13

kubectl set image deployment nginx-deployment nginx=nginx:1.13

6.升级后的查看:

7.查看更新记录

kubectl rollout history deployment nginx-deployment

默认的部署方式不会记录CHANGE-CAUSE,需要在部署的时候添加 --record 选项~~

spec.revisionHistoryLimit被用来设置保留的历史记录数量,默认为2,设置为0时将不能回滚~~

8.回滚

可以使用kubectl rollout undo deployment nginx-deployment 回到之前的版本

回滚到指定版本:

kubectl rollout undo deployment nginx-deployment --to-revision=2

 

 

 

 

 

 

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐