亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不尊重使用 DeletionGracePeriodSeconds 創建 Kubernetes POD

不尊重使用 DeletionGracePeriodSeconds 創建 Kubernetes POD

Go
眼眸繁星 2022-07-11 14:47:12
我正在使用 Golang 創建 Kubernetes POD。我正在嘗試設置 DeletionGracePeriodSeconds 但在創建 pod 之后,該 pod 在此字段中有 30 而我設置為 25。 pod 的名稱是好的,所以在創建 POD 后它具有我在代碼中分配的名稱。func setupPod(client *Client, ns string, name string, labels map[string]string) (*v1.Pod, error) {     seconds := func(i int64) *int64 { return &i }(25)     pod := &v1.Pod{}     pod.Name = name     pod.Namespace = ns     pod.SetDeletionGracePeriodSeconds(seconds) //it is 25 seconds under debugger     pod.DeletionGracePeriodSeconds = seconds     pod.Spec.Containers = []v1.Container{v1.Container{Name: "ubuntu", Image: "ubuntu", Command: []string{"sleep", "30"}}}     pod.Spec.NodeName = "node1"     if labels != nil {        pod.Labels = labels     }     _, err := client.client.CoreV1().Pods(ns).Create(client.context, pod, metav1.CreateOptions{})     return pod, err}
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻1900條經驗 獲得超5個贊

DeletionGracePeriodSeconds是只讀的,因此您無法更改它。您應該改為設置terminationGracePeriodSeconds,kubernetes 將DeletionGracePeriodSeconds相應地設置。您可以通過獲取值并打印它來驗證這一點。


來自API 文檔


此對象從系統中刪除之前允許正常終止的秒數。僅當還設置了deletionTimestamp 時才設置。只能縮短。只讀.


podSpec := &v1.Pod{

        Spec: v1.PodSpec{

            TerminationGracePeriodSeconds: <Your-Grace-Period>

        },

    }


    _, err = clientset.CoreV1().Pods("namespacename").Create(context.TODO(), podSpec, metav1.CreateOptions{})



查看完整回答
反對 回復 2022-07-11
  • 1 回答
  • 0 關注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號