LFS258-LAB-Managing State With Deployment

使用ReplicaSets

1.创建replicaset

apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  name: rs-one
spec:
  replicas: 2
  template:
    metadata:
      labels:
        system: ReplicaOne
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

student@ubuntu:~/job$kubectl create -f rs.yaml 
replicaset.extensions/rs-one created

2.查看replicaset的状态

student@ubuntu:~/job$kubectl get rs
NAME     DESIRED   CURRENT   READY   AGE
rs-one   2         2         2       47s

student@ubuntu:~/job$kubectl describe replicasets. rs-one 
Name:         rs-one
Namespace:    default
Selector:     system=ReplicaOne
Labels:       system=ReplicaOne
Annotations:  <none>
Replicas:     2 current / 2 desired
Pods Status:  2 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  system=ReplicaOne
  Containers:
   nginx:
    Image:        nginx
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  88s   replicaset-controller  Created pod: rs-one-gccmz
  Normal  SuccessfulCreate  88s   replicaset-controller  Created pod: rs-one-j7p55

3.查看rs创建的pod

student@ubuntu:~/job$kubectl get po
NAME           READY   STATUS    RESTARTS   AGE
rs-one-gccmz   1/1     Running   0          3m15s
rs-one-j7p55   1/1     Running   0          3m15s

4.删除rs,而不删除创建的pod

student@ubuntu:~/job$kubectl delete rs rs-one --cascade=false
replicaset.extensions "rs-one" deleted
student@ubuntu:~/job$kubectl get pod,rs
NAME               READY   STATUS    RESTARTS   AGE
pod/rs-one-gccmz   1/1     Running   0          4m29s
pod/rs-one-j7p55   1/1     Running   0          4m29s
  1. 不更新label的情况下创建rs
student@ubuntu:~/job$kubectl get rs
NAME     DESIRED   CURRENT   READY   AGE
rs-one   2         2         2       16s
student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
rs-one-gccmz   1/1     Running   0          5m35s
rs-one-j7p55   1/1     Running   0          5m35s
  1. 修改pod label使其脱离rs的管控
student@ubuntu:~/job$kubectl edit po rs-one-gccmz 
...
kind: Pod
metadata:
  annotations:
    cni.projectcalico.org/podIP: 192.168.0.169/32
    kubernetes.io/limit-ranger: 'LimitRanger plugin set: cpu, memory request for container
      nginx; cpu, memory limit for container nginx'
  creationTimestamp: 2018-12-04T02:10:16Z
  generateName: rs-one-
  labels:
    system: ReplicaOne-new
  name: rs-one-gccmz
student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
rs-one-88cjg   1/1     Running   0          56s
rs-one-gccmz   1/1     Running   0          7m59s
rs-one-j7p55   1/1     Running   0          7m59s

7.查看pod的label

student@ubuntu:~/job$kubectl get pod -L system
NAME           READY   STATUS    RESTARTS   AGE     SYSTEM
rs-one-88cjg   1/1     Running   0          111s    ReplicaOne
rs-one-gccmz   1/1     Running   0          8m54s   ReplicaOne-new
rs-one-j7p55   1/1     Running   0          8m54s   ReplicaOne

8.删除rs

student@ubuntu:~/job$kubectl delete rs rs-one 
replicaset.extensions "rs-one" deleted
student@ubuntu:~/job$kubectl get po
NAME           READY   STATUS        RESTARTS   AGE
rs-one-gccmz   1/1     Running       0          9m29s
rs-one-j7p55   0/1     Terminating   0          9m29s

9.使用label删除pod

student@ubuntu:~/job$kubectl delete pod -l system=ReplicaOne-new
pod "rs-one-gccmz" deleted

使用daemonset

1.创建daemonset

student@ubuntu:~/job$cat ds.yaml 
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: rs-one
spec:
  template: 
    metadata:
      labels:
        system: ReplicaOne
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

student@ubuntu:~/job$kubectl create -f ds.yaml 
daemonset.extensions/rs-one created

2.查看daemonset状态

student@ubuntu:~/job$kubectl get ds
NAME     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
rs-one   2         2         2       2            2           <none>          28s
student@ubuntu:~/job$kubectl get po
NAME           READY   STATUS    RESTARTS   AGE
rs-one-dmdxv   1/1     Running   0          33s
rs-one-jr62m   1/1     Running   0          33s

滚动升级和回滚

1.查看升级的policy

student@ubuntu:~/job$kubectl get ds rs-one -o yaml|grep -A 1 -i stra
  updateStrategy:
    type: OnDelete

2.升级ds

student@ubuntu:~/job$kubectl set image ds rs-one nginx=nginx:1.9.10
daemonset.extensions/rs-one image updated

3.查看升级状态,ds已更新,pod未更新

student@ubuntu:~/job$kubectl describe ds rs-one |grep -i image
    Image:        nginx:1.9.10


student@ubuntu:~/job$kubectl describe pod  |grep -i image
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:5d32f60db294b5deb55d078cd4feb410ad88e6fe77500c87d3970eca97f54dba
  Normal  Pulling    5m39s  kubelet, node-193  pulling image "nginx"
  Normal  Pulled     5m35s  kubelet, node-193  Successfully pulled image "nginx"
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:5d32f60db294b5deb55d

4.删除pod,查看更新情况

student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
rs-one-dmdxv   1/1     Running   0          7m12s
rs-one-jr62m   1/1     Running   0          7m12s
student@ubuntu:~/job$kubectl delete pod rs-one-dmdxv 
pod "rs-one-dmdxv" deleted
student@ubuntu:~/job$kubectl describe po |grep -i image
    Image:          nginx:1.9.10
    Image ID:       
  Normal  Pulling    9s    kubelet, node-193  pulling image "nginx:1.9.10"
    Image:          nginx

5.查看升级历史

student@ubuntu:~/job$kubectl rollout history ds 
daemonset.extensions/rs-one 
REVISION  CHANGE-CAUSE
1         <none>
2         <none>

student@ubuntu:~/job$kubectl rollout history ds rs-one --revision=2
daemonset.extensions/rs-one with revision #2
Pod Template:
  Labels:   system=ReplicaOne
  Containers:
   nginx:
    Image:  nginx:1.9.10
    Port:   80/TCP
    Host Port:  0/TCP
    Environment:    <none>
    Mounts: <none>
  Volumes:  <none>

student@ubuntu:~/job$kubectl rollout history ds rs-one --revision=1
daemonset.extensions/rs-one with revision #1
Pod Template:
  Labels:   system=ReplicaOne
  Containers:
   nginx:
    Image:  nginx
    Port:   80/TCP
    Host Port:  0/TCP
    Environment:    <none>
    Mounts: <none>
  Volumes:  <none>

6.回滚版本

student@ubuntu:~/job$kubectl rollout undo ds rs-one --to-revision=1
daemonset.extensions/rs-one rolled back
student@ubuntu:~/job$kubectl describe ds rs-one |grep -i image
    Image:        nginx

7.pod的升级policy是Ondelete,所以没有改变

student@ubuntu:~/job$kubectl describe pod |grep -i image:
    Image:          nginx:1.9.10
    Image:          nginx

student@ubuntu:~/job$kubectl delete pod --all
pod "rs-one-jphxj" deleted
pod "rs-one-jr62m" deleted
student@ubuntu:~/job$kubectl describe pod |grep -i image:
    Image:          nginx
    Image:          nginx

8.修改ds的升级为RollingUpdate

student@ubuntu:~/job$kubectl edit ds rs-one

  updateStrategy:
    type: RollingUpdate

9.查看升级状态

student@ubuntu:~/job$kubectl describe pod |grep -i image:
    Image:          nginx
    Image:          nginx
student@ubuntu:~/job$kubectl set image ds rs-one nginx=nginx:1.9.10
daemonset.extensions/rs-one image updated
student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS        RESTARTS   AGE
rs-one-797cw   1/1     Running       0          2m47s
rs-one-mb6ns   0/1     Terminating   0          2m47s
student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS              RESTARTS   AGE
rs-one-797cw   1/1     Running             0          2m55s
rs-one-dm6rl   0/1     ContainerCreating   0          5s
student@ubuntu:~/job$kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
rs-one-dm6rl   1/1     Running   0          14s
rs-one-v74l7   1/1     Running   0          7s
student@ubuntu:~/job$kubectl describe pod |grep -i image
    Image:          nginx:1.9.10
    Image ID:       docker-pullable://nginx@sha256:ca132615822fdf485c49ce2ca8d7d04494136af6c90e55c0f0b3a7f274817e0b
  Normal  Pulling    24s   kubelet, ubuntu    pulling image "nginx:1.9.10"
  Normal  Pulled     21s   kubelet, ubuntu    Successfully pulled image "nginx:1.9.10"
    Image:          nginx:1.9.10
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,222评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,455评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,720评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,568评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,696评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,879评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,028评论 3 409
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,773评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,220评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,550评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,697评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,360评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,002评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,782评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,010评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,433评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,587评论 2 350

推荐阅读更多精彩内容

  • 1.4 Kubernetes基本概念和术语  Kubernetes中的大部分概念如Node、Pod、Replica...
    Chandler_珏瑜阅读 3,896评论 1 32
  • 一、 K8s 是什么? Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群...
    loveroot阅读 6,640评论 1 21
  • 1、基础架构 1.1 Master Master节点上面主要由四个模块组成:APIServer、scheduler...
    阿斯蒂芬2阅读 10,864评论 0 44
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,633评论 18 139
  • 排错指南 - Pod 本文档介绍 Pod 的异常状态,可能原因和解决办法。 排查 Pod 异常的常用命令如下: 查...
    小孩子的童话2014阅读 6,962评论 0 2