image.png

image.png

409主机的APIServer日志:
image.png

image.png

https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#delete-collection-pod-v1-core

image.png

image.png

kubectl删除namespace下的全部pod时,其实走的还是一个一个删,可以从日志中看到:

  1. [root@master ~]# kubectl get pod -n cicd -owide
  2. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  3. b1-1-c8477796f-rnz4w 0/1 CrashLoopBackOff 1 5m26s 10.100.219.77 master <none> <none>
  4. b1-10-5bb56df9d7-gsgwt 0/1 CrashLoopBackOff 1 5m26s 10.100.219.110 master <none> <none>
  5. b1-11-bd4ffb6cc-dglgz 0/1 CrashLoopBackOff 1 5m26s 10.100.219.89 master <none> <none>
  6. b1-2-649c5c8b6f-f7jh2 0/1 CrashLoopBackOff 1 5m26s 10.100.219.112 master <none> <none>
  7. b1-3-57f47c8dc7-6mgpp 0/1 CrashLoopBackOff 1 5m26s 10.100.219.95 master <none> <none>
  8. b1-4-5bbfcc49d5-7zpx6 0/1 Completed 0 5m26s 10.100.219.70 master <none> <none>
  9. b1-5-76b54754df-nd5r4 0/1 CrashLoopBackOff 1 5m26s 10.100.219.113 master <none> <none>
  10. b1-6-5b7d8c6577-v797b 0/1 Completed 0 5m26s 10.100.219.87 master <none> <none>
  11. b1-8-844477c99c-47xw9 0/1 Completed 0 5m26s 10.100.219.83 master <none> <none>
  12. b1-9-789d4ddb77-8lwzd 0/1 CrashLoopBackOff 1 5m26s 10.100.219.111 master <none> <none>
  13. busybox-a-86b6df6fb9-k8nhq 0/1 Completed 0 5m25s 10.100.219.71 master <none> <none>
  14. [root@master ~]# kubectl delete pod -n cicd --all --v=7
  15. I0815 22:26:24.013473 26739 loader.go:375] Config loaded from file: /root/.kube/config
  16. I0815 22:26:24.015065 26739 round_trippers.go:420] GET https://172.21.0.15:6443/apis/middleware.hc.middleware/v1alpha1?timeout=32s
  17. I0815 22:26:24.015078 26739 round_trippers.go:427] Request Headers:
  18. I0815 22:26:24.015084 26739 round_trippers.go:431] Accept: application/json, */*
  19. I0815 22:26:24.015089 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  20. I0815 22:26:24.022127 26739 round_trippers.go:446] Response Status: 503 Service Unavailable in 7 milliseconds
  21. I0815 22:26:24.030746 26739 request.go:1171] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
  22. I0815 22:26:24.030766 26739 cached_discovery.go:78] skipped caching discovery info due to the server is currently unable to handle the request
  23. I0815 22:26:24.031703 26739 round_trippers.go:420] GET https://172.21.0.15:6443/apis/middleware.hc.middleware/v1alpha1?timeout=32s
  24. I0815 22:26:24.031717 26739 round_trippers.go:427] Request Headers:
  25. I0815 22:26:24.031723 26739 round_trippers.go:431] Accept: application/json, */*
  26. I0815 22:26:24.031727 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  27. I0815 22:26:24.032463 26739 round_trippers.go:446] Response Status: 503 Service Unavailable in 0 milliseconds
  28. I0815 22:26:24.039493 26739 request.go:1171] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
  29. I0815 22:26:24.039511 26739 cached_discovery.go:78] skipped caching discovery info due to the server is currently unable to handle the request
  30. I0815 22:26:24.039547 26739 shortcut.go:89] Error loading discovery information: unable to retrieve the complete list of server APIs: middleware.hc.middleware/v1alpha1: the server is currently unable to handle the request
  31. I0815 22:26:24.040969 26739 round_trippers.go:420] GET https://172.21.0.15:6443/apis/middleware.hc.middleware/v1alpha1?timeout=32s
  32. I0815 22:26:24.041021 26739 round_trippers.go:427] Request Headers:
  33. I0815 22:26:24.041040 26739 round_trippers.go:431] Accept: application/json, */*
  34. I0815 22:26:24.041049 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  35. I0815 22:26:24.042800 26739 round_trippers.go:446] Response Status: 503 Service Unavailable in 1 milliseconds
  36. I0815 22:26:24.050095 26739 request.go:1171] body was not decodable (unable to check for Status): couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" }
  37. I0815 22:26:24.050111 26739 cached_discovery.go:78] skipped caching discovery info due to the server is currently unable to handle the request
  38. I0815 22:26:24.051372 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods
  39. I0815 22:26:24.051388 26739 round_trippers.go:427] Request Headers:
  40. I0815 22:26:24.051397 26739 round_trippers.go:431] Accept: application/json
  41. I0815 22:26:24.051405 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  42. I0815 22:26:24.053545 26739 round_trippers.go:446] Response Status: 200 OK in 2 milliseconds
  43. I0815 22:26:24.057180 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-1-c8477796f-rnz4w
  44. I0815 22:26:24.057196 26739 round_trippers.go:427] Request Headers:
  45. I0815 22:26:24.057202 26739 round_trippers.go:431] Accept: application/json
  46. I0815 22:26:24.057206 26739 round_trippers.go:431] Content-Type: application/json
  47. I0815 22:26:24.057211 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  48. I0815 22:26:24.063420 26739 round_trippers.go:446] Response Status: 200 OK in 6 milliseconds
  49. pod "b1-1-c8477796f-rnz4w" deleted
  50. I0815 22:26:24.063851 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-10-5bb56df9d7-gsgwt
  51. I0815 22:26:24.063858 26739 round_trippers.go:427] Request Headers:
  52. I0815 22:26:24.063863 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  53. I0815 22:26:24.063868 26739 round_trippers.go:431] Accept: application/json
  54. I0815 22:26:24.063872 26739 round_trippers.go:431] Content-Type: application/json
  55. I0815 22:26:24.070894 26739 round_trippers.go:446] Response Status: 200 OK in 7 milliseconds
  56. pod "b1-10-5bb56df9d7-gsgwt" deleted
  57. I0815 22:26:24.071311 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-11-bd4ffb6cc-dglgz
  58. I0815 22:26:24.071318 26739 round_trippers.go:427] Request Headers:
  59. I0815 22:26:24.071323 26739 round_trippers.go:431] Accept: application/json
  60. I0815 22:26:24.071328 26739 round_trippers.go:431] Content-Type: application/json
  61. I0815 22:26:24.071332 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  62. I0815 22:26:24.086686 26739 round_trippers.go:446] Response Status: 200 OK in 15 milliseconds
  63. pod "b1-11-bd4ffb6cc-dglgz" deleted
  64. I0815 22:26:24.087133 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-2-649c5c8b6f-f7jh2
  65. I0815 22:26:24.087140 26739 round_trippers.go:427] Request Headers:
  66. I0815 22:26:24.087145 26739 round_trippers.go:431] Content-Type: application/json
  67. I0815 22:26:24.087150 26739 round_trippers.go:431] Accept: application/json
  68. I0815 22:26:24.087154 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  69. I0815 22:26:24.114167 26739 round_trippers.go:446] Response Status: 200 OK in 26 milliseconds
  70. pod "b1-2-649c5c8b6f-f7jh2" deleted
  71. I0815 22:26:24.114676 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-3-57f47c8dc7-6mgpp
  72. I0815 22:26:24.114684 26739 round_trippers.go:427] Request Headers:
  73. I0815 22:26:24.114689 26739 round_trippers.go:431] Accept: application/json
  74. I0815 22:26:24.114694 26739 round_trippers.go:431] Content-Type: application/json
  75. I0815 22:26:24.114699 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  76. I0815 22:26:24.140298 26739 round_trippers.go:446] Response Status: 200 OK in 25 milliseconds
  77. pod "b1-3-57f47c8dc7-6mgpp" deleted
  78. I0815 22:26:24.140787 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-4-5bbfcc49d5-7zpx6
  79. I0815 22:26:24.140795 26739 round_trippers.go:427] Request Headers:
  80. I0815 22:26:24.140801 26739 round_trippers.go:431] Accept: application/json
  81. I0815 22:26:24.140806 26739 round_trippers.go:431] Content-Type: application/json
  82. I0815 22:26:24.140810 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  83. I0815 22:26:24.175724 26739 round_trippers.go:446] Response Status: 200 OK in 34 milliseconds
  84. pod "b1-4-5bbfcc49d5-7zpx6" deleted
  85. I0815 22:26:24.176215 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-5-76b54754df-nd5r4
  86. I0815 22:26:24.176223 26739 round_trippers.go:427] Request Headers:
  87. I0815 22:26:24.176228 26739 round_trippers.go:431] Accept: application/json
  88. I0815 22:26:24.176233 26739 round_trippers.go:431] Content-Type: application/json
  89. I0815 22:26:24.176237 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  90. I0815 22:26:24.199651 26739 round_trippers.go:446] Response Status: 200 OK in 23 milliseconds
  91. pod "b1-5-76b54754df-nd5r4" deleted
  92. I0815 22:26:24.200156 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-6-5b7d8c6577-v797b
  93. I0815 22:26:24.200163 26739 round_trippers.go:427] Request Headers:
  94. I0815 22:26:24.200169 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  95. I0815 22:26:24.200174 26739 round_trippers.go:431] Content-Type: application/json
  96. I0815 22:26:24.200178 26739 round_trippers.go:431] Accept: application/json
  97. I0815 22:26:24.215455 26739 round_trippers.go:446] Response Status: 200 OK in 15 milliseconds
  98. pod "b1-6-5b7d8c6577-v797b" deleted
  99. I0815 22:26:24.221410 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-8-844477c99c-47xw9
  100. I0815 22:26:24.221433 26739 round_trippers.go:427] Request Headers:
  101. I0815 22:26:24.221439 26739 round_trippers.go:431] Accept: application/json
  102. I0815 22:26:24.221445 26739 round_trippers.go:431] Content-Type: application/json
  103. I0815 22:26:24.221450 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  104. I0815 22:26:24.228376 26739 round_trippers.go:446] Response Status: 200 OK in 6 milliseconds
  105. pod "b1-8-844477c99c-47xw9" deleted
  106. I0815 22:26:24.228881 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/b1-9-789d4ddb77-8lwzd
  107. I0815 22:26:24.228894 26739 round_trippers.go:427] Request Headers:
  108. I0815 22:26:24.228899 26739 round_trippers.go:431] Accept: application/json
  109. I0815 22:26:24.228904 26739 round_trippers.go:431] Content-Type: application/json
  110. I0815 22:26:24.228908 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  111. I0815 22:26:24.239194 26739 round_trippers.go:446] Response Status: 200 OK in 10 milliseconds
  112. pod "b1-9-789d4ddb77-8lwzd" deleted
  113. I0815 22:26:24.239701 26739 round_trippers.go:420] DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods/busybox-a-86b6df6fb9-k8nhq
  114. I0815 22:26:24.239708 26739 round_trippers.go:427] Request Headers:
  115. I0815 22:26:24.239714 26739 round_trippers.go:431] Content-Type: application/json
  116. I0815 22:26:24.239719 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  117. I0815 22:26:24.239723 26739 round_trippers.go:431] Accept: application/json
  118. I0815 22:26:24.245485 26739 round_trippers.go:446] Response Status: 200 OK in 5 milliseconds
  119. pod "busybox-a-86b6df6fb9-k8nhq" deleted
  120. I0815 22:26:24.245752 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-1-c8477796f-rnz4w
  121. I0815 22:26:24.245758 26739 round_trippers.go:427] Request Headers:
  122. I0815 22:26:24.245764 26739 round_trippers.go:431] Accept: application/json
  123. I0815 22:26:24.245768 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  124. I0815 22:26:24.250632 26739 round_trippers.go:446] Response Status: 200 OK in 4 milliseconds
  125. I0815 22:26:24.251035 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-1-c8477796f-rnz4w&resourceVersion=29591860&watch=true
  126. I0815 22:26:24.251049 26739 round_trippers.go:427] Request Headers:
  127. I0815 22:26:24.251056 26739 round_trippers.go:431] Accept: application/json
  128. I0815 22:26:24.251064 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  129. I0815 22:26:24.251773 26739 round_trippers.go:446] Response Status: 200 OK in 0 milliseconds
  130. I0815 22:26:32.882791 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-10-5bb56df9d7-gsgwt
  131. I0815 22:26:32.882809 26739 round_trippers.go:427] Request Headers:
  132. I0815 22:26:32.882817 26739 round_trippers.go:431] Accept: application/json
  133. I0815 22:26:32.882824 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  134. I0815 22:26:32.887905 26739 round_trippers.go:446] Response Status: 200 OK in 5 milliseconds
  135. I0815 22:26:32.888319 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-10-5bb56df9d7-gsgwt&resourceVersion=29592026&watch=true
  136. I0815 22:26:32.888330 26739 round_trippers.go:427] Request Headers:
  137. I0815 22:26:32.888336 26739 round_trippers.go:431] Accept: application/json
  138. I0815 22:26:32.888344 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  139. I0815 22:26:32.892324 26739 round_trippers.go:446] Response Status: 200 OK in 3 milliseconds
  140. I0815 22:26:34.082259 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-11-bd4ffb6cc-dglgz
  141. I0815 22:26:34.082279 26739 round_trippers.go:427] Request Headers:
  142. I0815 22:26:34.082286 26739 round_trippers.go:431] Accept: application/json
  143. I0815 22:26:34.082291 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  144. I0815 22:26:34.084077 26739 round_trippers.go:446] Response Status: 200 OK in 1 milliseconds
  145. I0815 22:26:34.084214 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-2-649c5c8b6f-f7jh2
  146. I0815 22:26:34.084224 26739 round_trippers.go:427] Request Headers:
  147. I0815 22:26:34.084229 26739 round_trippers.go:431] Accept: application/json
  148. I0815 22:26:34.084234 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  149. I0815 22:26:34.088244 26739 round_trippers.go:446] Response Status: 200 OK in 4 milliseconds
  150. I0815 22:26:34.088380 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-3-57f47c8dc7-6mgpp
  151. I0815 22:26:34.088388 26739 round_trippers.go:427] Request Headers:
  152. I0815 22:26:34.088396 26739 round_trippers.go:431] Accept: application/json
  153. I0815 22:26:34.088401 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  154. I0815 22:26:34.090553 26739 round_trippers.go:446] Response Status: 200 OK in 2 milliseconds
  155. I0815 22:26:34.090661 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-4-5bbfcc49d5-7zpx6
  156. I0815 22:26:34.090667 26739 round_trippers.go:427] Request Headers:
  157. I0815 22:26:34.090672 26739 round_trippers.go:431] Accept: application/json
  158. I0815 22:26:34.090677 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  159. I0815 22:26:34.094562 26739 round_trippers.go:446] Response Status: 200 OK in 3 milliseconds
  160. I0815 22:26:34.094667 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-5-76b54754df-nd5r4
  161. I0815 22:26:34.094673 26739 round_trippers.go:427] Request Headers:
  162. I0815 22:26:34.094678 26739 round_trippers.go:431] Accept: application/json
  163. I0815 22:26:34.094683 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  164. I0815 22:26:34.096260 26739 round_trippers.go:446] Response Status: 200 OK in 1 milliseconds
  165. I0815 22:26:34.096355 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-6-5b7d8c6577-v797b
  166. I0815 22:26:34.096361 26739 round_trippers.go:427] Request Headers:
  167. I0815 22:26:34.096366 26739 round_trippers.go:431] Accept: application/json
  168. I0815 22:26:34.096371 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  169. I0815 22:26:34.097290 26739 round_trippers.go:446] Response Status: 200 OK in 0 milliseconds
  170. I0815 22:26:34.097390 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-8-844477c99c-47xw9
  171. I0815 22:26:34.097396 26739 round_trippers.go:427] Request Headers:
  172. I0815 22:26:34.097401 26739 round_trippers.go:431] Accept: application/json
  173. I0815 22:26:34.097405 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  174. I0815 22:26:34.098371 26739 round_trippers.go:446] Response Status: 200 OK in 0 milliseconds
  175. I0815 22:26:34.098454 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-9-789d4ddb77-8lwzd
  176. I0815 22:26:34.098460 26739 round_trippers.go:427] Request Headers:
  177. I0815 22:26:34.098464 26739 round_trippers.go:431] Accept: application/json
  178. I0815 22:26:34.098469 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  179. I0815 22:26:34.102150 26739 round_trippers.go:446] Response Status: 200 OK in 3 milliseconds
  180. I0815 22:26:34.102565 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Db1-9-789d4ddb77-8lwzd&resourceVersion=29592032&watch=true
  181. I0815 22:26:34.102574 26739 round_trippers.go:427] Request Headers:
  182. I0815 22:26:34.102579 26739 round_trippers.go:431] Accept: application/json
  183. I0815 22:26:34.102584 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  184. I0815 22:26:34.103099 26739 round_trippers.go:446] Response Status: 200 OK in 0 milliseconds
  185. I0815 22:26:35.277055 26739 round_trippers.go:420] GET https://172.21.0.15:6443/api/v1/namespaces/cicd/pods?fieldSelector=metadata.name%3Dbusybox-a-86b6df6fb9-k8nhq
  186. I0815 22:26:35.277073 26739 round_trippers.go:427] Request Headers:
  187. I0815 22:26:35.277079 26739 round_trippers.go:431] Accept: application/json
  188. I0815 22:26:35.277083 26739 round_trippers.go:431] User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae
  189. I0815 22:26:35.282397 26739 round_trippers.go:446] Response Status: 200 OK in 5 milliseconds
  190. [root@master ~]#

所以,kube-APIServer中无批量删除Delete的日志:

[root@master ~]# kubectl logs  -n kube-system kube-apiserver-master | grep Delete
[root@master ~]# kubectl logs  -n kube-system kube-apiserver-master | grep cicd
[root@master ~]#

image.png

go程序测试

pod总数:

[root@master test]# kubectl get pod -n cicd |  wc -l
2011

go.mod


module k8s.io/test

go 1.13

require (
    github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
    github.com/imdario/mergo v0.3.11 // indirect
    golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
    golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
    k8s.io/apimachinery v0.17.3
    k8s.io/apiserver v0.17.3 // indirect
    k8s.io/client-go v0.17.3
)

main.go

package main

import (
    "flag"
    "github.com/golang/glog"
    metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    clientset "k8s.io/client-go/kubernetes"
    restclient "k8s.io/client-go/rest"
    "k8s.io/client-go/tools/clientcmd"
)
func main() {
    flag.Parse()
    defer glog.Flush()

    glog.Infof("aaaa")

    clients, err := createClients()
    if err != nil {
        glog.Fatalf("create client err: %v", err)
    }

    err = clients.CoreV1().Pods("cicd").DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{})
    if err != nil {
        glog.Fatalf("delete pod err:", err)
    }
}

type Arg struct {
    Master string
    KubeConfig string
}

func createClients() (*clientset.Clientset, error) {
    kubeconfig, err := clientcmd.BuildConfigFromFlags("", "/root/.kube/config")
    if err != nil {
        return nil, err
    }

    //controller-manager的类型为"application/vnd.kubernetes.protobuf"但在这里有问题,导致同步事件AddFunc、UpdateFunc、delFunc出问题,
    // 不能加,后续细细研究,
    //kubeconfig.ContentConfig.ContentType = s.ContentType
    // Override kubeconfig qps/burst settings from flags
    kubeconfig.QPS = 20
    kubeconfig.Burst = 30
    kubeClient, err := clientset.NewForConfig(restclient.AddUserAgent(kubeconfig, "operator-manager"))
    if err != nil {
        glog.Fatalf("Invalid API configuration: %v", err)
    }
    return kubeClient, nil
}
[root@master test]# kubectl get pod -n cicd | wc -l
2011
[root@master test]#
[root@master test]# go mod vendor
[root@master test]# go build -a -o main
[root@master test]# 
[root@master test]# ll
total 35652
-rw-r--r-- 1 root root      381 Aug 16 08:53 go.mod
-rw-r--r-- 1 root root    33529 Aug 16 08:53 go.sum
-rwxr-xr-x 1 root root 36453104 Aug 16 08:53 main
-rw-r--r-- 1 root root     1313 Aug 16 08:39 main.go
drwxr-xr-x 8 root root     4096 Aug 16 08:39 vendor
[root@master test]# ./main 
F0816 08:54:29.073082    7355 main.go:24] delete pod err:%!(EXTRA *errors.StatusError=Timeout: request did not complete within requested timeout 30s)
goroutine 1 [running]:
github.com/golang/glog.stacks(0xc000268600, 0xc0003f2000, 0x96, 0xeb)
    /root/gopath/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:769 +0xb8
github.com/golang/glog.(*loggingT).output(0x1da49e0, 0xc000000003, 0xc00023ecb0, 0x1d1f369, 0x7, 0x18, 0x0)
    /root/gopath/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:720 +0x372
github.com/golang/glog.(*loggingT).printf(0x1da49e0, 0xc000000003, 0x1327418, 0xf, 0xc0000dff30, 0x1, 0x1)
    /root/gopath/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:655 +0x14b
github.com/golang/glog.Fatalf(...)
    /root/gopath/pkg/mod/github.com/golang/glog@v0.0.0-20160126235308-23def4e6c14b/glog.go:1148
main.main()
    /root/gopath/src/k8s.io/test/main.go:24 +0x2af

执行后,可以看到APIServer中有如下日志:

[root@master test]# kubectl logs -f -n kube-system kube-apiserver-master | grep Delete
I0816 00:54:29.072293       1 trace.go:116] Trace[789103800]: "Delete" url:/api/v1/namespaces/cicd/pods (started: 2020-08-16 00:53:59.071909387 +0000 UTC m=+5740361.632700959) (total time: 30.000366126s):

curl模拟

pod总数:

[root@master test]# kubectl get pod -n cicd |  wc -l
2011

模拟:

[root@master test]# curl -k -X DELETE https://172.21.0.15:6443/api/v1/namespaces/cicd/pods
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "Timeout: request did not complete within requested timeout 30s",
  "reason": "Timeout",
  "details": {

  },
  "code": 504
}[root@master test]#kubectl logs  -n kube-system kube-apiserver-master | grep Deletes
^C
[root@master test]# kubectl logs  -n kube-system kube-apiserver-master | grep Delete
I0816 00:54:29.072293       1 trace.go:116] Trace[789103800]: "Delete" url:/api/v1/namespaces/cicd/pods (started: 2020-08-16 00:53:59.071909387 +0000 UTC m=+5740361.632700959) (total time: 30.000366126s):
I0816 01:01:28.789859       1 trace.go:116] Trace[1098869689]: "Delete" url:/api/v1/namespaces/cicd/pods (started: 2020-08-16 01:00:58.789571053 +0000 UTC m=+5740781.350362618) (total time: 30.000266058s):
[root@master test]#

初步结论

APIServer中的日志,在请求超过一定时间才会记录Trace日志。