k8s修改节点的conditions

说明

  • 起因是装了node-problem-detector,启用了一些check之后,不想要,导致节点的conditions一直留着,强迫症难受

  • k8s集群版本1.20

节点conditions

这里想去掉RAMRoleError,kubectl各种patch都不行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- type: RAMRoleError
status: 'false'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: NodeHasNoRAMRole
message: node has no ram role
- type: PublicNetworkError
status: 'false'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: PublicNetworkOffline
message: node could not connect to public network
- type: KernelDeadlock
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: KernelHasNoDeadlock
message: kernel has no deadlock
- type: ReadonlyFilesystem
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: FilesystemIsReadOnly
message: Filesystem is read-only
- type: FDPressure
status: Unknown
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: NodeHasNoFDPressure
message: node has no fd pressure
- type: NvidiaXidError
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: NodeHasNoNvidiaXidError
message: Node has no Nvidia Xid error occured
- type: NTPProblem
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: NTPIsUp
message: ntp service is up
- type: PSProcessHang
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: PSProcessIsHung
message: ps process is hung
- type: irqbalanceStatus
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: irqbalanceOpen
message: node irqbalance service open
- type: NetworkUnavailable
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: FlannelIsUp
message: Flannel is running on this node
- type: MemoryPressure
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: KubeletHasSufficientMemory
message: kubelet has sufficient memory available
- type: DiskPressure
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: KubeletHasNoDiskPressure
message: kubelet has no disk pressure
- type: PIDPressure
status: 'False'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: KubeletHasSufficientPID
message: kubelet has sufficient PID available
- type: Ready
status: 'True'
lastHeartbeatTime: 'xxxxxxxxxxxxxxxxxxxx'
lastTransitionTime: 'xxxxxxxxxxxxxxxxxxxx'
reason: KubeletReady
message: kubelet is posting ready status

操作

  1. 获取节点status,另存为json1
1
2
3
4
5
6
7
$ curl -X PATCH \
-H 'Content-Type: application/json-patch+json' \
--cacert /path/to/cacert \
--cert /path/to/clientcert \
--key /path/to/clientkey \
https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}/api/v1/nodes/${NODE_NAME}/status \
> json1
  1. 修改后的节点status,另存为json2
  2. 用 json-patch 生成对应的json-patch op

ubuntu-20.04安装python3-jsonpatch

1
$ JSON_OP=$(jsondiff json1 json2)
  1. 提交json-patch

这里用kubectl patch不成功,转而用curl命令来操作

1
2
3
4
5
6
7
$ curl -X PATCH \
-H 'Content-Type: application/json-patch+json' \
--cacert /path/to/cacert \
--cert /path/to/clientcert \
--key /path/to/clientkey \
https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}/api/v1/nodes/${NODE_NAME}/status \
-d $JSON_OP
  1. 检查节点conditions
1
$ kubectl describe node ${NODE_NAME}