sandervanvugt

CKA day2 jan22

Jan 14th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.38 KB | None | 0 0
  1. INSTALLING HA KUBERNETES CLUSTER
  2. ### AS ROOT
  3. 1 yum install -y git vim
  4. 2 ip a
  5. 3 ping nu.nl
  6. 4 ping 8.8.8.8
  7. 5 ip route show
  8. 6 ping nu.nl
  9. 7 vim /etc/hosts
  10. 8 yum install -y git vim
  11. 9 vim /etc/hosts
  12. 10 scp /etc/hosts control2:/etc/hosts
  13. 11 scp /etc/hosts control3:/etc/hosts
  14. 12 git clone https://github.com/sandervanvugt/cka
  15. 13 cd cka
  16. 14 ls *sh
  17. 15 ./setup-container.sh
  18. 16 ./setup-kubetools.sh
  19. 17 grep '4.100' *
  20. 18 vim check_apiserver.sh
  21. 19 vim keepalived.conf
  22. 20 ./setup-lb.sh
  23. 21 kubeadm init --control-plane-endpoint "192.168.29.100:8443" --upload-certs
  24. 22 vim /etc/hosts
  25. 23 scp /etc/hosts control3:/etc/hosts
  26. 24 scp /etc/hosts control2:/etc/hosts
  27. 25 vim /tmp/hatodo.txt
  28. 26 cat /tmp/hatodo.txt
  29. 27 history
  30. 28 cat /tmp/hatodo.txt
  31. 29 su - student
  32. 30 history
  33.  
  34. ### as non-root
  35. 1 mkdir .kube
  36. 2 cp -i /etc/kubernetes/admin.conf .kube/config
  37. 3 sudo cp -i /etc/kubernetes/admin.conf .kube/config
  38. 4 cat /tmp/hatodo.txt
  39. 5 sudo chown student:student .kube/config
  40. 6 ls -l .kube/config
  41. 7 kubectl get all
  42. 8 kubectl apply -f https://docs.projectcalico.org/latest/manifests/calico.yaml
  43. 9 cat /tmp/hatodo.txt
  44. 10 kubectl get nodes
  45. 11 sudo -i
  46. 12 exit
  47. 13 history
  48.  
  49. 1 mkdir .kube
  50. 2 cp -i /etc/kubernetes/admin.conf .kube/config
  51. 3 sudo cp -i /etc/kubernetes/admin.conf .kube/config
  52. 4 cat /tmp/hatodo.txt
  53. 5 sudo chown student:student .kube/config
  54. 6 ls -l .kube/config
  55. 7 kubectl get all
  56. 8 kubectl apply -f https://docs.projectcalico.org/latest/manifests/calico.yaml
  57. 9 cat /tmp/hatodo.txt
  58. 10 kubectl get nodes
  59. 11 sudo -i
  60. 12 exit
  61. 13 history
  62. 14 kubectl -h | less
  63. 15 kubectl top -h
  64. 16 kubectl top pod
  65. 17 kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases
  66. 18 vim components.yaml
  67. 19 kubectl create -f components.yaml
  68. 20 kubectl -n kube-system get pods
  69. 21 source <(kubectl completion bash)
  70. 22 sudo yum install -y bash-completion
  71. 23 source <(kubectl completion bash)
  72. 24 exit
  73. 25 kubectl get pods -n kube-system
  74. 26 kubectl logs metrics-server-6c49cf6978-8g6hr
  75. 27 kubectl logs metrics-server-6c49cf6978-8g6hr -n kube-system
  76. 28 kubectl -n kube-system edit deploy metrics-server
  77. 29 kubectl get pods -n kube-system
  78. 30 kubectl -n kube-system edit deploy metrics-server
  79. 31 kubectl top pods -A
  80. 32 history
  81. 33 ls
  82. 34 git clone https://github.com/sandervanvugt/cka
  83. 35 cka/counter.sh 13
  84. 36 kubectl get nodes
  85. 37 kube edit node control1.example.com
  86. 38 kubectl edit node control1.example.com
  87. 39 kubectl create myweb --image=nginx --replicas=3
  88. 40 kubectl create deploy myweb --image=nginx --replicas=3
  89. 41 kubectl get pods -o wide
  90. 42 kubectl edit node control2.example.com
  91. 43 kubectl edit node control3.example.com
  92. 44 cat /etc/redhat-release
  93. 45 history
  94. 46 ip a
  95. 47 kubectl get pods -n kube-system
  96. 48 cd cka
  97. 49 kubectl apply -f nwpolicy-complete-example.yaml
  98. 50 kubectl expose pod nginx --port-80
  99. 51 kubectl expose pod nginx --port=80
  100. 52 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  101. 53 kubectl get nwp -o yaml
  102. 54 kubectl get networkpolicy -o yaml
  103. 55 kubectl get pods --show-labels
  104. 56 kubectl label pod busybox access=true
  105. 57 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  106. 58 kubectl create ns nwp-namespace
  107. 59 vim nwp-lab11-1.yaml
  108. 60 kubectl create -f nwp-lab11-1.yaml
  109. 61 kubectl expose pod nwp-nginx --port=80
  110. 62 kubectl exec -it newp-busybox -n nwp-namespace -- wget --spider --timeout=1 nwp-nginx
  111. 63 kubectl exec -it nwp-busybox -n nwp-namespace -- wget --spider --timeout=1 nwp-nginx
  112. 64 kubectl exec -it nwp-busybox -n nwp-namespace -- nsloolup nwp-nginx
  113. 65 kubectl exec -it nwp-busybox -n nwp-namespace -- nslookup nwp-nginx
  114. 66 vim nwp-lab11-1.yaml
  115. 67 kubectl exec -it nwp-busybox -n nwp-namespace -- wget --spider --timeout=1 nwp-nginx.default.svc.cluster.local
  116. 68 vim nwp-lab11-2.yaml
  117. 69 kubectl create -f nwp-lab11-2.yaml
  118. 70 kubectl exec -it nwp-busybox -n nwp-namespace -- wget --spider --timeout=1 nwp-nginx.default.svc.cluster.local
  119. 71 kubectl create deploy busybox --image=busybox -- sleep 3600
  120. 72 kubectl get pods
  121. 73 kubectl exec -it busybox-669745485f-h8r88 -- wget --spider --timeout=1 nwp-nginx
  122. 74 history
  123.  
  124. ##### on the 3 node cluster
  125. student@control:~$ history
  126. 1 cat /etc/hosts
  127. 2 ip a
  128. 3 sudo apt install -y git vim
  129. 4 kubectl get pods -h | less
  130. 5 kubectl get pods -o wide --sort-by-.spec.nodeName
  131. 6 kubectl get pods -o wide --sort-by=.spec.nodeName
  132. 7 git clone https://github.com/sandervanvugt/cka
  133. 8 cd cka
  134. 9 ls *sh
  135. 10 vim setup-container.sh
  136. 11 ./setup-container.sh
  137. 12 ./setup-kubetools.sh
  138. 13 sudo ./setup-kubetools.sh
  139. 14 sudo vim /etc/fstab
  140. 15 sudo swapoff -a
  141. 16 free -m
  142. 17 sudo vim /etc/hosts
  143. 18 sudo -i
  144. 19 vim /tmp/todo.txt
  145. 20 top
  146. 21 cat /tmp/todo.txt
  147. 22 cd
  148. 23 mkdir -p .kube
  149. 24 sudo cp -i /etc/kubernetes/admin.conf .kube/config
  150. 25 sudo chown student:student .kube/config
  151. 26 kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
  152. 27 kubectl get all
  153. 28 kubectl get all -A
  154. 29 cat /tmp/todo.txt
  155. 30 kubectl get nodes
  156. 31 history
  157. 32 kubectl get nodes
  158. 33 history
  159. 34 cat /tmp/todo.txt
  160. 35 sudo kubeadm -h | less
  161. 36 history
  162. 37 cd cka
  163. 38 ls
  164. 39 history
  165. 40 kubectl get nodes
  166. 41 ./counter.sh 3
  167. 42 kubectl create ns mynamespace
  168. 43 kubectl run myalp --image=alpine -- sleep 3600 > myalp.yaml
  169. 44 vim myalp.yaml
  170. 45 kubectl run myalp --image=alpine -- sleep 3600 --dry-run=client -o yaml > myalp.yaml
  171. 46 kubectl delete pod myalp
  172. 47 kubectl run myalp --image=alpine --dry-run=client -o yaml -- sleep 3600
  173. 48 ./counter.sh 6
  174. 49 vim wk3.yaml
  175. 50 kubectl create -f wk3.yaml
  176. 51 kubectl get pods
  177. 52 kubectl describe pod exercise3
  178. 53 ./counter.sh 17
  179. 54 vim oinit.yaml
  180. 55 kubectl create -f oinit.yaml
  181. 56 kubectl get pods
  182. 57 kubectl describe pod init-demo
  183. 58 kubectl get pods -o wide
  184. 59 ./counter.sh 5
  185. 60 kubectl get nodes
  186. 61 kubectl edit node control
  187. 62 kubectl create deploy nginx --image=nginx --replicas=3
  188. 63 kubectl get pods -o wide
  189. 64 kubectl edit node control
  190. 65 kubectl get pods -o wide
  191. 66 kubectl completion -h
  192. 67 source <(kubectl completion bash)
  193. 68 kubectl scale deployment nginx --replicas=6
  194. 69 kubectl get pods -o wide
  195. 70 ./counter.sh 7
  196. 71 kubectl run nginx --dry-run=client -o yaml > static.yaml
  197. 72 kubectl run nginx --dry-run=client --image=nginx -o yaml > static.yaml
  198. 73 cat static.yaml
  199. 74 kubectl get pods
  200. 75 ./counter.sh 23
  201. 76 vim wg8.yaml
  202. 77 kubectl create -f wg8.yaml
  203. 78 kubectl describe pod pv-pod
  204. 79 kubectl describe pod pv-pod -n myvol
  205. 80 kubectl exec -it pv-pod -n myvol -- sh
  206. 81 kubectl get pvc
  207. 82 kubectl get pvc -n myvol
  208. 83 kubectl get pv
  209. 84 kubectl describe pv task-pv-volume
  210. 85 kubectl explain pv.spec | less
  211. 86 kubectl api-resources | less
  212. 87 kubectl create quota --help | less
  213. 88 kubectl set resources -h | less
  214. 89 history
  215. 90 ./counter.sh 8
  216. 91 #kubectl create quota qtest --hard pods=3,cpu=100,memory=500Mi --namespace limited
  217. 92 kubectl create ns limited
  218. 93 kubectl create quota qtest --hard pods=3,cpu=100,memory=500Mi --namespace limited
  219. 94 kubectl create deploy nginx --image=nginx --replicas=3 -n limited
  220. 95 kubectl get all -n limited
  221. 96 kubectl describe -n limited replicasets.apps nginx-85b98978db
  222. 97 kubectl describe ns limited
  223. 98 kubectl set resources deploy nginx --requests cpu=100m,memory=5Mi --limites cpu=200m,memory=20Mi -n limited
  224. 99 kubectl set resources deploy nginx --requests cpu=100m,memory=5Mi --limits cpu=200m,memory=20Mi -n limited
  225. 100 kubectl get pods -n limited
  226. 101 kubectl create deploy lmitbox --image=busybox --replicas=3 -- sleep 3000
  227. 102 kubectl get pods -n limited
  228. 103 kubectl get all -n limited
  229. 104 kubectl create deploy lmitbox --image=busybox --replicas=3 -n limited -- sleep 3000
  230. 105 kubectl get all -n limited
  231. 106 kubectl describe -n limited replicasets.apps lmitbox-6fdd4d7884
  232. 107 history
  233. 108 ./counter.sh 12
  234. 109 vim sr8.yaml
  235. 110 kubectl explain limitrange
  236. 111 kubectl explain quota
  237. 112 vim sr8.yaml
  238. 113 ./counter.sh 5
  239. 114 kubectl create app1 --image=nginx --replicas=3
  240. 115 kubectl create deploy app1 --image=nginx --replicas=3
  241. 116 kubectl create deploy app3 --image=nginx --replicas=3
  242. 117 kubectl label deployments.apps app1 app=working
  243. 118 kubectl label deployments.apps app1 type=working
  244. 119 kubectl label deployments.apps app3 type=working
  245. 120 kubectl get pods --selector type=working
  246. 121 kubectl get pods --show-labels
  247. 122 kubectl get pods --selector app=nginx
  248. 123 kubectl get pod -h | less
  249. 124 kubectl get pod exercise3 -o json | less
  250. 125 kubectl get pod -h | less
  251. 126 kubectl get pods --selector app=nginx -o wide
  252. 127 kubectl get pods --selector app=nginx -o wide --sort-by=.spec.nodeName
  253. 128 kubectl get pods --selector app=nginx -o wide --sort-by=.spec.nodeName > /tmp/sortlist.txt
  254. 129 cat /tmp/sortlist.txt
  255. 130 kubectl get pods -l app=nginx -o wide --sort-by=.spec.nodeName
  256. 131 ./counter.sh 5
  257. 132 vim df10.yaml
  258. 133 kubectl create deploy daemonploy --image=nginx --dry-run=client -o yaml > daemonploy.yaml
  259. 134 vim daemonploy.yaml
  260. 135 kubectl api-resources
  261. 136 kubectl create -f daemonploy.yaml
  262. 137 kubectl get ds,pods -o wide
  263. 138 kubectl get ds -A
  264. 139 history
  265. 140 sudo -i
  266. 141 cd cka
  267. 142 ./counter.sh 15
  268. 143 ip a
  269. 144 ip a | less
  270. 145 kubectl get all
  271. 146 cd cka
  272. 147 ./counter.sh 10
  273. 148 sudo -i
  274. 149 kubectl cordon -h
  275. 150 kubectl drain -h
  276. 151 kubectl drain -h | less
  277. 152 kubectl drain worker2
  278. 153 kubectl drain worker2 --force
  279. 154 kubectl drain worker2 --force --ignore-daemonsets
  280. 155 kubectl get pods -o wide
  281. 156 kubectl uncordon worker2
  282. 157 kubectl get nodes
  283. 158 kubectl get pods -o wide
  284. 159 kubectl get nodes
  285. 160 kubectl get nodes\
  286. 161 kubectl get nodes
  287. 162 kubectl describe node worker2 | less
  288. 163 kubectl get nodes
  289. 164 kubectl labe nodes worker2.example.com disktype=ssd
  290. 165 kubectl label nodes worker2.example.com disktype=ssd
  291. 166 kubectl get nodes
  292. 167 kubectl label nodes worker2 disktype=ssd
  293. 168 kubectl get nodes -l
  294. 169 kubectl get nodes --show-labels
  295. 170 vim selector-pod.yaml
  296. 171 kubectl create -f selector-pod.yaml
  297. 172 kubectl get pods -o wide
  298. 173 source <(kubectl completion bash)
  299. 174 kubectl describe pod nginx
  300. 175 kubectl get pods
  301. 176 kubectl delete pod nginx
  302. 177 vim selector-pod.yaml
  303. 178 kubectl create -f selector-pod.yaml
  304. 179 kubectl get pods
  305. 180 kubectl get nodes -o wide
  306. 181 kubectl taint nodes worker1 example-key=value1:NoSchedule
  307. 182 kubectl describe nodes worker1 | less
  308. 183 kubectl create deploy nginx-taint --image=nginx --replicas=3
  309. 184 kubectl get pods -o wide
  310. 185 vim taint-toleration.yaml
  311. 186 kubectl create -f taint-toleration.yaml
  312. 187 kubectl get pods nginx-toleration
  313. 188 kubectl get pods nginx-toleration -o wide
  314. 189 ./counter.sh 16
  315. 190 vim df20.yaml
  316. 191 kubectl create -f df20.yaml
  317. 192 kubectl get pods
  318. 193 kubectl get pods -o yaml
  319. 194 vim df20.yaml
  320. 195 kubectl get nodes --show-labels
  321. 196 kubectl delete -f df20.yaml
  322. 197 vim df20.yaml
  323. 198 kubectl create -f df20.yaml
  324. 199 kubectl get pods affinitypod
  325. 200 vim sanderfinity.yaml
  326. 201 kubectl get nodes -o wide
  327. 202 kubectl edit nodes worker1
  328. 203 kubectl create -f sanderfinity.yaml
  329. 204 kubectl get pods sanderx
  330. 205 kubectl delete -f df20.yaml
  331. 206 kubectl create -f df20.yaml
  332. 207 kubectl get pods affinitypod
  333. 208 vim df20.yaml
  334. 209 kubectl delete -f df20.yaml
  335. 210 vim df20.yaml
  336. 211 kubectl create -f df20.yaml
  337. 212 kubectl get pods affinitypod
  338. 213 kubectl config view
  339. 214 sudo less /etc/kubernetes/admin.conf
  340. 215 kubectl api-resources | less
  341. 216 sudo useradd -G adm anna
  342. 217 sudo passwd anna
  343. 218 su - anna
  344. 219 sudo userdel -rf anna
  345. 220 sudo useradd -G adm -m anna
  346. 221 sudo passwd anna
  347. 222 su - anna
  348. 223 id
  349. 224 sudo usermod -aG sudo anna
  350. 225 su - anna
  351. 226 kubectl get CertificateSigningRequest -A
  352. 227 kubectl api-resources | grep ertifi
  353. 228 kubectl api-resources | grep certificates.k8s
  354. 229 kubectl api-resources | grep -i certificates.k8s
  355. 230 vim podaccessrole.yaml
  356. 231 kubectl create -f podaccessrole.yaml
  357. 232 vim rolebinding.yaml
  358. 233 kubectl create -f rolebinding.yaml
  359. 234 vim rolebinding.yaml
  360. 235 kubectl create -f rolebinding.yaml
  361. 236 vim rolebinding.yaml
  362. 237 kubectl run rolepod --image=nginx
  363. 238 kubectl get pods
  364. 239 su - anna
  365. 240 kubectl auth can-i get pods --as anna
  366. 241 su - anna
  367. 242 ./counter.sh 20
  368. 243 ./counter.sh 10
  369. 244 kubectl get all -n kube-system
  370. 245 kubectl delete ds weave-net kube-system
  371. 246 kubectl delete ds weave-net -n kube-system
  372. 247 kubectl apply -f https://docs.projectcalico.org/latest/manifests/calico.yaml
  373. 248 kubectl get pods -n kube-system
  374. 249 kubectl get pods -n kube-system -o wide
  375. 250 kubectl get ds -n kube-system
  376. 251 vim nwpolicy-complete-example.yaml
  377. 252 kubectl create -f nwpolicy-complete-example.yaml
  378. 253 kubectl delete -f nwpolicy-complete-example.yaml
  379. 254 kubectl delete pods nginx
  380. 255 kubectl create -f nwpolicy-complete-example.yaml
  381. 256 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  382. 257 kubectl exec -it busybox -- nslookup nginx
  383. 258 kubectl expose pod nginx --port=80
  384. 259 kubectl exec -it busybox -- wget --spider --timeout=1 nginx
  385. 260 kubectl get all -n kube-system
  386. 261 kubectl logs calico-node-wqvvr
  387. 262 kubectl logs calico-node-wqvvr -n kube-system
  388. 263 sudo reboot
  389. 264 kubectl get pods -n kube-system
  390. 265 history
  391.  
Add Comment
Please, Sign In to add comment