apps-review.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. ---
  2. # Prepares the environment for the apps-placement exercise, and cleans up afterwards.
  3. #
  4. # TODO: create some projects:
  5. # - one with a project node selector
  6. # and a deployment with conflicting node {selector|affinity} ???
  7. # - one with a very low quota
  8. # and a deployment which exceeds the quota
  9. # - taint a node
  10. # and select a deployment to run a pod on it
  11. # then debug these conditions and fix them
  12. #
  13. # TODO: make two nodes unschedulable, create a project, and deploy an application, scale to three
  14. # make the nodes schedulable again, use podAntiAffinity to disperse the pods, scale to 6 and see scheduling
  15. #
  16. # simulate load (loadtest? loadgenerator?) beyond container's cpu limit and then improve performance by raising limit
  17. #
  18. # TODO: probes with extremely low cpu limit, see them crashloop, fix it
  19. #
  20. # use stress-ng ap to allocate all memory (more than limit), monitor the metrics to diagnose the crash
  21. #
  22. # client-server apps, low limits, monitor performance
  23. #
  24. # custom metrics, grafana
  25. #
  26. # TODO: run two instances on the same node, no pdb, drain the node - observe failure in another terminal
  27. # repeat with pdb, see no failures
  28. #
  29. # recreate strategy, rollout a change, observe outage in another terminal
  30. # switch to rolling w/maxUnavailable, repeat, see no failures
  31. #
  32. # deploy an app w/requests, generate load, observe timing
  33. # add HPA, generate load, compare
  34. #
  35. - name: Prepare (or clean up) the exercise of apps-placement.
  36. hosts: localhost
  37. gather_subset: min
  38. become: no
  39. tasks:
  40. - name: Prereqs
  41. include_role:
  42. name: check-env
  43. - name: Ensure the projects are there
  44. kubernetes.core.k8s:
  45. kubeconfig: tmp/kubeconfig-ocp4
  46. validate_certs: no
  47. api_version: v1
  48. kind: namespace
  49. name: "{{ item.name }}"
  50. resource_definition:
  51. metadata:
  52. annotations:
  53. openshift.io/node-selector: "{{ item.nodeselector | default(omit) }}"
  54. loop:
  55. - name: apps-selector-conflict
  56. nodeselector: kubernetes.io/hostname=worker03
  57. - name: apps-selector-impossible
  58. - name: apps-lowquota
  59. - name: apps-taint
  60. - name: apps-antiaffinity
  61. #- name: apps-lowlimit
  62. - name: apps-pdb
  63. - name: Deployment conflicting node selector
  64. kubernetes.core.k8s:
  65. kubeconfig: tmp/kubeconfig-ocp4
  66. validate_certs: no
  67. api_version: apps/v1
  68. kind: deployment
  69. namespace: apps-selector-conflict
  70. name: conflict
  71. resource_definition:
  72. spec:
  73. replicas: 3
  74. selector:
  75. matchLabels:
  76. app: hello
  77. template:
  78. metadata:
  79. labels:
  80. app: hello
  81. spec:
  82. nodeSelector:
  83. kubernetes.io/hostname: worker01
  84. containers:
  85. - name: hello
  86. image: quay.io/redhattraining/hello-world-nginx:latest
  87. ports:
  88. - name: http
  89. containerPort: 8080
  90. - name: Deployment with an impossible node selector
  91. kubernetes.core.k8s:
  92. kubeconfig: tmp/kubeconfig-ocp4
  93. validate_certs: no
  94. api_version: apps/v1
  95. kind: deployment
  96. namespace: apps-selector-impossible
  97. name: select
  98. resource_definition:
  99. spec:
  100. replicas: 3
  101. selector:
  102. matchLabels:
  103. app: hello
  104. template:
  105. metadata:
  106. labels:
  107. app: hello
  108. spec:
  109. nodeSelector:
  110. impossible: nodelabel
  111. containers:
  112. - name: hello
  113. image: quay.io/redhattraining/hello-world-nginx:latest
  114. ports:
  115. - name: http
  116. containerPort: 8080
  117. - name: Ensure low quota on the lowquota project
  118. kubernetes.core.k8s:
  119. kubeconfig: tmp/kubeconfig-ocp4
  120. validate_certs: no
  121. api_version: v1
  122. kind: resourcequota
  123. resource_definition:
  124. metadata:
  125. name: compute-quota
  126. namespace: apps-lowquota
  127. spec:
  128. hard:
  129. requests.cpu: 500m
  130. requests.memory: 512Mi
  131. limits.cpu: 1000m
  132. limits.memory: 1Gi
  133. - name: Deployment exceeding quota
  134. kubernetes.core.k8s:
  135. kubeconfig: tmp/kubeconfig-ocp4
  136. validate_certs: no
  137. api_version: apps/v1
  138. kind: deployment
  139. namespace: apps-lowquota
  140. name: quota
  141. resource_definition:
  142. spec:
  143. replicas: 3
  144. selector:
  145. matchLabels:
  146. app: hello
  147. template:
  148. metadata:
  149. labels:
  150. app: hello
  151. spec:
  152. containers:
  153. - name: hello
  154. image: quay.io/redhattraining/hello-world-nginx:latest
  155. ports:
  156. - name: http
  157. containerPort: 8080
  158. resources:
  159. requests:
  160. memory: 1Gi
  161. cpu: 2
  162. - name: Taint a node
  163. kubernetes.core.k8s:
  164. kubeconfig: tmp/kubeconfig-ocp4
  165. validate_certs: no
  166. api_version: v1
  167. kind: node
  168. name: worker01
  169. state: patched
  170. resource_definition:
  171. spec:
  172. taints:
  173. - effect: NoSchedule
  174. key: foo
  175. value: bar
  176. - name: Deployment targetting tainted node
  177. kubernetes.core.k8s:
  178. kubeconfig: tmp/kubeconfig-ocp4
  179. validate_certs: no
  180. api_version: apps/v1
  181. kind: deployment
  182. namespace: apps-taint
  183. name: tainted
  184. resource_definition:
  185. spec:
  186. replicas: 3
  187. selector:
  188. matchLabels:
  189. app: hello
  190. template:
  191. metadata:
  192. labels:
  193. app: hello
  194. spec:
  195. nodeSelector:
  196. kubernetes.io/hostname: worker01
  197. containers:
  198. - name: hello
  199. image: quay.io/redhattraining/hello-world-nginx:latest
  200. ports:
  201. - name: http
  202. containerPort: 8080
  203. - name: Make nodes unschedulable
  204. kubernetes.core.k8s:
  205. kubeconfig: tmp/kubeconfig-ocp4
  206. validate_certs: no
  207. api_version: v1
  208. kind: node
  209. name: "{{ item }}"
  210. state: patched
  211. resource_definition:
  212. spec:
  213. unschedulable: true
  214. loop:
  215. - worker01
  216. - worker02
  217. - name: Deployment on the only available node, to be preferred
  218. kubernetes.core.k8s:
  219. kubeconfig: tmp/kubeconfig-ocp4
  220. validate_certs: no
  221. api_version: apps/v1
  222. kind: deployment
  223. namespace: apps-antiaffinity
  224. name: dislike
  225. resource_definition:
  226. spec:
  227. replicas: 3
  228. selector:
  229. matchLabels:
  230. app: dislike
  231. template:
  232. metadata:
  233. labels:
  234. app: dislike
  235. spec:
  236. #affinity:
  237. # podAntiAffinity:
  238. # preferredDuringSchedulingIgnoredDuringExecution:
  239. # - weight: 10
  240. # podAffinityTerm:
  241. # labelSelector:
  242. # matchLabels:
  243. # app: dislike
  244. # topologyKey: kubernetes.io/hostname
  245. containers:
  246. - name: hello
  247. image: quay.io/redhattraining/hello-world-nginx:latest
  248. ports:
  249. - name: http
  250. containerPort: 8080
  251. - name: Deployment on the only available node, to be required
  252. kubernetes.core.k8s:
  253. kubeconfig: tmp/kubeconfig-ocp4
  254. validate_certs: no
  255. api_version: apps/v1
  256. kind: deployment
  257. namespace: apps-antiaffinity
  258. name: refuse
  259. resource_definition:
  260. spec:
  261. replicas: 3
  262. selector:
  263. matchLabels:
  264. app: refuse
  265. template:
  266. metadata:
  267. labels:
  268. app: refuse
  269. spec:
  270. #affinity:
  271. # podAntiAffinity:
  272. # requiredDuringSchedulingIgnoredDuringExecution:
  273. # labelSelector:
  274. # matchLabels:
  275. # app: refuse
  276. # topologyKey: kubernetes.io/hostname
  277. containers:
  278. - name: hello
  279. image: quay.io/redhattraining/hello-world-nginx:latest
  280. ports:
  281. - name: http
  282. containerPort: 8080
  283. - name: Make nodes schedulable again
  284. kubernetes.core.k8s:
  285. kubeconfig: tmp/kubeconfig-ocp4
  286. validate_certs: no
  287. api_version: v1
  288. kind: node
  289. name: "{{ item }}"
  290. state: patched
  291. resource_definition:
  292. spec:
  293. unschedulable: false
  294. loop:
  295. - worker01
  296. - worker02
  297. - name: Deployment on the same node for PDB
  298. kubernetes.core.k8s:
  299. kubeconfig: tmp/kubeconfig-ocp4
  300. validate_certs: no
  301. api_version: apps/v1
  302. kind: deployment
  303. namespace: apps-pdb
  304. name: budget
  305. resource_definition:
  306. spec:
  307. replicas: 2
  308. selector:
  309. matchLabels:
  310. app: hello
  311. template:
  312. metadata:
  313. labels:
  314. app: hello
  315. spec:
  316. affinity:
  317. nodeAffinity:
  318. preferredDuringSchedulingIgnoredDuringExecution:
  319. - preference:
  320. matchExpressions:
  321. - key: kubernetes.io/hostname
  322. operator: In
  323. values:
  324. - worker02
  325. weight: 50
  326. containers:
  327. - name: hello
  328. image: quay.io/redhattraining/hello-world-nginx:latest
  329. ports:
  330. - name: http
  331. containerPort: 8080
  332. ...