您好,登錄后才能下訂單哦!
這篇文章主要講解了“Kubernetes中Node異常時Pod狀態(tài)是怎樣的”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Kubernetes中Node異常時Pod狀態(tài)是怎樣的”吧!
一個節(jié)點(diǎn)上運(yùn)行著pod前提下,這個時候把kubelet進(jìn)程停掉。里面的pod會被干掉嗎?會在其他節(jié)點(diǎn)recreate嗎?
結(jié)論:
(1)Node狀態(tài)變?yōu)镹otReady (2)Pod 5分鐘之內(nèi)狀態(tài)無變化,5分鐘之后的狀態(tài)變化:Daemonset的Pod狀態(tài)變?yōu)镹odelost,Deployment、Statefulset和Static Pod的狀態(tài)先變?yōu)镹odeLost,然后馬上變?yōu)閁nknown。Deployment的pod會recreate,但是Deployment如果是node selector停掉kubelet的node,則recreate的pod會一直處于Pending的狀態(tài)。Static Pod和Statefulset的Pod會一直處于Unknown狀態(tài)。
如果kubelet 10分鐘后又起來了,node和pod會怎樣?
結(jié)論:
(1)Node狀態(tài)變?yōu)镽eady。 (2)Daemonset的pod不會recreate,舊pod狀態(tài)直接變?yōu)镽unning。 (3)Deployment的則是將kubelet進(jìn)程停止的Node刪除(原因可能是因為舊Pod狀態(tài)在集群中有變化,但是Pod狀態(tài)在變化時發(fā)現(xiàn)集群中Deployment的Pod實(shí)例數(shù)已經(jīng)夠了,所以對舊Pod做了刪除處理) (4)Statefulset的Pod會重新recreate。 (5)Staic Pod沒有重啟,但是Pod的運(yùn)行時間會在kubelet起來的時候置為0。
在kubelet停止后,statefulset的pod會變成nodelost,接著就變成unknown,但是不會重啟,然后等kubelet起來后,statefulset的pod才會recreate。
還有一個就是Static Pod在kubelet重啟以后應(yīng)該沒有重啟,但是集群中查詢Static Pod的狀態(tài)時,Static Pod的運(yùn)行時間變了
Node down后,StatefulSet Pods並沒有重建,為什麼?
我們在node controller中發(fā)現(xiàn),除了daemonset pods外,都會調(diào)用delete pod api刪除pod。
但并不是調(diào)用了delete pod api就會從apiserver/etcd中刪除pod object,僅僅是設(shè)置pod 的deletionTimestamp,標(biāo)記該pod要被刪除。真正刪除Pod的行為是kubelet,kubelet grace terminate該pod后去真正刪除pod object。這個時候statefulset controller 發(fā)現(xiàn)某個replica缺失就會去recreate這個pod。
但此時由于kubelet掛了,無法與master通信,導(dǎo)致Pod Object一直無法從etcd中刪除。如果能成功刪除Pod Object,就可以在其他Node重建Pod。
另外,要注意,statefulset只會針對isFailed Pod,(但現(xiàn)在Pods是Unkown狀態(tài))才會去delete Pod。
// delete and recreate failed pods if isFailed(replicas[I]) { ssc.recorder.Eventf(set, v1.EventTypeWarning, "RecreatingFailedPod", "StatefulSetPlus %s/%s is recreating failed Pod %s", set.Namespace, set.Name, replicas[I].Name) if err := ssc.podControl.DeleteStatefulPlusPod(set, replicas[I]); err != nil { return &status, err } if getPodRevision(replicas[I]) == currentRevision.Name { status.CurrentReplicas— } if getPodRevision(replicas[I]) == updateRevision.Name { status.UpdatedReplicas— } status.Replicas— replicas[I] = newVersionedStatefulSetPlusPod( currentSet, updateSet, currentRevision.Name, updateRevision.Name, i) }
所以針對node異常的情況,有狀態(tài)應(yīng)用(Non-Quorum)的保障,應(yīng)該補(bǔ)充以下行為:
監(jiān)測node的網(wǎng)絡(luò)、kubelet進(jìn)程、操作系統(tǒng)等是否異常,區(qū)別對待。
比如,如果是網(wǎng)絡(luò)異常,Pod無法正常提供服務(wù),那么需要kubectl delete pod -f —grace-period=0
進(jìn)行強(qiáng)制從etcd中刪除該pod。
強(qiáng)制刪除后,statefulset controller就會自動觸發(fā)在其他Node上recreate pod。
亦或者,更粗暴的方法,就是放棄GracePeriodSeconds,StatefulSet Pod GracePeriodSeconds為nil或者0,則就會直接從etcd中刪除該object。
// BeforeDelete tests whether the object can be gracefully deleted. // If graceful is set, the object should be gracefully deleted. If gracefulPending // is set, the object has already been gracefully deleted (and the provided grace // period is longer than the time to deletion). An error is returned if the // condition cannot be checked or the gracePeriodSeconds is invalid. The options // argument may be updated with default values if graceful is true. Second place // where we set deletionTimestamp is pkg/registry/generic/registry/store.go. // This function is responsible for setting deletionTimestamp during gracefulDeletion, // other one for cascading deletions. func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.Object, options *metav1.DeleteOptions) (graceful, gracefulPending bool, err error) { objectMeta, gvk, kerr := objectMetaAndKind(strategy, obj) if kerr != nil { return false, false, kerr } if errs := validation.ValidateDeleteOptions(options); len(errs) > 0 { return false, false, errors.NewInvalid(schema.GroupKind{Group: metav1.GroupName, Kind: "DeleteOptions"}, "", errs) } // Checking the Preconditions here to fail early. They'll be enforced later on when we actually do the deletion, too. if options.Preconditions != nil && options.Preconditions.UID != nil && *options.Preconditions.UID != objectMeta.GetUID() { return false, false, errors.NewConflict(schema.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, objectMeta.GetName(), fmt.Errorf("the UID in the precondition (%s) does not match the UID in record (%s). The object might have been deleted and then recreated", *options.Preconditions.UID, objectMeta.GetUID())) } gracefulStrategy, ok := strategy.(RESTGracefulDeleteStrategy) if !ok { // If we're not deleting gracefully there's no point in updating Generation, as we won't update // the obcject before deleting it. return false, false, nil } // if the object is already being deleted, no need to update generation. if objectMeta.GetDeletionTimestamp() != nil { // if we are already being deleted, we may only shorten the deletion grace period // this means the object was gracefully deleted previously but deletionGracePeriodSeconds was not set, // so we force deletion immediately // IMPORTANT: // The deletion operation happens in two phases. // 1. Update to set DeletionGracePeriodSeconds and DeletionTimestamp // 2. Delete the object from storage. // If the update succeeds, but the delete fails (network error, internal storage error, etc.), // a resource was previously left in a state that was non-recoverable. We // check if the existing stored resource has a grace period as 0 and if so // attempt to delete immediately in order to recover from this scenario. if objectMeta.GetDeletionGracePeriodSeconds() == nil || *objectMeta.GetDeletionGracePeriodSeconds() == 0 { return false, false, nil } ... } ... }
感謝各位的閱讀,以上就是“Kubernetes中Node異常時Pod狀態(tài)是怎樣的”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Kubernetes中Node異常時Pod狀態(tài)是怎樣的這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。