sandervanvugt

CKA oct 21 day2

Oct 20th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.07 KB | None | 0 0
  1. ON 3-NODE CLUSTER
  2. student@control:~$ history
  3. 1 kubectl create deploy nginx --image=nginx --dry-run -o yaml | sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml
  4. 2 vim nginx-ds.yaml
  5. 3 kubectl get ds
  6. 4 kubectl delete ds nginx-ds
  7. 5 kubectl create -f nginx-ds.yaml
  8. 6 kubectl delete -f nginx-ds.yaml
  9. 7 cd cka/
  10. 8 vim wg2.yaml
  11. 9 exit
  12. 10 sudo vim /etc/hosts
  13. 11 cat /etc/hosts
  14. 12 sudo apt install vim git bash-completion -y
  15. 13 git clone https://github.com/sandervanvugt/cka
  16. 14 cd cka
  17. 15 ls
  18. 16 vim setup-container.sh
  19. 17 ./setup-container.sh
  20. 18 ls
  21. 19 vim setup-kubetools.sh
  22. 20 vim setup-kubetools-ubuntu.sh
  23. 21 ./setup-kubetools-ubuntu.sh
  24. 22 history
  25. 23 cat /etc/hosts
  26. 24 sudo kubeadm init --help
  27. 25 sudo kubeadm init --pod-network-cidr=10.10.0.0/16
  28. 26 mkdir -p $HOME/.kube
  29. 27 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  30. 28 sudo chown $(id -u):$(id -g) $HOME/.kube/config
  31. 29 kubectl get all
  32. 30 kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
  33. 31 kubectl get nodes
  34. 32 kubectl create testginx --image=nginx --replicas=3
  35. 33 kubectl create deploy testginx --image=nginx --replicas=3
  36. 34 kubectl get all
  37. 35 ls
  38. 36 history
  39. 37 ls
  40. 38 ./counter.sh 15
  41. 39 kubectl completion -h
  42. 40 source <(kubectl completion bash)
  43. 41 kubectl create namespace mynamespace
  44. 42 kubectl get ns
  45. 43 kubectl run mypod --image=alpine -n mynamespace -- sleep 3600
  46. 44 kubectl get pods mypod -n mynamespace -o yaml | less
  47. 45 history
  48. 46 ./counter.sh 15
  49. 47 vim wg.yaml
  50. 48 kubectl apply -f wg.yaml
  51. 49 kubectl get all
  52. 50 kubectl describe pod myapp-pod
  53. 51 history
  54. 52 ./counter.sh
  55. 53 vim nrv.yaml
  56. 54 kubectl apply -f nrv.yaml
  57. 55 kubectl get pods
  58. 56 kubectl describe pod ex3
  59. 57 kubectl delete pod ex3
  60. 58 ls -lrt
  61. 59 vim nrv.yaml
  62. 60 kubectl run busybox --image=busybox --dry-run=client -o yaml -- sleep 3600
  63. 61 vim aj.yaml
  64. 62 kubectl create -f aj.yaml
  65. 63 kubectl delete -f aj.yaml
  66. 64 kubectl create -f aj.yaml
  67. 65 kubectl get pods
  68. 66 kubectl describe myapp-pod
  69. 67 kubectl describe pod myapp-pod
  70. 68 kubectl logs myapp-pod
  71. 69 kubectl describe pod myapp-pod
  72. 70 ./counter.sh 5
  73. 71 vim wg2.yaml
  74. 72 kubectl create -f wg2.yaml
  75. 73 kubectl get all
  76. 74 kubectl get pod -o wide
  77. 75 vim svv.yaml
  78. 76 kubectl create -f svv.yaml
  79. 77 kubectl create deploy nginx --image=nginx --dry-run -o yaml | \ sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml kubectl apply -f nginx-ds.yaml
  80. 78 sudo apt install sed
  81. 79 kubectl create deploy nginx --image=nginx --dry-run -o yaml | \ sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml kubectl apply -f nginx-ds.yaml
  82. 80 kubectl create deploy nginx --image=nginx --dry-run -o yaml > nginx-ds.yaml
  83. 81 vim nginx-ds.yaml
  84. 82 kubectl create -f nginx-ds.yaml
  85. 83 vim nginx-ds.yaml
  86. 84 kubectl create -f nginx-ds.yaml
  87. 85 ./counter.sh 25
  88. 86 kubectl create deploy nginx --image=nginx --dry-run -o yaml | sed '/null\|{}\|replicas/d;/status/,$d;s/Deployment/DaemonSet/g' > nginx-ds.yaml
  89. 87 vim nginx-ds.yaml
  90. 88 ls -lrt
  91. 89 vim ex18.yaml
  92. 90 cd /etc/kubernetes/
  93. 91 ls
  94. 92 cd manifests/
  95. 93 ls
  96. 94 vim kube-scheduler.yaml
  97. 95 sudo vim kube-scheduler.yaml
  98. 96 ssh worker1
  99. 97 cd
  100. 98 kubectl run auto-web --image=nginx --dry-run=client -o yaml > auto-web.yaml
  101. 99 cat auto-web.yaml
  102. 100 kubectl get pods -o wide
  103. 101 kubectl create ns limited
  104. 102 kubectl create quota --help
  105. 103 kubectl create quota qtest --hard pods=3,cpu=100,memory=500Mi -n limited
  106. 104 kubectl describe ns limited
  107. 105 kubectl create deploy nginx --image=nginx --replicas=3 -n limited
  108. 106 kubectl get all -n limited
  109. 107 kubectl describe -n limited rs nginx-6799fc88d8
  110. 108 kubectl get all -n limited
  111. 109 kubectl set resources -h | less
  112. 110 kubectl set resources deploy nginx --requests cpu=100m,memory=5Mi --limits cpu=200m,memory=20Mi -n limited
  113. 111 kubectl get all -n limited
  114. 112 kubectl scale deploy nginx --replicas=5 -n limited
  115. 113 kubectl get all -n limited
  116. 114 kubectl describe ns limited
  117. 115 kubectl describe -n limited rs nginx-86d467bc98
  118. 116 kubectl delete deploy nginx -n limited
  119. 117 kubectl set resources deploy nginx --limits cpu=200m,memory=1Mi -n limited
  120. 118 kubectl create deploy nginx
  121. 119 kubectl create deploy nginx --image=nginx -n limited
  122. 120 kubectl set resources deploy nginx --limits cpu=200m,memory=1Mi -n limited
  123. 121 kubectl get deploy nginx -n limited -o yaml > oom.yaml
  124. 122 kubectl delete deploy nginx
  125. 123 kubectl delete deploy nginx -n limited
  126. 124 vim oom.yaml
  127. 125 kubectl create -f oom.yaml
  128. 126 kubectl get all -n limited
  129. 127 kubectl describe -n limited pod nginx-566bfb9779-ll295
  130. 128 history
  131. 129 sleep 120; cka/counter.sh 13
  132. 130 kubectl get nodes
  133. 131 kubectl get pods -o wide
  134. 132 kubectl get nodes
  135. 133 kubectl describe node worker1
  136. 134 kubectl get pods
  137. 135 kubectl get nodes
  138. 136 cka/counter.sh 5
  139. 137 cd cka
  140. 138 ls
  141. 139 cd ..
  142. 140 git clone https://github.com/sandervanvugt/ckad
  143. 141 cd ckad
  144. 142 ls
  145. 143 vim pv.yaml
  146. 144 kubectl create -f pv.yaml
  147. 145 kubectl api-resources | less
  148. 146 vim pvc.yaml
  149. 147 kubectl create -f pvc.yaml
  150. 148 kubectl get pv
  151. 149 kubectl get storageclass
  152. 150 kubectl pv-pod.yaml
  153. 151 vim pv-pod.yaml
  154. 152 kubectl create -f pv-pod.yaml
  155. 153 kubectl exec -it pv-pod -- touch /usr/share/nginx/html/hello.txt
  156. 154 kubectl describe pv pv-volume
  157. 155 ls /
  158. 156 kubectl get pods -o wide
  159. 157 kubectl explain pv.spec | less
  160. 158 kubectl explain pv.spec.iscsi
  161. 159 kubectl explain pv.spec.initiatorName
  162. 160 kubectl explain pv.spec.iscsi
  163. 161 vim pvc.yaml
  164. 162 cat /etc/os-release
  165. 163 history
  166. 164 man signals
  167. 165 kubectl get nodes
  168. 166 kubectl label nodes worker2 disktype=ssd
  169. 167 cd ../cka
  170. 168 vim selector-pod.yaml
  171. 169 kubectl create -f selector-pod.yaml
  172. 170 kubectl get pods
  173. 171 kubectl describe pod nginx
  174. 172 kubectl delete po nginx
  175. 173 vim selector-pod.yaml
  176. 174 kubectl create -f selector-pod.yaml
  177. 175 kubectl get pods
  178. 176 kubectl tainint nodes worker1 example-key=value1:NoSchedule
  179. 177 kubectl taint nodes worker1 example-key=value1:NoSchedule
  180. 178 kubectl describe nodes worker1 | less
  181. 179 kubectl get pods -o wide
  182. 180 kubectl create deploy nginx-taint --image=nginx --replicas=3
  183. 181 kubectl get pods -o wide
  184. 182 vim taint-toleration.yaml
  185. 183 kubectl create -f taint-toleration.yaml
  186. 184 kubectl get pods -o wide
  187. 185 vim sc.txt
  188. 186 kubectl get nodes -o wide
  189. 187 kubectl describe nodes control
  190. 188 #kubectl taint node <nodename> node-role.kubernetes.io/master:NoSchedule-
  191. 189 kubectl edit control
  192. 190 kubectl edit node control
  193. 191 kubectl cordon --help
  194. 192 kubectl drain --help
  195. 193 kubectl drain worker2
  196. 194 kubectl get pods -o wide
  197. 195 kubectl drain worker2 --force --ignore-daemonsets
  198. 196 kubectl get pods -o wide
  199. 197 kubectl edit worker1
  200. 198 kubectl edit node worker1
  201. 199 kubectl get pods
  202. 200 kubectl describe pod testginx-6b7bbdbc9d-kt4db
  203. 201 kubectl get all
  204. 202 kubectl describe node worker1
  205. 203 kubectl describe node worker1 | grep taint
  206. 204 kubectl describe node worker1 | less
  207. 205 kubectl edit node worker1
  208. 206 kubectl get pods
  209. 207 kubectl describe ns default
  210. 208 kubectl get nodes
  211. 209 kubectl kubectl uncordon worker2
  212. 210 kubectl uncordon worker2
  213. 211 kubectl get pods
  214. 212 #ETCDCTL_API=3 etcdctl --endpoints 10.2.0.9:2379 \
  215. 213 #ETCDCTL_API=3 etcdctl --endpoints $ENDPOINT snapshot save snapshotdb
  216. 214 apt install etcd
  217. 215 sudo apt install etcd
  218. 216 etcdctl history
  219. 217 history
  220. 218 ps aux | grep 2379
  221. 219 ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /tmp/etcdbackup
  222. 220 sudo ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /tmp/etcdbackup
  223. 221 sudo ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /tmp/etcdback
  224. 222 mkdir -p /var/exam
  225. 223 sudo mkdir -p /var/exam
  226. 224 sudo cp /tmp/etcdback /var/exam
  227. 225 #sudo ETCDCTL_API=3 etcdctl --endpoints 127.0.0.1:2379 --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key --cacert=/etc/kubernetes/pki/etcd/ca.crt snapshot save /tmp/etcdback
  228. 226 ps aux | grep server.crt
  229. 227 ETCDCTL_API=3 etcdctl --help
  230. 228 ./counter.sh 12
  231. 229 vim ~/.kube/config
  232. 230 sudo useradd -G sudo anna
  233. 231 id
  234. 232 sudo passwd anna
  235. 233 su - anna
  236. 234 sudo userdel -r anna
  237. 235 sudo useradd -m -G sudo anna
  238. 236 sudo passwd anna
  239. 237 su - anna
  240. 238 vim podaccessrole.yaml
  241. 239 kubectl create -f podaccessrole.yaml
  242. 240 vim rolebinding.yaml
  243. 241 kubectl create -f rolebinding.yaml
  244. 242 kubectl run rolepod --image-=nginx
  245. 243 kubectl run rolepod --image=nginx
  246. 244 kubectl get pods
  247. 245 su - anna
  248. 246 kubectl auth can-i get pods --as anna
  249. 247 kubectl auth can-i get pods --as bob
  250. 248 ./counter.sh 27
  251. 249 kubectl top
  252. 250 kubectl top pod
  253. 251 git clone https://github.com/kubernetes-sigs/metrics-server
  254. 252 cd metrics-server/
  255. 253 ls
  256. 254 cd manifests/
  257. 255 ls
  258. 256 kubectl create -f base/
  259. 257 cd base
  260. 258 cd ..
  261. 259 kubectl delete -f manifests/base/
  262. 260 kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
  263. 261 kubectl -n kube-system get pods
  264. 262 kubectl -n kube-system edit deploy metrics-server
  265. 263 kubectl -n kube-system get pods
  266. 264 kubectl get pods
  267. 265 kubectl get pods -n kube-system
  268. 266 kubectl top pod
  269. 267 cd
  270. 268 kubectl get all -n kube-system
  271. 269 kubectl delete -n kube-system daemonset weave-net
  272. 270 kubectl get all -n kube-system
  273. 271 kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
  274. 272 wget https://docs.projectcalico.org/manifests/custom-resources.yaml
  275. 273 vim custom-resources.yaml
  276. 274 kubectl create -f custom-resources.yaml
  277. 275 kubectl get pods -n calico-system
  278. 276 kubectl get all -n calico-system
  279. 277 kubectl logs -n calico-system calico-node-bx9l2
  280. 278 kubectl create deploy testing --image=nginx --relicas=3
  281. 279 kubectl create deploy testing --image=nginx --replicas=3
  282. 280 kubectl get all
  283. 281 kubectl get all -o wide
  284. 282 kubectl get all -n calico-system
  285. 283 cd cka
  286. 284 vim nwpolicy-complete-example.yaml
  287. 285 kubectl apply -f nwpolicy-complete-example.yaml
  288. 286 kubectl expose pod nginx --port=80
  289. 287 kubectl describe svc nginx
  290. 288 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  291. 289 kubectl label pod busybox access=true
  292. 290 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  293. 291 kubectl get all -n calico-system
  294. 292 kubectl get pods -o wide
  295. 293 kubectl get svc
  296. 294 kubectl get pods -n kube-system
  297. 295 sudo reboot
  298. 296 kubectl get all -n calico-system
  299. 297 kubectl get all
  300. 298 sudo poweroff
  301. 299 history
  302. 300 sudo poweroff
  303. 301 history
  304.  
  305.  
  306. ON HA-CLUSTER
  307. student@haco1:~$ history
  308. 1 cd cka
  309. 2 ./setup-lb.sh
  310. 3 sudo vim /etc/hosts
  311. 4 vim setup-lb.sh
  312. 5 sudo vim /etc/hosts
  313. 6 ./setup-lb.sh
  314. 7 man read
  315. 8 read --help
  316. 9 vim setup-lb.sh
  317. 10 export --help
  318. 11 vim setup-lb.sh
  319. 12 ./setup-lb.sh
  320. 13 sudo vim /etc/hosts
  321. 14 vim setup-lb.sh
  322. 15 ./setup-lb.sh
  323. 16 vim setup-lb.sh
  324. 17 scp student@192.168.29.11:/home/student/setup-lb-ubuntu-alpha.sh .
  325. 18 scp student@192.168.29.11:/home/student/cka/setup-lb-ubuntu-alpha.sh .
  326. 19 chmod +x setup-lb*
  327. 20 vim setup-lb.sh
  328. 21 rm setup-lb.sh
  329. 22 exit
  330. 23 ip a
  331. 24 sudo vim /etc/hosts
  332. 25 for i in haco2 haco3 hawo1 hawo2; do scp /etc/hosts $1:/etc/; done
  333. 26 cat /etc/hosts
  334. 27 sudo apt install -y vim git bash-completion
  335. 28 git clone https://github.com/sandervanvugt/cka
  336. 29 cd cka
  337. 30 ls
  338. 31 ./setup-container.sh
  339. 32 ./setup-kubetools-ubuntu.sh
  340. 33 cat /etc/hosts
  341. 34 ./counter.sh 12
  342. 35 vim setup-lb.sh
  343. 36 vim keepalived.conf
  344. 37 vim setup-lb.sh
  345. 38 ls -l setup-lb.sh
  346. 39 ls -l setup-lb*
  347. 40 chmod +x setup-lb*
  348. 41 ./setup-lb-ubu-alpha.sh
  349. 42 vim setup-lb-ubu-alpha.sh
  350. 43 ./setup-lb-ubu-alpha.sh
  351. 44 ssh -t haco2 "sudo ls /root"
  352. 45 scp /etc/hosts haco2:/tmp && ssh -t haco2 "sudo cp /tmp/hosts /root"
  353. 46 ssh -t haco2 "sudo ls /root"
  354. 47 vim setup-lb-ubu-alpha.sh
  355. 48 vim setup-lb-ubu.sh
  356. 49 ls -lrt
  357. 50 vim setup-lb.sh
  358. 51 ./setup-lb.sh
  359. 52 vim setup-lb.sh
  360. 53 cp setup-lb.sh setup-lb-ubuntu-alpha.sh
  361. 54 ./counter.sh 3
  362. 55 vim nwp-lab11-1.yaml
  363. 56 vim nwp-lab11-2.yaml
  364. 57 ip a
  365. 58 vim setup-lb-ubuntu-alpha.sh
  366. 59 sudo kubeadm init --control-plane-endpoint "192.168.29.100:8443" --upload-certs
  367. 60 mkdir -p $HOME/.kube
  368. 61 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  369. 62 sudo chown student:student ~/.kube/config
  370. 63 kubectl get all
  371. 64 kubectl apply -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
  372. 65 wget https://docs.projectcalico.org/manifests/custom-resources.yaml
  373. 66 vim custom-resources.yaml
  374. 67 ps aux | grep kube-api
  375. 68 kubectl create -f custom-resources.yaml
  376. 69 kubectl get pods -n calico-system
  377. 70 kubectl get ns
  378. 71 kubectl get pods -n tigera-operator
  379. 72 kubectl get pods n kube-system
  380. 73 kubectl get pods -n kube-system
  381. 74 kubectl delete -f custom-resources.yaml
  382. 75 kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
  383. 76 kubectl get nodes
  384. 77 kubectl get pods
  385. 78 kubectl get nodes
  386. 79 cd
  387. 80 cd .kube/
  388. 81 vim config
  389. 82 cd
  390. 83 kubectl run busybox --rm -ti --image=busybox -- /bin/sh
  391. 84 kubectl get pods
  392.  
  393.  
  394. INTERACTIVE SCENARIOS (WILL BE PUBLISHED VERY SOON)
  395. https://learning.oreilly.com/scenarios/certified-kubernetes-cka/9780137836116X001/
  396. https://learning.oreilly.com/scenarios/certified-kubernetes-cka/9780137836116X002/
  397. https://learning.oreilly.com/scenarios/certified-kubernetes-cka/9780137836116X003/
  398. https://learning.oreilly.com/scenarios/certified-kubernetes-cka/9780137836116X004/
  399. https://learning.oreilly.com/scenarios/certified-kubernetes-cka/9780137836116X005/
Add Comment
Please, Sign In to add comment