這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
所有涉及到儲存的地方都是極易出現“坑”的地方,Kubernetes也不例外。
一、問題起因
問題始於昨天升級一個stateful service的操作。該service下的Pod掛載了使用ceph RBD提供的一個Persistent Volume。該Pod是用普通deployment部署的,並沒有使用處於alpha狀態的PetSet。改動僅僅是image的版本發生了變化。我執行的操作如下:
# kubectl apply -f index-api.yaml
操作是成功的。但命令執行後,再次查看index-api這個Pod的狀態,該Pod的狀態長期處於:“ContainerCreating”,顯然Pod沒能重啟成功。
進一步通過describe pod 檢視events,發現如下Warning:
events: FirstSeen LastSeen Count From SubobjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 2m 2m 1 {default-scheduler } Normal Scheduled Successfully assigned index-api-3362878852-9tm9j to 10.46.181.146 11s 11s 1 {kubelet 10.46.181.146} Warning FailedMount Unable to mount volumes for pod "index-api-3362878852-9tm9j_default(ad89c829-f40b-11e6-ad11-00163e1625a9)": timeout expired waiting for volumes to attach/mount for pod "index-api-3362878852-9tm9j"/"default". list of unattached/unmounted volumes=[index-api-pv] 11s 11s 1 {kubelet 10.46.181.146} Warning FailedSync Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "index-api-3362878852-9tm9j"/"default". list of unattached/unmounted volumes=[index-api-pv]
index-api這個Pod嘗試掛載index-api-pv這個pv逾時,並失敗。
二、問題探索和臨時解決
首先查看問題pod所在Node(10.46.181.146)上的kubelet日誌,kubelet負責與本地的docker engine以及其他本地服務互動:
... ...I0216 13:59:27.380007 1159 reconciler.go:294] MountVolume operation started for volume "kubernetes.io/rbd/7e6c415a-f40c-11e6-ad11-00163e1625a9-index-api-pv" (spec.Name: "index-api-pv") to pod "7e6c415a-f40c-11e6-ad11-00163e1625a9" (UID: "7e6c415a-f40c-11e6-ad11-00163e1625a9").E0216 13:59:27.393946 1159 disk_manager.go:56] failed to attach diskE0216 13:59:27.394013 1159 rbd.go:228] rbd: failed to setup mount /var/lib/kubelet/pods/7e6c415a-f40c-11e6-ad11-00163e1625a9/volumes/kubernetes.io~rbd/index-api-pv rbd: image index-api-image is locked by other nodesE0216 13:59:27.394121 1159 nestedpendingoperations.go:254] Operation for "\"kubernetes.io/rbd/7e6c415a-f40c-11e6-ad11-00163e1625a9-index-api-pv\" (\"7e6c415a-f40c-11e6-ad11-00163e1625a9\")" failed. No retries permitted until 2017-02-16 14:01:27.394076217 +0800 CST (durationBeforeRetry 2m0s). Error: MountVolume.SetUp failed for volume "kubernetes.io/rbd/7e6c415a-f40c-11e6-ad11-00163e1625a9-index-api-pv" (spec.Name: "index-api-pv") pod "7e6c415a-f40c-11e6-ad11-00163e1625a9" (UID: "7e6c415a-f40c-11e6-ad11-00163e1625a9") with: rbd: image index-api-image is locked by other nodesE0216 13:59:32.695919 1159 kubelet.go:1958] Unable to mount volumes for pod "index-api-3362878852-pzxm8_default(7e6c415a-f40c-11e6-ad11-00163e1625a9)": timeout expired waiting for volumes to attach/mount for pod "index-api-3362878852-pzxm8"/"default". list of unattached/unmounted volumes=[index-api-pv]; skipping podE0216 13:59:32.696223 1159 pod_workers.go:183] Error syncing pod 7e6c415a-f40c-11e6-ad11-00163e1625a9, skipping: timeout expired waiting for volumes to attach/mount for pod "index-api-3362878852-pzxm8"/"default". list of unattached/unmounted volumes=[index-api-pv]... ...
通過kubelet的日誌我們可以看出調度到10.46.181.146這個Node上的index-api pod之所以無法掛載ceph RBD volume,是因為index-api-image已經被其他node鎖住。
我的這個小叢集一共就只有兩個Node(10.46.181.146和10.47.136.60),那鎖住index-api-image的就是10.47.136.60這個node了。我們查看一下平台上pv和pvc的狀態:
# kubectl get pvNAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGEceph-pv 1Gi RWO Recycle Bound default/ceph-claim 101dindex-api-pv 2Gi RWO Recycle Bound default/index-api-pvc 49d# kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESSMODES AGEceph-claim Bound ceph-pv 1Gi RWO 101dindex-api-pvc Bound index-api-pv 2Gi RWO 49d
index-api-pv和index-api-pvc的狀態都是正常的,從這裡看不出lock的情況。無奈我只能從ceph這個層面去查問題了!
index-api-image在mioss pool下面,我們利用ceph的rbd cli工具查看一下其狀態:
# rbd ls miossindex-api-image# rbd info mioss/index-api-imagerbd image 'index-api-image': size 2048 MB in 512 objects order 22 (4096 kB objects) block_name_prefix: rb.0.5e36.1befd79f format: 1# rbd disk-usage mioss/index-api-imagewarning: fast-diff map is not enabled for index-api-image. operation may be slow.NAME PROVISIONED USEDindex-api-image 2048M 168M
index-api-image狀態ok。
如果你在執行rbd時,出現下面錯誤:
# rbdrbd: error while loading shared libraries: /usr/lib/x86_64-linux-gnu/libicudata.so.52: invalid ELF header
可以通過重裝libicu52這個包(這裡示範的是基於ubuntu 14.04 amd64的版本)來解決:
# wget -c http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu52_52.1-3ubuntu0.4_amd64.deb# dpkg -i ./libicu52_52.1-3ubuntu0.4_amd64.deb
迴歸正題!
經查manual發現,rbd提供了lock相關子命令可以查看image的lock list:
# rbd lock list mioss/index-api-imageThere is 1 exclusive lock on this image.Locker ID Addressclient.24128 kubelet_lock_magic_node1 10.47.136.60:0/1864102866
真兇找到!我們看到位於10.47.136.60 node上有一個locker將該image鎖住。我嘗試重啟10.47.136.60上的kubelet,發現重啟後,lock依舊。
怎麼取消這個鎖呢?rbd不光提供了lock list命令,還提供了lock remove命令:
lock remove (lock rm) Release a lock on an imageusage: lock remove image-spec lock-id locker Release a lock on an image. The lock id and locker are as output by lock ls.
開始解鎖:
# rbd lock remove mioss/index-api-image kubelet_lock_magic_node1 client.24128
解鎖成功後,delete掉那個處於ContainerCreating的Pod,然後index-api pod就啟動成功了:
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE LABELSdefault index-api-3362878852-m6k0j 1/1 Running 0 10s 172.16.57.7 10.46.181.146 app=index-api,pod-template-hash=3362878852
三、問題簡要分析
從問題現象來看,起因是由於index-api pod被從10.47.136.60這個node調度到 10.46.181.146這個node上而導致的。但是為什麼image的lock沒有釋放的確怪異,因為我的index-api是捕捉pod退回訊號,支援優雅退出的:
# kubectl delete -f index-api-deployment.yamldeployment "index-api" deleted2017/02/16 08:41:27 1 Received SIGTERM.2017/02/16 08:41:27 1 [::]:30080 Listener closed.2017/02/16 08:41:27 1 Waiting for connections to finish...2017/02/16 08:41:27 [C] [asm_amd64.s:2086] ListenAndServe: accept tcp [::]:30080: use of closed network connection 12017/02/16 08:41:27 [I] [engine.go:109] engine[mioss1(online)]: mioss1-29583fe44a637eabe4f865bc59bde44fa307e38e exit!2017/02/16 08:41:27 [I] [engine.go:109] engine[wx81f621e486239f6b(online)]: wx81f621e486239f6b-58b5643015a5f337931aaa4a5f4db1b35ac784bb exit!2017/02/16 08:41:27 [I] [engine.go:109] engine[wxa4d49c280cefd38c(online)]: wxa4d49c280cefd38c-f38959408617862ed69dab9ad04403cee9564353 exit!2017/02/16 08:41:27 [D] [enginemgr.go:310] Search Engines exit ok
因此,初步猜測:這裡很可能是kubernetes在監視和處理pod退出時,對於儲存外掛程式的狀態處理存在一些bug,至於具體什麼問題,還不得而知。
四、小結
對於像index-api service這樣的stateful服務來說,使用普通deployment顯然不能滿足要求。Kubernetes在[1.3.0, 1.5.0)版本區間提供了處於alpha狀態的PetSet controller,在1.5.0版本後,PetSet被改名為StatefulSet。與普通Pod不同,PetSet下面的每個Pet都有嚴格的身份屬性,並根據身份屬性綁定一定資源,並且不會像普通Pod那樣被Kubernetes隨意調度到任意Node上。
像index-api-service索引服務這樣的一個執行個體綁定一個cephRBD pv的應用,特別適合使用PetSet或StatefulSet,不過我這裡尚未測試用上PetSet後是否還會出現無法掛載rbd卷的問題。
微博:@tonybai_cn
公眾號:iamtonybai
github.com帳號: https://github.com/bigwhite
2017, bigwhite. 著作權.