LFS258-LAB-Managing State With Deployment

使用ReplicaSets

1.創(chuàng)建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的狀態(tài)

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創(chuàng)建的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搂根,而不刪除創(chuàng)建的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的情況下創(chuàng)建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.創(chuàng)建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狀態(tài)

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

滾動(dòng)升級和回滾

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.查看升級狀態(tài)揭北,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.查看升級狀態(tài)

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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末荐绝,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子旷痕,更是在濱河造成了極大的恐慌碳锈,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,817評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件欺抗,死亡現(xiàn)場離奇詭異售碳,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,329評論 3 385
  • 文/潘曉璐 我一進(jìn)店門贸人,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人艺智,你說我怎么就攤上這事×撸” “怎么了?”我有些...
    開封第一講書人閱讀 157,354評論 0 348
  • 文/不壞的土叔 我叫張陵父晶,是天一觀的道長。 經(jīng)常有香客問我弄跌,道長甲喝,這世上最難降的妖魔是什么铛只? 我笑而不...
    開封第一講書人閱讀 56,498評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮淳玩,結(jié)果婚禮上直撤,老公的妹妹穿的比我還像新娘。我一直安慰自己蜕着,他們只是感情好谋竖,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,600評論 6 386
  • 文/花漫 我一把揭開白布蓖乘。 她就那樣靜靜地躺著,像睡著了一般嘉抒。 火紅的嫁衣襯著肌膚如雪袍暴。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,829評論 1 290
  • 那天政模,我揣著相機(jī)與錄音,去河邊找鬼览徒。 笑死,一個(gè)胖子當(dāng)著我的面吹牛纽什,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播芦缰,決...
    沈念sama閱讀 38,979評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼让蕾,長吁一口氣:“原來是場噩夢啊……” “哼浪规!你這毒婦竟也來了探孝?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,722評論 0 266
  • 序言:老撾萬榮一對情侶失蹤缸濒,失蹤者是張志新(化名)和其女友劉穎粱腻,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绍些,經(jīng)...
    沈念sama閱讀 44,189評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡柬批,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,519評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了萝快。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,654評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡旋恼,死狀恐怖奄容,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情昂勒,我是刑警寧澤,帶...
    沈念sama閱讀 34,329評論 4 330
  • 正文 年R本政府宣布奠衔,位于F島的核電站,受9級特大地震影響归斤,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜她我,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,940評論 3 313
  • 文/蒙蒙 一迫横、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧矾踱,春花似錦、人聲如沸拴事。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,762評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至哮针,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間十厢,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,993評論 1 266
  • 我被黑心中介騙來泰國打工缩抡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留包颁,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,382評論 2 360
  • 正文 我出身青樓蘑险,卻偏偏與公主長得像,于是被迫代替她去往敵國和親佃迄。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,543評論 2 349

推薦閱讀更多精彩內(nèi)容

  • 1.4 Kubernetes基本概念和術(shù)語 ?Kubernetes中的大部分概念如Node堆缘、Pod柴信、Replica...
    Chandler_玨瑜閱讀 3,896評論 1 32
  • 一、 K8s 是什么随常? Kubernetes(k8s)是自動(dòng)化容器操作的開源平臺(tái),這些操作包括部署唆鸡,調(diào)度和節(jié)點(diǎn)集群...
    loveroot閱讀 6,640評論 1 21
  • 1枣察、基礎(chǔ)架構(gòu) 1.1 Master Master節(jié)點(diǎn)上面主要由四個(gè)模塊組成:APIServer、scheduler...
    阿斯蒂芬2閱讀 10,863評論 0 44
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理臂痕,服務(wù)發(fā)現(xiàn),斷路器握童,智...
    卡卡羅2017閱讀 134,633評論 18 139
  • 排錯(cuò)指南 - Pod 本文檔介紹 Pod 的異常狀態(tài)叛赚,可能原因和解決辦法。 排查 Pod 異常的常用命令如下: 查...
    小孩子的童話2014閱讀 6,962評論 0 2