一、文件创建带--record

1、文件

[root@k8s-master ~]# cat nginx_deploy.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: 10.0.128.0:5000/nginx:1.13
ports:
- containerPort: 80

2、启动

[root@k8s-master ~]# kubectl create -f nginx_deploy.yml --record
deployment "nginx-deployment" created
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx-deployment 3 3 3 3 7s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-deployment-2950479891 3 3 3 7s nginx 10.0.128.0:5000/nginx:1.13 app=nginx,pod-template-hash=2950479891 NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-deployment-2950479891-3dwct 1/1 Running 0 7s 172.16.50.2 k8s-node1
po/nginx-deployment-2950479891-6wvsw 1/1 Running 0 7s 172.16.19.2 k8s-node2
po/nginx-deployment-2950479891-95133 1/1 Running 0 7s 172.16.50.3 k8s-node1

3、更新镜像

[root@k8s-master ~]# vim nginx_deploy.yml
版本手动修改为1.15
[root@k8s-master ~]# kubectl apply -f nginx_deploy.yml
deployment "nginx-deployment" configured
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx-deployment 3 3 3 3 1m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-deployment-2950479891 0 0 0 1m nginx 10.0.128.0:5000/nginx:1.13 app=nginx,pod-template-hash=2950479891
rs/nginx-deployment-3113009173 3 3 3 7s nginx 10.0.128.0:5000/nginx:1.15 app=nginx,pod-template-hash=3113009173 NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-deployment-3113009173-4xrq4 1/1 Running 0 7s 172.16.19.3 k8s-node2
po/nginx-deployment-3113009173-5crv5 1/1 Running 0 5s 172.16.19.2 k8s-node2
po/nginx-deployment-3113009173-vckhg 1/1 Running 0 7s 172.16.50.2 k8s-node1

4、显示历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginx-deployment
deployments "nginx-deployment"
REVISION CHANGE-CAUSE
1 kubectl create -f nginx_deploy.yml --record
2 kubectl apply -f nginx_deploy.yml

二、命令行创建不带--record

1、启动

[root@k8s-master ~]# kubectl delete deployment nginx
deployment "nginx" deleted
[root@k8s-master ~]# kubectl get all -o wide
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb
[root@k8s-master ~]# kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5
deployment "nginx" created
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx 5 5 5 5 7s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-835034785 5 5 5 7s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-835034785-8f4m0 1/1 Running 0 7s 172.16.50.2 k8s-node1
po/nginx-835034785-8j9w2 1/1 Running 0 7s 172.16.19.3 k8s-node2
po/nginx-835034785-c7nx3 1/1 Running 0 7s 172.16.19.4 k8s-node2
po/nginx-835034785-p2vn0 1/1 Running 0 7s 172.16.19.2 k8s-node2
po/nginx-835034785-z42qh 1/1 Running 0 7s 172.16.50.3 k8s-node1

2、更新镜像

[root@k8s-master ~]#  kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15
deployment "nginx" image updated
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx 5 5 5 5 34s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-835034785 0 0 0 34s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx
rs/nginx-984850083 5 5 5 10s nginx 10.0.128.0:5000/nginx:1.15 pod-template-hash=984850083,run=nginx NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-984850083-4pd4w 1/1 Running 0 10s 172.16.19.2 k8s-node2
po/nginx-984850083-k979d 1/1 Running 0 10s 172.16.50.4 k8s-node1
po/nginx-984850083-nljkt 1/1 Running 0 4s 172.16.19.4 k8s-node2
po/nginx-984850083-r3hqh 1/1 Running 0 6s 172.16.19.3 k8s-node2
po/nginx-984850083-x6x47 1/1 Running 0 7s 172.16.50.5 k8s-node1

3、查看历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginx
deployments "nginx"
REVISION CHANGE-CAUSE
1 <none>
2 <none>

三、命令创建不带--record

1、启动

[root@k8s-master ~]# kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record
deployment "nginx" created
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx 5 5 5 0 3s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-835034785 5 5 0 3s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-835034785-b9mnp 0/1 ContainerCreating 0 3s <none> k8s-node2
po/nginx-835034785-gp2m5 0/1 ContainerCreating 0 3s <none> k8s-node1
po/nginx-835034785-hhz0b 0/1 ContainerCreating 0 3s <none> k8s-node1
po/nginx-835034785-mvv4p 0/1 ContainerCreating 0 3s <none> k8s-node2
po/nginx-835034785-x6mjp 0/1 ContainerCreating 0 3s <none> k8s-node1

2、升级镜像版本

[root@k8s-master ~]#  kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15
deployment "nginx" image updated
[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx 5 5 5 5 32s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR
rs/nginx-835034785 0 0 0 32s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx
rs/nginx-984850083 5 5 5 14s nginx 10.0.128.0:5000/nginx:1.15 pod-template-hash=984850083,run=nginx NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-984850083-4xt4s 1/1 Running 0 5s 172.16.50.4 k8s-node1
po/nginx-984850083-gk5fq 1/1 Running 0 7s 172.16.50.2 k8s-node1
po/nginx-984850083-mhp7h 1/1 Running 0 13s 172.16.50.3 k8s-node1
po/nginx-984850083-vs93g 1/1 Running 0 14s 172.16.19.4 k8s-node2
po/nginx-984850083-z5px0 1/1 Running 0 11s 172.16.19.5 k8s-node2

3、查看历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginx
deployments "nginx"
REVISION CHANGE-CAUSE
1 kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record
2 kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15

四、小结

1、创建资源方式总结

方式一:

kubectl create -f nginx_deploy.yml

方式二:

kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record

通过以上三个查看历史版本的详细程度来看方式三为最优,建议生产使用,具体命令如下

kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record

  

kubernetes云平台管理实战:如何创建deployment更好(九)的更多相关文章

  1. kubernetes云平台管理实战:deployment通过标签管理pod(十)

    一.kubectl run命令拓展 1.RC创建 [root@k8s-master ~]# kubectl run web --generator=run/v1 --image=10.0.128.0: ...

  2. kubernetes云平台管理实战: 高级资源deployment-滚动升级(八)

    一.通过文件创建deployment 1.创建deployment文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions ...

  3. kubernetes云平台管理实战:HPA水平自动伸缩(十一)

    一.自动伸缩 1.启动 [root@k8s-master ~]# kubectl autoscale deployment nginx-deployment --max=8 --min=2 --cpu ...

  4. kubernetes云平台管理实战: 滚动升级秒级回滚(六)

    一.nginx保证有两个版本 1.查看当前容器运行nginx版本 [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS REST ...

  5. kubernetes云平台管理实战: 故障自愈实战(四)

    一.创建实验文件 [root@k8s-master ~]# cat myweb-rc.yml apiVersion: v1 kind: ReplicationController metadata: ...

  6. kubernetes云平台管理实战: 集群部署(一)

    一.环境规划 1.架构拓扑图 2.主机规划 3.软件版本 [root@k8s-master ~]# cat /etc/redhat-release CentOS Linux release 7.4.1 ...

  7. kubernetes云平台管理实战: 最小的资源pod(二)

    一.pod初体验 1.编辑k8s_pod.yml文件 [root@k8s-master ~]# cat k8s_pod.yml apiVersion: v1 kind: Pod metadata: n ...

  8. kubernetes云平台管理实战: 自动加载到负载均衡(七)

    一.如何实现外界能访问 外界访问不了 1.启动svc [root@k8s-master ~]# cat myweb-svc.yaml apiVersion: v1 kind: Service meta ...

  9. kubernetes云平台管理实战: 服务发现和负载均衡(五)

    一.rc控制器常用命令 1.rc控制器信息查看 [root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT ...

随机推荐

  1. c/c++ 网络编程 bind函数

    网络编程 bind函数 bind的作用是确定端口号. 正常处理都是先bind,然后listen 如果不bind,直接listen,会是什么结果? 内核会自动随机分配一个端口号 例子: #include ...

  2. js学习之路2: JavaScript 变量

    1. 变量的创建 首先,可以创建一个变量 var firstVar; 这时候,并没有给它赋值.这个变量还是空的. 然后,我们可以给这个变量赋值. firstVar = 128: 2. 变量的赋值 变量 ...

  3. 聚类——GMM

    聚类——认识GMM算法 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.GMM概述 二.GMM算法步骤 三.具体推导参考文献 1. 李航. 统计学习 ...

  4. c#语法学习

    自动属性.隐试类型.命名参数和自动初始化器. note:这里说的这些,是语法糖.按照一定的格式写,部分代码编译器帮我们实现了, 1.自动属性:自动属性是非常有用的语法糖,帮我我们做了两件事:1.自动帮 ...

  5. Linux删除文件夹和修改文件名

    rm [选项] 文件 -f, --force 强力删除,不要求确认 -i 每删除一个文件或进入一个子目录都要求确认 -I 在删除超过三个文件或者递归删除前要求确认 -r, -R 递归删除子目录 -d, ...

  6. Django-CRM项目学习(二)-模仿admin实现stark

    开始今日份整理 1.stark模块基本操作 1.1 stark模块的启动 保证django自动的加载每一个app下的stark.py文件 创建django项目,创建stark项目,start app ...

  7. 聊聊计算机中的编码(Unicode,GBK,ASCII,utf8,utf16,ISO8859-1等)以及乱码问题的解决办法

    作为一个程序员,一个中国的程序员,想来“乱码”问题基本上都遇到过,也为之头疼过.出现乱码问题的根本原因是编码与解码使用了不同而且不兼容的“标准”,在国内一般出现在中文的编解码过程中. 我们平时常见的编 ...

  8. GXOI/GZOI2019题解

    GXOI/GZOI2019题解 P5300 [GXOI/GZOI2019]与或和 一眼题.. 显然枚举每个二进制位,答案就变成了全1子矩阵数量. 这个xjb推推,单调栈一下就行了. #include& ...

  9. Spring AOP前置通知实例说明AOP相关概念

    今天又看了下韩顺平的SpringAOP的讲解,讲解的很透彻.仿照视频自己使用下前置通知. 一.引出问题 有个接口TestServiceInter,有两个实现方法TestService和Test2Ser ...

  10. 基于Grunt构建一个的项目

    没有搭建环境的,请参考<Grunt自动化构建环境搭建 >,搭建完成后 新建一个项目目录,这里建立一个“Demo”目录 运行CMD,并进入这个目录,运行 npm install grunt ...