猿问

不尊重使用 DeletionGracePeriodSeconds 创建 Kubernetes POD

我正在使用 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

}


眼眸繁星
浏览 234回答 1
1回答

梵蒂冈之花

DeletionGracePeriodSeconds是只读的,因此您无法更改它。您应该改为设置terminationGracePeriodSeconds,kubernetes 将DeletionGracePeriodSeconds相应地设置。您可以通过获取值并打印它来验证这一点。来自API 文档此对象从系统中删除之前允许正常终止的秒数。仅当还设置了deletionTimestamp 时才设置。只能缩短。只读.podSpec := &v1.Pod{&nbsp; &nbsp; &nbsp; &nbsp; Spec: v1.PodSpec{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TerminationGracePeriodSeconds: <Your-Grace-Period>&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; }&nbsp; &nbsp; _, err = clientset.CoreV1().Pods("namespacename").Create(context.TODO(), podSpec, metav1.CreateOptions{})
随时随地看视频慕课网APP

相关分类

Go
我要回答