研發工程師玩轉Kubernetes——就緒探針(Readiness Probe)和服務(Service)

在《研發工程師玩轉Kubernetes——啟動、存活和就緒探針》中,我們講了就緒探針和服務之間的特殊關系。就緒探針檢測失敗并不代表整個程序處于“非存活”狀態,可能只是短暫臨時的不可以提供服務,比如CPU階段性占滿,導致就緒探針檢測超時而導致失敗。這個時候就緒探針并不會向存活探針那樣嘗試重啟容器,而只是簡單的把它從何它關聯的Service中摘除。

帶Readiness Probe的Nginx

apiVersion: apps/v1
kind: Deployment
metadata:name: readiness-nginx-deployment
spec:selector:matchLabels:app: readiness-nginxreplicas: 2template:metadata:labels:app: readiness-nginxspec:containers:- name: readiness-nginx-containerimage: nginxports:- containerPort: 80command: ["/bin/sh", "-c", "sleep 3; touch /tempdir/readiness-nginx; while true; do sleep 5; done"]volumeMounts:- name:  probe-volumemountPath:  /tempdirreadinessProbe:exec:command:- cat- /tempdir/readiness-nginxinitialDelaySeconds: 2failureThreshold: 6periodSeconds: 1successThreshold: 1volumes:- name: probe-volumeemptyDir: medium: MemorysizeLimit: 1Gi

Nginx關聯的Service

kind: Service
apiVersion: v1
metadata:name: readiness-nginx-service
spec:selector:app: readiness-nginxports:- protocol: TCPport: 80targetPort: 80

實驗

創建上述組件,可以看到啟動了下面的Pod

kubectl get pod -o wide
NAME                                          READY   STATUS    RESTARTS   AGE   IP             NODE      NOMINATED NODE   READINESS GATES
readiness-nginx-deployment-57b7fd5644-7x7wc   1/1     Running   0          25s   10.1.43.223    ubuntuc   <none>           <none>
readiness-nginx-deployment-57b7fd5644-lhszp   1/1     Running   0          25s   10.1.209.155   ubuntub   <none>           <none>

Service也綁定了這些IP。

kubectl describe endpoints readiness-nginx-service 
Name:         readiness-nginx-service
Namespace:    default
Labels:       <none>
Annotations:  endpoints.kubernetes.io/last-change-trigger-time: 2023-08-14T14:35:33Z
Subsets:Addresses:          10.1.209.155,10.1.43.223NotReadyAddresses:  <none>Ports:Name     Port  Protocol----     ----  --------<unset>  80    TCPEvents:  <none>

現在我們挑選一個容器(readiness-nginx-deployment-57b7fd5644-7x7wc,10.1.43.223),觀察該容器的Event狀態:

kubectl describe pod readiness-nginx-deployment-57b7fd5644-7x7wc
Name:             readiness-nginx-deployment-57b7fd5644-7x7wc
Namespace:        default
Priority:         0
Service Account:  default
Node:             ubuntuc/172.22.247.176
Start Time:       Mon, 14 Aug 2023 14:35:27 +0000
Labels:           app=readiness-nginxpod-template-hash=57b7fd5644
Annotations:      cni.projectcalico.org/containerID: c475d3e82ff0d5adbd35252ab990608ad75955f8d0862bb8b0c54ee60a0878ebcni.projectcalico.org/podIP: 10.1.43.223/32cni.projectcalico.org/podIPs: 10.1.43.223/32
Status:           Running
IP:               10.1.43.223
IPs:IP:           10.1.43.223
Controlled By:  ReplicaSet/readiness-nginx-deployment-57b7fd5644
Containers:readiness-nginx-container:Container ID:  containerd://5d82d8467bc6e0c8151e40ee3258d54bffec8659bcdad4a441848ea8f77a3223Image:         nginxImage ID:      docker.io/library/nginx@sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31caPort:          80/TCPHost Port:     0/TCPCommand:/bin/sh-csleep 3; touch /tempdir/readiness-nginx; while true; do sleep 5; doneState:          RunningStarted:      Mon, 14 Aug 2023 14:35:30 +0000Ready:          TrueRestart Count:  0Readiness:      exec [cat /tempdir/readiness-nginx] delay=2s timeout=1s period=1s #success=1 #failure=6Environment:    <none>Mounts:/tempdir from probe-volume (rw)/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c4tcl (ro)
Conditions:Type              StatusInitialized       True Ready             True ContainersReady   True PodScheduled      True 
Volumes:probe-volume:Type:       EmptyDir (a temporary directory that shares a pod's lifetime)Medium:     MemorySizeLimit:  1Gikube-api-access-c4tcl:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type     Reason     Age                    From               Message----     ------     ----                   ----               -------Normal   Scheduled  3m53s                  default-scheduler  Successfully assigned default/readiness-nginx-deployment-57b7fd5644-7x7wc to ubuntucNormal   Pulling    3m53s                  kubelet            Pulling image "nginx"Normal   Pulled     3m50s                  kubelet            Successfully pulled image "nginx" in 2.489885583s (2.489893984s including waiting)Normal   Created    3m50s                  kubelet            Created container readiness-nginx-containerNormal   Started    3m50s                  kubelet            Started container readiness-nginx-containerWarning  Unhealthy  3m48s (x2 over 3m48s)  kubelet            Readiness probe failed: cat: /tempdir/readiness-nginx: No such file or directory

可以看到就緒探針在第3次檢測時就存在了,這個時候Pod的Ready和ContainersReady都是True的狀態。

就緒->非就緒

現在我們刪除就緒標志文件

kubectl exec pods/readiness-nginx-deployment-57b7fd5644-7x7wc --container readiness-nginx-container -- rm /tempdir/readiness-nginx

再觀察其狀態,可以發現

Name:             readiness-nginx-deployment-57b7fd5644-7x7wc
Namespace:        default
Priority:         0
Service Account:  default
Node:             ubuntuc/172.22.247.176
Start Time:       Mon, 14 Aug 2023 14:35:27 +0000
Labels:           app=readiness-nginxpod-template-hash=57b7fd5644
Annotations:      cni.projectcalico.org/containerID: c475d3e82ff0d5adbd35252ab990608ad75955f8d0862bb8b0c54ee60a0878ebcni.projectcalico.org/podIP: 10.1.43.223/32cni.projectcalico.org/podIPs: 10.1.43.223/32
Status:           Running
IP:               10.1.43.223
IPs:IP:           10.1.43.223
Controlled By:  ReplicaSet/readiness-nginx-deployment-57b7fd5644
Containers:readiness-nginx-container:Container ID:  containerd://5d82d8467bc6e0c8151e40ee3258d54bffec8659bcdad4a441848ea8f77a3223Image:         nginxImage ID:      docker.io/library/nginx@sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31caPort:          80/TCPHost Port:     0/TCPCommand:/bin/sh-csleep 3; touch /tempdir/readiness-nginx; while true; do sleep 5; doneState:          RunningStarted:      Mon, 14 Aug 2023 14:35:30 +0000Ready:          FalseRestart Count:  0Readiness:      exec [cat /tempdir/readiness-nginx] delay=2s timeout=1s period=1s #success=1 #failure=6Environment:    <none>Mounts:/tempdir from probe-volume (rw)/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c4tcl (ro)
Conditions:Type              StatusInitialized       True Ready             False ContainersReady   False PodScheduled      True 
Volumes:probe-volume:Type:       EmptyDir (a temporary directory that shares a pod's lifetime)Medium:     MemorySizeLimit:  1Gikube-api-access-c4tcl:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type     Reason     Age                 From     Message----     ------     ----                ----     -------Warning  Unhealthy  7s (x22 over 6m6s)  kubelet  Readiness probe failed: cat: /tempdir/readiness-nginx: No such file or directory

可以看到Ready和ContainersReady都變成了False狀態。
我們再觀察Service

kubectl describe endpoints readiness-nginx-service 
Name:         readiness-nginx-service
Namespace:    default
Labels:       <none>
Annotations:  endpoints.kubernetes.io/last-change-trigger-time: 2023-08-14T14:41:18Z
Subsets:Addresses:          10.1.209.155NotReadyAddresses:  10.1.43.223Ports:Name     Port  Protocol----     ----  --------<unset>  80    TCPEvents:  <none>

可以看到被刪除了就緒探針檢測文件的Pod被從Service中摘掉了。

非就緒->就緒

我們再將檢測文件還原

kubectl exec pods/readiness-nginx-deployment-57b7fd5644-7x7wc --container readiness-nginx-container -- touch /tempdir/readiness-nginx

觀察對應Pod的狀態,其Ready和ContainersReady又變成了True狀態。

Name:             readiness-nginx-deployment-57b7fd5644-7x7wc
Namespace:        default
Priority:         0
Service Account:  default
Node:             ubuntuc/172.22.247.176
Start Time:       Mon, 14 Aug 2023 14:35:27 +0000
Labels:           app=readiness-nginxpod-template-hash=57b7fd5644
Annotations:      cni.projectcalico.org/containerID: c475d3e82ff0d5adbd35252ab990608ad75955f8d0862bb8b0c54ee60a0878ebcni.projectcalico.org/podIP: 10.1.43.223/32cni.projectcalico.org/podIPs: 10.1.43.223/32
Status:           Running
IP:               10.1.43.223
IPs:IP:           10.1.43.223
Controlled By:  ReplicaSet/readiness-nginx-deployment-57b7fd5644
Containers:readiness-nginx-container:Container ID:  containerd://5d82d8467bc6e0c8151e40ee3258d54bffec8659bcdad4a441848ea8f77a3223Image:         nginxImage ID:      docker.io/library/nginx@sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31caPort:          80/TCPHost Port:     0/TCPCommand:/bin/sh-csleep 3; touch /tempdir/readiness-nginx; while true; do sleep 5; doneState:          RunningStarted:      Mon, 14 Aug 2023 14:35:30 +0000Ready:          TrueRestart Count:  0Readiness:      exec [cat /tempdir/readiness-nginx] delay=2s timeout=1s period=1s #success=1 #failure=6Environment:    <none>Mounts:/tempdir from probe-volume (rw)/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c4tcl (ro)
Conditions:Type              StatusInitialized       True Ready             True ContainersReady   True PodScheduled      True 
Volumes:probe-volume:Type:       EmptyDir (a temporary directory that shares a pod's lifetime)Medium:     MemorySizeLimit:  1Gikube-api-access-c4tcl:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type     Reason     Age                   From     Message----     ------     ----                  ----     -------Warning  Unhealthy  3m5s (x262 over 13m)  kubelet  Readiness probe failed: cat: /tempdir/readiness-nginx: No such file or directory

Service也重新將其加回來了。

Name:         readiness-nginx-service
Namespace:    default
Labels:       <none>
Annotations:  endpoints.kubernetes.io/last-change-trigger-time: 2023-08-14T14:48:23Z
Subsets:Addresses:          10.1.209.155,10.1.43.223NotReadyAddresses:  <none>Ports:Name     Port  Protocol----     ----  --------<unset>  80    TCPEvents:  <none>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/37682.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/37682.shtml
英文地址,請注明出處:http://en.pswp.cn/news/37682.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【Spring MVC】Spring MVC基于注解的程序開發

目錄 一、什么是Spring MVC 二、Spring MVC項目的創建和使用 1、實現客戶端和服務器端之間的連接 1.1、RequsestMapping注解 1.2、RequestMapper的簡單使用 1.3、使用GetMapping和POSTMapping注解來實現HTTP連接 三、獲取參數 1、實現獲取單個參數 2、實現獲取對象 3…

解決ubantu驅動掉了的問題

這里寫自定義目錄標題 解決ubuntu驅動掉了的問題 解決ubuntu驅動掉了的問題 首先確定是否有驅動&#xff1a; ls /usr/src | grep nvidia若有&#xff0c;則大概率是驅動版本與內核版本對應不上&#xff0c;則把內核版本切換為初始版本即可。參照&#xff1a;https://blog.cs…

書寫自動智慧:探索Python文本分類器的開發與應用:支持二分類、多分類、多標簽分類、多層級分類和Kmeans聚類

書寫自動智慧&#xff1a;探索Python文本分類器的開發與應用&#xff1a;支持二分類、多分類、多標簽分類、多層級分類和Kmeans聚類 文本分類器&#xff0c;提供多種文本分類和聚類算法&#xff0c;支持句子和文檔級的文本分類任務&#xff0c;支持二分類、多分類、多標簽分類…

nodejs+vue+elementui+express智慧社區小區物業管理系統的設計與實現_2p760

開發語言 node.js 框架&#xff1a;Express 前端:Vue.js 數據庫&#xff1a;mysql 數據庫工具&#xff1a;Navicat 開發軟件&#xff1a;VScode 前端nodejsvueelementuiexpress vue的文件結構其實就是一個index.html 中間的內容&#xff0c;用的是vue&#xff0c;但最終都會轉…

OpenCV圖像處理——形態學操作

目錄 連通性形態學操作腐蝕和膨脹開閉運算禮帽和黑帽 連通性 形態學操作 形態學轉換是基于圖像形狀的一些簡單操作。它通常在二進制圖像上執行。腐蝕和膨脹時兩個基本的形態學運算符。然后它的變體形式如開運算&#xff0c;閉運算&#xff0c;禮帽黑帽等 腐蝕和膨脹 cv.erode…

費曼學習法

費曼學習法 費曼學習法&#xff08;Feynman Technique&#xff09;是一種學習和理解復雜概念的方法&#xff0c;以理查德費曼&#xff08;Richard Feynman&#xff09;這位著名的理論物理學家命名。該方法的核心思想是通過將學習內容簡化并用自己的話解釋給別人&#xff0c;來…

Node.js學習筆記-04

這第九章也是個大重點 九、玩轉進程 Node在選型時決定在V8引擎之上構建&#xff0c;也就意味著它的模型與瀏覽器類似。 本章關于進程的介紹和討論將會解決如下兩個問題&#xff1a; 單進程單線程并非完美&#xff0c;如今CPU基本均是多核的&#xff0c;真正的服務器&#xf…

背上小書包準備面試之TypeScript篇

目錄 typescript是啥&#xff1f;與javascript的區別&#xff1f; typescript數據類型&#xff1f; typescript中枚舉類型&#xff1f;應用場景&#xff1f; typescript中接口的理解&#xff1f;應用場景&#xff1f; typescript中泛型的理解&#xff1f;應用場景&#xf…

輕薄的ESL電子標簽有哪些特性?

在智慧物聯逐漸走進千萬家的當下&#xff0c;技術變革更加日新月異。ESL電子標簽作為科技物聯的重要組成部分&#xff0c;是推動千行百業數字化轉型的重要技術&#xff0c;促進物聯網產業的蓬勃發展。在智慧零售、智慧辦公、智慧倉儲等領域&#xff0c;ESL電子標簽在未來是不可…

win11右下角圖標(網絡,音量,電量)點擊無反應問題,兩分鐘解決!

win11系統用的好好的&#xff0c;突然有一天任務欄右下角的常用三件套&#xff08;網絡&#xff0c;音量&#xff0c;電量&#xff09;左鍵單擊沒反應&#xff0c;無法方便的調節音量和連接wifi&#xff0c;如下圖所示&#xff0c;但是右鍵好用&#xff0c;不過不方便。網上查了…

嵌入式 C 語言程序數據基本存儲結構

一、5大內存分區 內存分成5個區&#xff0c;它們分別是堆、棧、自由存儲區、全局/靜態存儲區和常量存儲區。 1、棧區(stack)&#xff1a;FIFO就是那些由編譯器在需要的時候分配&#xff0c;在不需要的時候自動清除的變量的存儲區。里面的變量通常是局部變量、函數參數等。 ?…

【Windows API】獲取卷標、卷名

1、卷->卷標 使用FindFirstVolume()和FindNextVolume()函數體系&#xff0c;枚舉系統所有卷&#xff08;Volume&#xff09;的例子&#xff0c;然后獲取卷標、卷類型。這個方式可以枚舉出沒有驅動器號&#xff08;卷標&#xff09;的卷。 int TestMode1() {HANDLE hVolume…

Failed to connect to bitbucket.org port 443

瀏覽器可以訪問bitbucket&#xff0c;但是在終端或者sourcetree上死活無法進行pull, push等操作。 Root Cause&#xff1a;“【翻】【墻】軟件”使用了http proxy&#xff0c;所以也得為git設置相同的http proxy。 所以&#xff0c;解決方法是&#xff1a; 1&#xff0c;查看“…

網絡系統架構演變

1.系統架構演變 隨著互聯網的發展&#xff0c;網站應用的規模不斷擴大。需求的激增&#xff0c;帶來的是技術上的壓力。系統架構也因此不斷的演進、升級、迭代。從單一應用&#xff0c;到垂直拆分&#xff0c;到分布式服務&#xff0c;到SOA&#xff0c;以及現在火熱的微服務架…

【Django】無法從“django.utils.encoding”導入名稱“force_text”

整晚處理 Django 的導入錯誤。 我將把它作為提醒&#xff0c;希望處于相同情況的人數會減少。 原因 某些軟件包版本不支持Django 4 請看下表并決定Django和Python的版本 方案 如果出現難以響應&#xff0c;或者更改環境麻煩&#xff0c;請嘗試以下操作 例如出現以下錯誤 …

云計算的發展前景怎么樣

云計算是當前科技領域中最受關注的領域之一,它的出現改變了傳統的計算模式,使得企業和個人能夠更加便捷地訪問和使用計算資源。隨著云計算技術的不斷發展,它的前景也變得更加光明。 以下是云計算的發展前景: 云計算的市場份額將繼續增長:根據市場研究機構的報告,云計算的市場份…

vfuhyuuy

Sublime Text is an awesome text editor. If you’ve never heard of it, you shouldcheck it out right now. I’ve made this tutorial because there’s no installer for the Linux versions of Sublime Text. While that’s not a real problem, I feel there is a clean…

通過版本號控制強制刷新瀏覽器或清空瀏覽器緩存

背景介紹 在我們做 web 項目時&#xff0c;經常會遇到一個問題就是&#xff0c;需要 通知業務人員&#xff08;系統用戶&#xff09;刷新瀏覽器或者清空瀏覽器 cookie 緩存的情況。 而對于用戶而言&#xff0c;很多人一方面不懂如何操作&#xff0c;另一方面由于執行力問題&am…

Android descendantFocusability 屬性

view 焦點問題處理 作用 通過該屬性可以指定viewGroup和其子View到底誰獲取焦點&#xff0c; 直接在viewGroup上使用就行。 屬性值 屬性值含義beforeDescendantsviewgroup會優先其子類控件而獲取到焦點afterDescendantsviewgroup只有當其子類控件不需要獲取焦點時才獲取焦點…

MFC創建和使用OCX控件

文章目錄 MFC建立OCX控件注冊OCX控件與反注冊使用Internet Explorer測試ocx控件OCX控件添加方法OCX控件添加事件Web使用OCX控件MFC使用OCX控件使用OCX控件調用ocx的功能函數對ocx的事件響應OCX控件調試工具tstcon32.exe加載ocx控件使用tstcon32.exe調試ocxMFC建立OCX控件 新建…