一、通过文件创建deployment

1、创建deployment文件

[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、启动deployment

[root@k8s-master ~]# kubectl create -f nginx_deploy.yml
deployment "nginx-deployment" created

3、查看deployment状态

[root@k8s-master ~]# kubectl get all
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx-deployment 3 3 3 3 17s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.254.0.1 <none> 443/TCP 1d
svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 21h NAME DESIRED CURRENT READY AGE
rs/nginx-deployment-2950479891 3 3 3 17s NAME READY STATUS RESTARTS AGE
po/nginx-deployment-2950479891-3zzdf 1/1 Running 0 17s
po/nginx-deployment-2950479891-6nqn3 1/1 Running 0 17s
po/nginx-deployment-2950479891-wxxr5 1/1 Running 0 17s

二、通过命令行创建deployment

1、删除方式1创建的deployment

[root@k8s-master ~]# kubectl delete -f nginx_deploy.yml
deployment "nginx-deployment" deleted
[root@k8s-master ~]# kubectl get all
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 1d
nginx 10.254.145.15 <nodes> 80:30027/TCP 21h

2、命令创建

[root@k8s-master ~]# kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record
deployment "nginx" created

3、查看

[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

4、升级镜像版本

[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

四、秒级回滚

1、查看历史版本

[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

2、执行回滚

[root@k8s-master ~]# kubectl rollout undo deployment nginx --to-revision=1
deployment "nginx" rolled back

3、回滚结果

[root@k8s-master ~]# kubectl get all -o wide
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/nginx 5 5 5 5 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-835034785 5 5 5 1m nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx
rs/nginx-984850083 0 0 0 1m nginx 10.0.128.0:5000/nginx:1.15 pod-template-hash=984850083,run=nginx NAME READY STATUS RESTARTS AGE IP NODE
po/nginx-835034785-1j1pp 1/1 Running 0 11s 172.16.19.2 k8s-node2
po/nginx-835034785-8jvd0 1/1 Running 0 11s 172.16.50.4 k8s-node1
po/nginx-835034785-9cn2z 1/1 Running 0 6s 172.16.19.3 k8s-node2
po/nginx-835034785-9v5q6 1/1 Running 0 7s 172.16.50.2 k8s-node1
po/nginx-835034785-wwqx7 1/1 Running 0 5s 172.16.50.5 k8s-node1

4、版本测试

[root@k8s-master ~]# curl -I 172.16.50.4
HTTP/1.1 200 OK
Server: nginx/1.13.12
Date: Mon, 21 Jan 2019 11:45:08 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 09 Apr 2018 16:01:09 GMT
Connection: keep-alive
ETag: "5acb8e45-264"
Accept-Ranges: bytes

kubernetes云平台管理实战: 高级资源deployment-滚动升级(八)的更多相关文章

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

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

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

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

  3. kubernetes云平台管理实战:如何创建deployment更好(九)

    一.文件创建带--record 1.文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions/v1beta1 kind: ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Python Learning: 01

    After a short period of  new year days, I found life a little boring. So just do something funny--Py ...

  2. HP ML150 G6 服务器硬件介绍

    前面板和背面板组件介绍: 1 介质托架                           12 系统运行状况 LED 指示灯 2 USB 2.0 端口 (2)               13 AC ...

  3. 中科曙光I620-G15服务器登录密码破解

    服务器型号:中科曙光I620-G15服务器 系统:windowsserver2008R2 单位:保密 服务器登录密码忘记了,进不去桌面,后来在我们云修网工程师的指导下,顺利绕过密码登录系统,然后修改系 ...

  4. elasticsearch系列一:elasticsearch(ES简介、安装&配置、集成Ikanalyzer)

    一.ES简介 1. ES是什么? Elasticsearch 是一个开源的搜索引擎,建立在全文搜索引擎库 Apache Lucene 基础之上 用 Java 编写的,它的内部使用 Lucene 做索引 ...

  5. 英语口语练习系列-C14-常用片语

    句子 1. Some ads are extremely persuasive and we find we buy products we don't really need. 有一些广告非常有说服 ...

  6. jdbc链接数据库

    JDBC简介 JDBC全称为:Java Data Base Connectivity (java数据库连接),可以为多种数据库提供填统一的访问.JDBC是sun开发的一套数据库访问编程接口,是一种SQ ...

  7. go笔记-pprof使用

    go tool pprof http://localhost:6060/debug/pprof/profile go tool pprof http://localhost:6060/debug/pp ...

  8. 【刷题】若串 =’software’ ,其子串数目为:37

    子串 子串是母串中的一部分,可以是母串本身,也可以是空字符串 设串中字符数为n,则其子串数目为:s=(1+n)*n/2+1 具体地: 长为0的子串:1 长为1的子串:8 长为2的子串:7 长为3的子串 ...

  9. 【问题解决方案】ImportError: No module named 'openpyxl'/‘xlrd’

    背景: 在jupyter notebook to_excle: 运行将dataframe保存为excel文件 df.to_excel('dataframe.xlsx') 时报错openpyxl rea ...

  10. Uint 5.css继承权重,盒模型和border padding

    一 .css的继承性和权重 1.1 继承性:继承是CSS的一个主要特征,它是依赖于祖先-后代的关系的.继承是一种机制,它允许样式不仅可以应用于某个特定的元素,还可以应用于它的后代. 可以被继承的属性有 ...