Skip to content

Instantly share code, notes, and snippets.

@jpbueno
Created June 5, 2020 20:30
Show Gist options
  • Save jpbueno/69fe622b196fd5588ee50a593a616022 to your computer and use it in GitHub Desktop.
Save jpbueno/69fe622b196fd5588ee50a593a616022 to your computer and use it in GitHub Desktop.
1 cd ~
2 clear
3 sudo hostnamectl set-hostname k8s-master
4 hostname
5 sudo reboot
6 cd ~
7 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
8 ls
9 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
10 $(lsb_release -cs) \
11 stable"
12 sudo apt-get update
13 sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu
14 sudo apt-mark hold docker-ce
15 sudo usermod -aG docker ubuntu
16 exit
17 docker info
18 cd ~
19 clear
20 curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
21 cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
22 deb https://apt.kubernetes.io/ kubernetes-xenial main
23 EOF
24 sudo apt-get update
25 sudo apt-get install -y kubelet=1.15.7-00 kubeadm=1.15.7-00 kubectl=1.15.7-00
26 sudo apt-mark hold kubelet kubeadm kubectl
27 kubeadm version
28 sudo kubeadm init --pod-network-cidr=10.244.0.0/16
29 mkdir -p $HOME/.kube
30 cd ~
31 kubectl version
32 clear
33 kubectl get nodes
34 echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
35 sudo sysctl -p
36 kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
37 kubectl get nodes
38 clear
39 kubectl get nodes
40 kubectl get pods -n kube-system
41 cd ~
42 cat << EOF | kubectl create -f -
43 apiVersion: v1
44 kind: Pod
45 metadata:
46 name: nginx
47 spec:
48 containers:
49 - name: nginx
50 image: nginx
51 EOF
52 ls
53 kubectl get pods
54 kubectl describe pod nginx
55 kubectl get pods -n kube-system
56 kubectl describe pod nginx
57 kubectl delete pod nginx
58 kubectl get pods
59 kubectl get nodes
60 kubectl describe node k8s-master
61 cat << EOF | kubectl create -f -
62 apiVersion: apps/v1
63 kind: Deployment
64 metadata:
65 name: nginx
66 labels:
67 app: nginx
68 spec:
69 replicas: 2
70 selector:
71 matchLabels:
72 app: nginx
73 template:
74 metadata:
75 labels:
76 app: nginx
77 spec:
78 containers:
79 - name: nginx
80 image: nginx:1.15.4
81 ports:
82 - containerPort: 80
83 EOF
84 kubectl get pods
85 cat << EOF | kubectl create -f -
86 apiVersion: v1
87 kind: Pod
88 metadata:
89 name: busybox
90 spec:
91 containers:
92 - name: busybox
93 image: radial/busyboxplus:curl
94 args:
95 - sleep
96 - "1000"
97 EOF
98 kubectl get pods
99 kubectl get pods -o wide
100 kubectl exec busybox -- curl 10.244.1.4
101 kubectl exec busybox -- curl 10.244.2.3
102 kubectl get pods -n kube-system
103 sudo systemctl status kubelet
104 cat <<EOF | kubectl create -f -
105 apiVersion: apps/v1
106 kind: Deployment
107 metadata:
108 name: nginx-deployment
109 labels:
110 app: nginx
111 spec:
112 replicas: 2
113 selector:
114 matchLabels:
115 app: nginx
116 template:
117 metadata:
118 labels:
119 app: nginx
120 spec:
121 containers:
122 - name: nginx
123 image: nginx:1.15.4
124 ports:
125 - containerPort: 80
126 EOF
127 kubectl get deployments
128 kubectl describe deployment nginx-deployment
129 kubectl get pods
130 cat << EOF | kubectl create -f -
131 kind: Service
132 apiVersion: v1
133 metadata:
134 name: nginx-service
135 spec:
136 selector:
137 app: nginx
138 ports:
139 - protocol: TCP
140 port: 80
141 targetPort: 80
142 nodePort: 30080
143 type: NodePort
144 EOF
145 kubectl get svc
146 curl localhost:30080
147 kubectl get services
148 kubectl get service
149 kubectl get node
150 kubectl get nodes
151 kubectl get pod
152 kubectl get pods
153 pwd
154 git clone https://github.com/linuxacademy/robot-shop.git
155 ls
156 cd robot-shop/K8s/descriptors/
157 ls
158 cat cart-deployment.yaml
159 cd ~
160 kubectl create namespace robot-shop
161 kubectl get namespaces
162 kubectl -n robot-shop create -f ~/robot-shop/K8s/descriptors/
163 kubectl get services
164 kubectl delete svc nginx-service
165 kubectl get services
166 kubectl get namespaces
167 kubectl get pod
168 kubectl delete pods busybox nginx-9b644dcd5-s5drv
169 kubectl get pod
170 kubectl delete pods busybox nginx-9b644dcd5-xzl22 nginx-9b644dcd5-zrdcv nginx-deployment-9b644dcd5-ft7w8 nginx-deployment-9b644dcd5-kcc2t
171 kubectl get pod
172 kubectl get deployment
173 kubectl delete deployment nginx nginx-deployment
174 kubectl get deployment
175 kubectl get pod
176 kubectl -n robot-shop create -f ~/robot-shop/K8s/descriptors/
177 kubectl get deployments
178 kubectl get pods -n robot-shop -w
179 kubectl get pods
180 kubectl get pods -n robot-shop
181 kubectl inspect pod web-75954897c-zbzvd
182 kubectl describe pod web-75954897c-zbzvd
183 kubectl describe namespace robot-shop
184 kubectl inspect namespace robot-shop
185 kubectl describe pod web-75954897c-zbzvd -n robot-shop
186 kubectl get deployments
187 kubectl get svc
188 kubectl get deployments
189 kubectl get pods -n robo-shop
190 cd ~
191 ls
192 kubectl create namespace robot-shop
193 kubectl get namespace
194 kubectl delete namespace robot-shop
195 kubectl get namespace
196 kubectl get pods -n robot-shop
197 kubectl get pods
198 kubectl version
199 kubectl get nodes
200 kubectl get pods --all-namespaces
201 kubectl get pods --all-namespaces -o wide
202 kubectl get namespaces
203 cat << EOF | kubectl create -f -
204 apiVersion: v1
205 kind: Pod
206 metadata:
207 name: nginx
208 spec:
209 containers:
210 - name: nginx
211 image: nginx
212 EOF
213 kubectl get pod
214 kubect describe pod nginx
215 kubectl describe pod nginx
216 kubectl delete pod nginx
217 kubectl get pods
218 cd ~
219 clear
220 kubectl get componentstatus
221 vim nginx.yml
222 cat nginx.yml
223 kubectl create -f nginx.yml
224 kubectl get pod
225 kubectl get deployment nginx-deployment -o yaml
226 kubectl get deployment
227 kubectl get namespace
228 kubectl get pods --show-labels
229 kubectl label pods nginx-deployment-5754944d6c-6vqqb env=prod
230 kubect get pod --show-labels
231 kubect get pods --show-labels
232 kubectl get pod --show-labels
233 kubeclt get pode -L
234 kubeclt get pode -L env
235 kubeclt get pod -L env
236 kubeclt get pods -L env
237 kubectl get pod -L env
238 kubectl get pod -L
239 kubectl get pod -L prod
240 kubectl get pod -L env
241 kubectl label pod nginx-deployment-5754944d6c-8ncpd env=dev
242 kubectl get pod -L env
243 cd ~
244 kubectl annotate deployment nginx-deployment ninja="JP"
245 kubectl get deployment
246 kubectl get deployment nginx-deployment -o yaml
247 kubectl get pods --field-selector status.phase=Running
248 kubectl get pods
249 kubectl get pods -o wide
250 kubectl delete pod nginx-deployment-5754944d6c-6vqqb
251 kubectl get pods -o wide
252 kubectl get svc
253 vim nginx-nodeport.yml
254 kubectl create -f nginx-nodeport.yml
255 kubectl get svc
256 cd ~
257 kubectl get pods -o wide
258 kubectl get service
259 kubectl describe pod nginx-deployment-5754944d6c-8ncpd
260 curl localhost:30080
261 kubectl get pod
262 cat << EOF | kubectl create -f -
263 apiVersion: v1
264 kind: Pod
265 metadata:
266 name: busybox
267 spec:
268 containers:
269 - name: busybox
270 image: radial/busyboxplus:curl
271 args:
272 - sleep
273 - "1000"
274 EOF
275 kubectl get pod
276 kubectl get pods -o wide
277 kubectl get services
278 kubectl exec busybox -- curl 10.97.122.237:80
279 kubectl exec busybox -- curl 10.244.2.15:30080
280 kubectl exec busybox -- curl 10.244.2.15:80
281 clear
282 kubectl get nodes
283 kubectl get namespaces
284 kubectl get nodes -o wide
285 kubectl describe node k8s-master
286 kubectl get pods --all-namespaces
287 kubectl get namespaces
288 kubectl get pods
289 kubectl get services -o wide
290 kubectl get pods --all-namespaces -o wide
291 kubectl get nodes -o wide
292 kubectl get deployments
293 kubectl describe pods etcd-k8s-master
294 kubectl get pods --all-namespaces --show-labels -o wide
295 kubectl get nodes
296 clear
297 kubectl get pods --all-namespaces
298 kubectl get namespaces
299 kubectl get pods
300 kubectl get pods --all-namespaces -o wide
301 kubectl get deployments
302 kubectl get pods -all-namespaces --show-labels -o wide
303 kubectl get pods --all-namespaces --show-labels -o wide
304 cd ~
305 clear
306 kubectl cluster-info
307 kubectl config view
308 kubectl describe pods
309 kubectl describe pod
310 kubectl describe nodes
311 kubectl describe pods
312 kubectl get services
313 kubectl get services --all-namespaces
314 kubectl api-resources -o wide
315 kubectl api-resources
316 kubectl cluster info
317 kubectl cluster-info
318 kubectl version
319 kubectl get secrets
320 cat .kube/config | more
321 exit
322 cd ~
323 hostname
324 clear
325 kubectl create ns my-ns
326 kubectl get ns
327 kubectl run test --image=chadmcrowell/kubectl-proxy -n my-ns
328 kubectl get pods --namespaces=ns
329 kubectl get pods --namespaces my-ns
330 kubectl get pods -namespaces my-ns
331 kubectl get pods -n my-ns
332 kubectl exec -it test-54776597d6-lltmf -n my-ns sh
333 kubectl get serviceaccounts
334 kubectl create nginx --image=nginx
335 kubectl run nginx --image=nginx
336 kubectl get pods
337 kubectl get deployments
338 kubect port-forward nginx-7bb7cd8db5-tj8ld 8081:80
339 kubectl port-forward nginx-7bb7cd8db5-tj8ld 8081:80
340 clear
341 kubectl get pods
342 kubectl logs nginx-7bb7cd8db5-tj8ld
343 kubectl exec -it nginx-7bb7cd8db5-tj8ld -- nginx -v
344 clear
345 kubectl expose deployment nginx --port 80 --type NodePort
346 kubectl get services
347 kubectl get services -o wide
348 kubectl get nodes
349 kubectl get pods
350 kubectl describe nodes
351 cd ~
352 clear
353 kubectl version --short
354 kubectl describe nodes
355 kubectl get nodes
356 kubectl version short
357 kubectl version --short
358 kubectl get pods -n kube-system
359 kubectl get pods kube-controller-manager-k8s-master -o yaml -n kube-system
360 clear
361 sudo apt-mark unhold kubeadm kubelet
362 sudo apt install -y kubeadm=1.16.6-00
363 sudo apt-mark hold kubeadm
364 kubeadm version
365 sudo kubeadk upgrade plan
366 sudo kubeadm upgrade plan
367 sudo kubeadm upgrade apply v1.16.6
368 kubectl get nodes
369 sudo apt install -y kubelet=1.16.6-00
370 kubectl get nodes
371 kubectl version --short
372 sudo apt-mark unhold kubectl
373 sudo apt install -y kubectl=1.16.6-00
374 kubectl version --short
375 kubectl get nodes
376 sudo apt-mark hold kubectl kubelet
377 kubectl get nodes
378 kubectl get pods -o wide
379 kubectl drain nginx-deployment-5754944d6c-qbsq7 --ignore-daemonsets
380 kubectl drain k8s-node1 --ignore-daemonsets
381 kubectl get pods -o wide
382 kubectl get pods watch
383 kubectl get pods --watch
384 kubectl get pods -o wide
385 kubectl get pods -o wide --watch
386 kubectl get pods -o wide
387 kubectl get nodes
388 kubectl uncordon k8s-node1
389 kubectl get nodes
390 sudo systemctl status kubelet
391 sudo systemctl restart kubelet
392 kubectl get nodes
393 echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
394 sudo sysctl -p
395 kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
396 kubectl get nodes
397 sudo systemctl restart flannel
398 etcdctl get /coreos.com/network/config
399 kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
400 kubectl get nodes
401 journalctl -u kubelet
402 kubeadm init
403 sudo kubeadm init
404 kubectl get nodes
405 kubectl get pods -o wide
406 kubectl get nodes
407 kubectl get no
408 kubectl get n
409 kubectl get nod
410 kubectl get no
411 sudo kubeadm token generate
412 sudo kubeadm token create atuzc4.tu1ae5iiyk5zglqa --ttl 1h --print-join-command
413 kubeadm --print-join-command
414 kubeadm token --print-join-command
415 kubeadm list --print-join-command
416 kubeadm list
417 sudo kubeadm list
418 kubectl get node
419 wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz
420 tar xvf etcd-v3.3.12-linux-amd64.tar.gz
421 sudo mv etcd-v3.3.12-linux-amd64/etcd* /usr/local/bin
422 sudo ETCDCTL_API=3 etcdctl snapshot save snapshot.db --cacert /etc/kubernetes/pki/etcd/ca.crt --cert /etc/kubernetes/pki/etcd/server.crt --key /etc/kubernetes/pki/etcd/server.key
423 ETCDCTL_API=3 etcdctl --help
424 cd /etc/kubernetes/pki/etcd/
425 ls
426 ETCDCTL_API=3 etcdctl --write-out=table snapshot status snapshot.db
427 cd ~
428 ETCDCTL_API=3 etcdctl --write-out=table snapshot status snapshot.db
429 sudo tar -zcvf etcd.tar.gz /etc/kubernetes/pki/etcd
430 cd ~
431 clear
432 kubectl get nodes
433 kubect get pods -o wide
434 kubectl get pods -o wide
435 cd ~
436 kubectl get services -o yaml
437 kubectl get services -o wide
438 kubectl get services -o yaml > services.txt
439 cat services.txt
440 rm -rf services.txt
441 ls
442 clear
443 kubectl get services -o wide
444 ping 10.96.0.1
445 ping 10.96.141.71
446 ping 10.97.122.237
447 curl http://10.97.122.237
448 kubectl get endpoints
449 kubectl get pods
450 kubectl get pods -o wide
451 sudo iptables-save | grep KUBE
452 sudo iptables-save | grep KUBE | grep nginx
453 sudo iptables-save | grep KUBE nginx
454 sudo iptables-save | grep KUBE nginx
455 cd ~
456 clear
457 vim nginx-loadbalancer.yml
458 kubectl run kubeserve2 --image=chadmcrowell/kubeserve2
459 kubectl get deployments
460 kubectl scale deployment/kubeserve2 --replicas=2
461 kubectl get pods -o wide
462 kubectl get pods -o wide watch
463 kubectl get pods -o wide --watch
464 kubectl expose deployment kubeserve2 --port 80 --target-port 8080 --type LoadBalancer
465 kubectl get services
466 kubectl get services -w
467 kubectl get services kubeserve2 -o yaml
468 curl http://10.111.27.59
469 kubectl describe services kubeserve
470 kubectl annotate service kubeserve2 externalTrafficPolicy=Local
471 kubectl edit ingress
472 kubectl describe ingress
473 curl http://kubeserve2.example.com
474 kubectl get pods -o wide
475 kubect get services -o wide
476 kubect get services
477 kubectl get services -o wide
478 kubectl remove service nginx
479 kubectl delete service nginx
480 kubectl get services -o wide
481 vim ingress.yaml
482 kubectl edit ingress
483 kubectl create -f ingress.yaml
484 kubectl get service
485 kubectl get services
486 kubectl edit ingress
487 kubectl describe ingress
488 kubectl get pods -n kube-system
489 kubectl get deployments -n kube-system
490 kubectl get services -n kube-system
491 vim busybox.yaml
492 kubectl create -f busybox.yaml
493 kubectl get pods
494 kubectl delete pod busybox
495 kubectl get pods
496 kubectl create -f busybox.yaml
497 kubectl get pods
498 kubectl exec -it busybox -- cat /etc/resolv.conf
499 kubectl exec -it busybox -- nslookup kubernetes
500 kubectl get pods -o wide
501 kubectl exec -ti busybox -- nslookup 10.244.2.15.default.pod.cluster.local
502 kubectl exec -ti busybox -- nslookup 10-32-0-5.default.pod.cluster.local
503 kubectl exec -it busybox -- nslookup kube-dns.kube-system.svc.cluster.local
504 kubectl get service
505 kubectl get pods -n kube-system
506 kubectl logs coredns-5644d7b6d9-dzjw9
507 kubectl logs coredns-5644d7b6d9-zc7c7
508 kubectl logs coredns-5644d7b6d9-zc7c7 -n kube-system
509 vim headless.yaml
510 kubectl create -f headless.yaml
511 kubectl get services
512 vim custom-dns.yaml
513 kubectl create -f custom-dns.yaml
514 kubectl get pods
515 kubectl get pods -o wide
516 kubectl exec -ti busybox -- nslookup 10-32-0-6.default.pod.cluster.local
517 kubectl exec -it dns-example -- cat /etc/resolv.conf
518 kubectl get namespaces
519 kubectl get pod -n kube-system
520 kubectl get all -all-namespaces -o wide
521 kubectl get all --all-namespaces -o wide
522 kubectl run pod --image=nginx jp_nginx --dryrun=client -o yaml > jp_nginx.yml
523 kubectl run pod --image=nginx jp_nginx --dry-run=client -o yaml > jp_nginx.yml
524 kubectl run --image=nginx jp_nginx --dry-run=client -o yaml > jp_nginx.yml
525 kubectl run --image=nginx jp_nginx --dry-run=client -o yaml > jp_nginx.yaml
526 kubectl run --image=nginx jp-ninx --dry-run=client -o yaml > jp-nginx.yml
527 kubectl run --image=nginx jp-ninx --dry-run -o yaml > jp-nginx.yml
528 cat jp_nginx.y
529 cat jp_nginx.yml
530 cat jp-nginx.yml
531 rm -rf jp_nginx.yml
532 ls
533 rm -rf jp_nginx.yaml
534 cat jp-nginx.yml
535 kubectl create -f jp-nginx.yml
536 kubectl get pod
537 kubectl create deployment jp-deployment --image=nginx --dry-run -o yaml > jp-deployment.yml
538 cat jp-deployment.yml
539 vim jp-deployment.yml
540 kubectl create -f jp-deployment.yml
541 kubectl get deployments.apps
542 kubectl get pod
543 kubectl delete -f jp-deployment.yml
544 kubectl get pod
545 kubectl get deployments.apps
546 kubectl delete -f jp-nginx.yml
547 kubectl get deployments.apps
548 kubectl get pod
549 kubectl delete pod --all
550 kubectl get pod
551 kubectl get deployments.apps
552 kubectl delete deployments.apps nginx
553 kubectl delete deployments.apps nginx-deployment
554 kubectl delete deployments.apps pref
555 kubectl get deployments.apps
556 kubectl delete deployments.apps kubeserve2
557 kubectl get deployments.apps
558 kubectl get pod
559 kubectl get pod --watch
560 kubectl get pod
561 kubectl get pod -n kube-system
562 kubectl create -f jp-deployment.yml -n jp-namespace
563 kubectl create -f jp-deployment.yml -n opa
564 kubectl create namespace
565 kubectl get namespaces
566 kubectl delete namespaces my-ns
567 kubectl get namespaces
568 kubectl create -f jp-deployment.yml -n jp
569 kubectl create namespace jp-namespace
570 kubectl get namespaces
571 kubectl create -f jp-deployment.yml -n jp-namespace
572 kubectl get deployments.apps
573 kubectl get deployments.apps -n jp-namespace
574 kubectl get pod
575 kubectl get pod -n jp-namespace
576 kubectl explain ReplicSet
577 kubectl get deployments.apps
578 kubectl get deployments.apps -n jp-namespace
579 kubectl delete deployments.apps -f jp-deployment.yml
580 kubectl delete -f jp-deployment.yml
581 kubectl delete deployments.apps jp-deployment.yml
582 kubectl delete deployments.apps jp-deployment
583 kubectl get deployments.apps
584 kubectl delete -f jp-deployment.yml -n jp-namespace
585 kubectl get pod -n jp-namespace
586 kubectl get pod -n jp-namespace
587 kubectl get namespaces
588 kubectl get deployments.apps
589 kubectl get deployments.apps -n jp-namespace
590 clear
591 kubectl run --image=nginx nginx
592 kubectl get pod
593 kubectl expose pod nginx-6db489d4b7-dbv5q --port 80
594 kubectl get pod
595 kubectl get service
596 kubectl delete service kube-headless kubeserve2
597 kubectl get service
598 kubectl delete service nginx-nodeport
599 kubectl get service
600 curl 10.107.204.246
601 kubectl delete service nginx-6db489d4b7-dbv5q
602 kubectl get service
603 kubectl expose pod nginx-6db489d4b7-dbv5q --port 80 --type NodePort
604 kubectl get service
605 curl 10.101.92.7
606 kubectl get pod -o wide
607 kubectl get pod
608 kubectl expose pod nginx-6db489d4b7-dbv5q --port 80 --type NodePort
609 kubectl expose pod nginx --port 80 --type NodePort
610 kubectl logs -f nginx-6db489d4b7-dbv5q
611 kubectl get depl
612 kubectl get deploy
613 kubectl get sv
614 kubectl get svc
615 kubectl get pod,deploy,svc,namespaces,node
616 kubect get all
617 kubect get --all
618 kubectl get all
619 kubectl delete nginx
620 kubectl get pod
621 kubectl delete nginx-6db489d4b7-dbv5q
622 kubectl delete pod nginx-6db489d4b7-dbv5q
623 kubectl delete service nginx-6db489d4b7-dbv5q
624 kubectl delete namespaces jp-namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment