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

一、通过文件创建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

原文地址:https://www.cnblogs.com/luoahong/p/10302601.html

时间: 2024-10-03 07:24:36

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

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

一.nginx保证有两个版本 1.查看当前容器运行nginx版本 [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE myweb-7w38b 1/1 Running 0 4h 172.16.10.4 k8s-node1 myweb-btflm 1/1 Running 0 4h 172.16.48.4 k8s-node2 myweb-cbt47 1/1 Running 0 4h 17

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

一.kubectl run命令拓展 1.RC创建 [root@k8s-master ~]# kubectl run web --generator=run/v1 --image=10.0.128.0:5000/nginx:1.13 --replicas=3 replicationcontroller "web" created 2.deployment创建 [root@k8s-master ~]# kubectl run web --image=10.0.128.0:5000/ngin

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

一.文件创建带--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

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

一.自动伸缩 1.启动 [root@k8s-master ~]# kubectl autoscale deployment nginx-deployment --max=8 --min=2 --cpu-percent=80 deployment "nginx-deployment" autoscaled 2.查看创建 [root@k8s-master ~]# kubectl get all NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE de

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

一.如何实现外界能访问 外界访问不了 1.启动svc [root@k8s-master ~]# cat myweb-svc.yaml apiVersion: v1 kind: Service metadata: name: nginx spec: type: NodePort ports: - port: 80 nodePort: 30001 selector: app: myweb [root@k8s-master ~]# kubectl create -f myweb-svc.yaml se

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

一.rc控制器常用命令 1.rc控制器信息查看 [root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT READY AGE myweb 3 3 3 3m [root@k8s-master ~]# kubectl get rc NAME DESIRED CURRENT READY AGE myweb 3 3 3 5m 2.删除rc [root@k8s-master ~]# kubectl delete

openStack 云平台管理节点管理网口流量非常大 出现丢包严重 终端总是时常中断问题调试及当前测试较有效方案

tuning for Data Transfer hosts connected at speeds of 1Gbps or higher <一.本次OpenStack系统调试简单过程简单记录> 1,dmesg 日志,丢包问题关键原因定位; [101231.909932] net_ratelimit: 85 callbacks suppressed 2,ethstatus -i p5p1 实时追踪网口TX/RX状态; 3,具体内核等相关参数调整 # recommended default co

Triton - 创新的开源云平台管理软件

SmartOS是基于Solaris的一个开源的操作系统,囊括了ZFS, Zone, Crossbow, DTrace, KVM, Bhyve等卓越的技术; Triton是基于SmartOS的一套开源免费的云平台管理软件,媲美openstack的所有主要功能模块,安装.升级.管理却比openstack简单很多.所有节点是从USB盘或者网络启动,系统不需要安装到硬盘,所以没有普通OS中的安装和打补丁的概念,系统升级只是需要从新的U盘启动就行.每一个系统核心服务都是通过一个image实现的,通过下载新

云平台项目实战(华为篇)

目前很多政府企业机房还是一个较为典型的传统数据中心,运行着企业的各种应用系统,为员工提供7*24信息化服务.中心机房采用传统的数据中心架构,多是单机运行应用,部分应用采用不同硬件平台的数据备份技术以提供一定程度的应用与数据的安全.随着应用系统不断发展,这种架构配置日益复杂化,安全难以保证.目前,各计算与存储资源均是单一硬件部署,没有整合成统一的资源池,在资源整合与利用率方面较弱. 传统数据中心-->云计算数据中心 很多政府企业数据中心也在不断转变,好了,废话不多说,无私奉献,我来一个干货,我给大