-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
823 lines (692 loc) · 24.9 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# Docker installation
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/install-docker-ubuntu-20.04.sh
sh install-docker-ubuntu-20.04.sh
# refresh your chrome
docker --version
docker run hello-world
docker images
docker version
systemctl status docker # press q to exit
which docker
docker images
docker pull nginx
docker images
docker pull redis
docker pull ubuntu
docker pull centos
docker images
docker pull nginx:1.9.5
docker images
# explore more images on hub.docker.com
mkdir ~/hello-python
cd ~/hello-python
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/hello-python/Dockerfile
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/hello-python/main.py
ls -l
docker build -t hello-python:v1 .
docker images
docker run hello-python:v1
# open second terminal using duplicate tab in chrome
# 1st tab
docker run nginx
# 2nd tab
ps aux | grep nginx
# 1st tab
Ctrl + C to terminate your container
# 2nd tab
ps aux | grep nginx
docker run ubuntu ls /
docker run ubuntu ps aux
docker run ubuntu uname -a
docker run centos uname -a
docker run -it ubuntu /bin/bash
# vim --version
# apt update
# apt install vim -y
# vim --version
# exit
sudo ls /var/lib/docker
sudo ls /var/lib/docker/image
sudo cat /var/lib/docker/image/overlay2/repositories.json
docker images
sudo ls /var/lib/docker/image/overlay2/layerdb/sha256
docker image inspect hello-python:v1
docker run jpetazzo/clock # ctrl + c to exit
docker run nginx # ctrl + c to exit
docker run -d jpetazzo/clock
docker run -d nginx
docker ps
docker logs <container-id>
docker ps
docker ps -l
docker ps -a
docker ps -q
docker ps -qa
docker run --name myapp -d nginx
docker ps
docker stop myapp
docker ps -a
docker start myapp
docker ps
docker kill myapp
docker ps -a
docker restart myapp
docker ps
docker attach myapp # ctrl + c to exit
docker ps -a
docker start myapp
docker ps
docker logs myapp
docker exec myapp ls -l /proc
docker exec -it myapp /bin/bash
# apt update && apt install vim -y
# exit
docker ps
docker exec myapp vim --version
docker inspect myapp | less
docker inspect myapp | grep -i ipaddress
curl 172.#.#.#
docker ps
docker rm myapp
docker stop myapp
docker ps -a
docker rm myapp
docker ps -a | grep hello-world
docker rm <container-id> <container-id>
docker ps -a | grep hello-world
docker system df
docker system info
docker system events # ctrl + c to exit
docker system prune
docker ps -a
docker run -it ubuntu /bin/bash
# hostname
# exit
docker run --hostname=front-end-app -it ubuntu /bin/bash
# hostname
# exit
docker ps
docker run --name=myapp -d nginx
docker ps
docker top myapp
docker stats
docker run -m 500M --memory-reservation 200M --name=myapp02 -d nginx
docker run --cpus 0.02 --name=myapp03 -d nginx
docker ps
docker stats
docker volume
docker volume create mysql-db
docker volume ls
docker volume inspect mysql-db
sudo ls /var/lib/docker/volumes/mysql-db/_data
docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -v mysql-db:/var/lib/mysql -d mysql
sudo ls /var/lib/docker/volumes/mysql-db/_data
docker exec -it mysql /bin/bash
# mysql -u root -p
# Enter password: password
# mysql > create database demo;
# mysql > show databases;
# mysql > exit
# exit
docker stop mysql
docker rm mysql
sudo ls /var/lib/docker/volumes/mysql-db/_data
docker run --name mysql1 -e MYSQL_ROOT_PASSWORD=password -v mysql-db:/var/lib/mysql -d mysql
docker exec -it mysql1 /bin/bash
# mysql -u root -p
# Enter password: password
# mysql > show databases;
# mysql > exit
# exit
cd ~
git clone https://github.com/Jaibw/FrozenYogurtShop.git
ls /home/ubuntu/FrozenYogurtShop
docker run --name website001 -v /home/ubuntu/FrozenYogurtShop:/usr/share/nginx/html -d nginx
docker ps
docker inspect website001 | grep -i ipaddress
curl 172.#.#.#
docker run --name website001 -p 8081:80 -v /home/ubuntu/FrozenYogurtShop:/usr/share/nginx/html -d nginx
Open Chrome http://PublicIP:8081
cd ~/hello-python
docker login
docker build -t DOCKER-USERNAME/hello-python . ## eg. docker build -t jaibw/hello-python .
docker push DOCKER-USERNAME/hello-python ## eg. docker push jaibw/hello-python
Open DockerHub and search for DOCKER-USERNAME/hello-python
docker search DOCKER-USERNAME
docker search rabbitmq
docker rmi DOCKER-USERNAME/hello-python
docker ps
docker stop `docker ps -q`
docker ps
docker ps -qa
docker rm `docker ps -qa`
docker ps -a
docker images
docker rmi python
docker images
docker system prune --all
docker images
docker volume ls
docker volume prune
docker images
docker pull nginx
docker images
docker run --name web -d nginx
docker ps
docker exec -it web /bin/bash
# apt update
# apt install vim nano default-jdk -y
# exit
docker ps -a
docker images
docker commit web USERNAME/web-base:v1
docker images
mkdir ~/custom-apache
cd ~/custom-apache/
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/custom-apache/Dockerfile
cat Dockerfile
docker build -t webserver:v1 .
docker images
docker run -d --name demo01 webserver:v1
docker inspect demo01 | grep -i ipaddress
curl 172.#.#.#
docker stop demo01
mkdir ~/hello-java
cd ~/hello-java
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/hello-java/Dockerfile
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/hello-java/Hello.java
cat Dockerfile
cat Hello.java
docker build -t hello-java:v1 .
docker images
docker run hello-java:v1
docker run -it hello-java:v1 /bin/bash
# ls
# java Hello
# exit
cat Dockerfile
mkdir ~/corporate-image
cd ~/corporate-image
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/corporate-image/Dockerfile
docker build -t base-ubuntu .
docker run -it base-ubuntu
# nano --version
# cd /data
# echo 'demo' > file1.txt
# exit
docker volume ls
docker history base-ubuntu
mkdir ~/mysql-db
cd ~/mysql-db
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/mysql-db/Dockerfile
vim Dockerfile
docker build -t mysql-db .
docker images
docker run -d --name mysql mysql-db
docker ps
docker exec -it mysql /bin/bash
# mysql -u root -p
# Password: --- type password
# mysql > exit
# exit
docker stop `docker ps -q`
docker rm `docker ps -qa`
mkdir ~/wordpress/db
mkdir -p ~/wordpress/db
mkdir -p ~/wordpress/app
cd ~/wordpress/db
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/mysql-db/Dockerfile
docker build -t mysql-db .
docker run -d --name mysql mysql-db
cd ~/wordpress/app
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/wordpress/Dockerfile
cat Dockerfile
docker inspect mysql | grep -i ipaddress
sed -i 's/DATABASEIP/172.#.#.#/g' Dockerfile
cat Dockerfile
docker build -t wp-app .
docker run -d --name wordpress -p 8080:80 wp-app
Open chrome http://PublicIP:8080/
docker login jaibw.jfrog.io
docker pull nginx
docker tag nginx jaibw.jfrog.io/devops-docker/nginx:YOURNAME
docker push jaibw.jfrog.io/devops-docker/nginx:YOURNAME
cd ~
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/docker-compose/wordpress.yaml
cat wordpress.yaml
docker-compose help
docker-compose -f wordpress.yaml up
Access http://PublicIP:8081/
Press Ctrl + c to exit from docker-compose up command
docker stop `docker ps -q`
docker rm `docker ps -qa`
docker system prune --all
docker volume prune
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/docker-compose/ovs.yaml
cat ovs.yaml
docker-compose -f ovs.yaml -p ovs up
Access App
http://PublicIP:8082
http://PublicIP:8082/swagger-ui.html
Acess DB Admin Utility:
Find DB details - https://raw.githubusercontent.com/Jaibw/docker-v1/master/docker-compose/ovs.yaml
http://PublicIP:8083
docker-compose -f ovs.yaml -p ovs start ## start it as a service
docker-compose -f ovs.yaml -p ovs stop ## stop the service
docker stop `docker ps -q`
docker rm `docker ps -qa`
docker system prune --all
docker volume prune
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
minikube version
minikube start --driver=docker
minikube kubectl -- get pods -A
docker ps
docker ps -a
minikube help
minikube status
minikube dashboard
minikube addons list
minikube addons enable metrics-server
minikube addons list
## Kubernetes Production Grade Setup - Multi-node cluster
master> sudo apt update
master> sudo apt -y upgrade
master> sudo systemctl reboot
worker01> sudo apt update
worker01> sudo apt -y upgrade
worker01> sudo systemctl reboot
master> sudo hostnamectl set-hostname master
master> REFRESH MY SESSION
worker01> sudo hostnamectl set-hostname worker01
worker01> REFRESH MY SESSION
# Install kubelet, kubeadm and kubectl
master> sudo apt -y install curl apt-transport-https
master> curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
master> echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
master> sudo apt update
master> sudo apt -y install vim git curl wget kubelet=1.23.7-00 kubeadm=1.23.7-00 kubectl=1.23.7-00
master> sudo apt-mark hold kubelet kubeadm kubectl
master> kubectl version --client
master> kubeadm version
worker01> sudo apt -y install curl apt-transport-https
worker01> curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
worker01> echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
worker01> sudo apt update
worker01> sudo apt -y install vim git curl wget kubelet=1.23.7-00 kubeadm=1.23.7-00
worker01> sudo apt-mark hold kubelet kubeadm
worker01> kubeadm version
# Turn off swap
master> sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
master> sudo swapoff -a
worker01> sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
worker01> sudo swapoff -a
# Enable kernel modules
master> sudo modprobe overlay
master> sudo modprobe br_netfilter
worker01> sudo modprobe overlay
worker01> sudo modprobe br_netfilter
# Add some settings to sysctl
master> sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
worker01> sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
# Reload sysctl
master> sudo sysctl --system
worker01> sudo sysctl --system
# Install and configure docker and other services
master> sudo apt install -y gnupg2 software-properties-common apt-transport-https ca-certificates
master> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
master> sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
master> sudo apt update
master> sudo apt install -y containerd.io docker-ce docker-ce-cli
master> sudo mkdir -p /etc/systemd/system/docker.service.d
master> sudo tee /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
# Start and enable Services
master> sudo systemctl daemon-reload
master> sudo systemctl restart docker
master> sudo systemctl enable docker
master> sudo systemctl enable kubelet
worker01> sudo apt install -y gnupg2 software-properties-common apt-transport-https ca-certificates
worker01> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
worker01> sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
worker01> sudo apt update
worker01> sudo apt install -y containerd.io docker-ce docker-ce-cli
worker01> sudo mkdir -p /etc/systemd/system/docker.service.d
worker01> sudo tee /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
# Start and enable Services
worker01> sudo systemctl daemon-reload
worker01> sudo systemctl restart docker
worker01> sudo systemctl enable docker
worker01> sudo systemctl enable kubelet
# Initialize Kubernetes Cluster
master> sudo docker images
master> sudo kubeadm config images pull
master> sudo docker images
master> sudo kubeadm help init
master> sudo kubeadm init --pod-network-cidr=10.100.0.0/16 --service-cidr=10.150.0.0/16 --upload-certs
worker01> sudo kubeadm join 172.#.#.#:6443 --token ###### --discovery-token-ca-cert-hash sha256:#######
master> sudo cat /etc/kubernetes/admin.conf
master> mkdir -p $HOME/.kube
master> kubectl cluster-info
master> sudo cp -f /etc/kubernetes/admin.conf $HOME/.kube/config
master> sudo chown $(id -u):$(id -g) $HOME/.kube/config
master> kubectl cluster-info
master> kubectl get nodes
master> kubectl get nodes -o wide
master> kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
master> watch kubectl get nodes
# Press Ctrl + c when your both nodes are in ready state
master> kubectl get pods --all-namespaces
## PODS
master> kubectl get pods
master> kubectl get ns
master> kubectl run web --image=nginx
master> kubectl get pods
master> kubectl get pods -o wide
master> kubectl describe pods web
master> kubectl logs web
master> kubectl get pods -o wide
master> curl 10.#.#.#
worker01> sudo docker ps | grep web
worker01> curl 10.#.#.#
master> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/pod.yaml
master> cat pod.yaml
master> kubectl create -f pod.yaml
master> kubectl get pods -o wide
master> curl 10.#.#.#
master> kubectl describe pods web01
master> kubectl logs web01
master> kubectl get pods
master> kubectl delete pod web
master> kubectl delete -f pod.yaml
master> kubectl get pods
worker01> sudo docker ps | grep web01
master> kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/pod-multi.yaml
master> kubectl get pods -o wide
master> curl 10.#.#.#
master> kubectl describe pods web02
master> kubectl logs web02 app
master> kubectl logs web02 db
worker01> sudo docker ps | grep web02
master> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/replication-controller.yaml
master> kubectl create -f replication-controller.yaml
master> kubectl get replicationcontroller
master> kubectl get rc
master> kubectl get pods
master> kubectl get pods -o wide
master> kubectl delete pod myapp-web-#####
master> kubectl get pods -o wide
master> cat replication-controller.yaml
master> sed -i 's/replicas: 3/replicas: 6/g' replication-controller.yaml
master> cat replication-controller.yaml
master> kubectl replace -f replication-controller.yaml
master> kubectl get rc
master> kubectl get pods -o wide
master> kubectl scale --replicas=9 -f replication-controller.yaml
master> kubectl get pods -o wide
master> kubectl scale --replicas=1 replicationcontroller myapp-web
master> kubectl get pods -o wide
master> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/replica-set.yaml
master> kubectl create -f replica-set.yaml
master> kubectl get replicaset
master> kubectl get rs
master> kubectl get pods
master> kubectl get pods -o wide
master> cat replica-set.yaml
master> sed -i 's/replicas: 3/replicas: 6/g' replica-set.yaml
master> cat replica-set.yaml
master> kubectl replace -f replica-set.yaml
master> kubectl get rs
master> kubectl get pods -o wide
master> kubectl scale --replicas=9 -f replica-set.yaml
master> kubectl get pods -o wide
master> kubectl scale --replicas=1 replicaset frontend
master> kubectl get pods -o wide
master> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/deployment.yaml
master> kubectl create -f deployment.yaml
master> kubectl get deployment
master> kubectl get rs
master> kubectl get pods
master> cat deployment.yaml
master> sed -i 's/replicas: 3/replicas: 6/g' deployment.yaml
master> cat deployment.yaml
master> kubectl replace -f deployment.yaml
master> kubectl get deployment
master> kubectl get pods -o wide
master> kubectl scale --replicas=9 -f deployment.yaml
master> kubectl get pods -o wide
master> kubectl scale --replicas=1 deployment website001
master> kubectl get pods -o wide
master> kubectl replace -f deployment.yaml
master> kubectl describe deployment website001
master> cat deployment.yaml
master> sed -i 's/image: nginx/image: nginx:1.23/g' deployment.yaml
master> cat deployment.yaml
master> kubectl replace -f deployment.yaml
master> kubectl rollout status deployment website001
master> kubectl get rs
master> kubectl rollout history deployment website001
master> kubectl set image deployment website001 web=nginx:1.9.1
master> kubectl rollout status deployment website001
master> kubectl rollout history deployment website001
master> kubectl rollout undo deployment website001
master> kubectl rollout status deployment website001
master> kubectl rollout history deployment website001
master> kubectl get rs
master> kubectl apply -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/node-port.yaml
master> kubectl get svc
master> kubectl describe service website001
Open http://PublicIP:30303
master> kubectl apply -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/cluster-ip.yaml
master> kubectl get svc
master> kubectl describe service website001-internal
master> curl http://10.##.##.##
# Kubectl autocomplete - BASH
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
kubectl get pods --> press the table key
Ref: https://kubernetes.io/docs/reference/kubectl/cheatsheet/
## Kubernetes setup with Kubespary
sudo hostnamectl set-hostname controller
sudo apt install python3-pip
git clone https://github.com/kubernetes-sigs/kubespray.git
cd kubespray/
sudo pip install -r requirements.txt
ansible --version
sudo vim /etc/ansible/hosts ## add your hosts details
ansible all -m ping
cp -rfp inventory/sample inventory/mycluster
declare -a IPS=(172.31.18.26 172.31.23.152 172.31.31.16 172.31.22.205)
CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}
vim inventory/mycluster/hosts.yaml ## update your nodes information
ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.yml
master> mkdir .kube
master> sudo cp /etc/kubernetes/admin.conf .kube/config
master> sudo chown ubuntu:ubuntu .kube/config
master> kubectl get nodes
master> kubectl get pods -A
## Create Namespace
kubectl get ns
kubectl get namespace
kubectl get pods -n default
kubectl get pods
kubectl get pods -n kube-system
kubectl create namespace NAME
kubectl get all -n NAME
kubectl run demo --image=nginx -n NAME
kubectl get all -n NAME
kubectl get pods -A
## OVS Deployment
# Creating configmap
kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/app-configmap.yaml -n NAME
kubectl get configmap -n NAME
kubectl describe configmap ovs-config -n NAME
kubectl get configmap ovs-config -o yaml -n NAME
# Postgres Password: echo -n 'password' | base64
kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/db-config.yaml -n NAME
kubectl get secret -n NAME
kubectl describe secret postgres-config -n NAME
kubectl get secret postgres-config -o yaml -n NAME
# Postgres deployment with clusterip
kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/postgres-db.yaml -n NAME
kubectl get all -n NAME
kubectl describe svc postgres -n NAME
# Deployment - adminer
kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/adminer.yaml -n NAME
kubectl get all -n NAME
kubectl describe svc adminer -n NAME
curl node3:NODEPORT
Open link http://54.215.208.140:NODEPORT
# Deployment - ovs
kubectl create -f https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/ovs-app.yaml -n NAME
kubectl get all -n NAME
kubectl logs ovs-####-###### -n NAME
kubectl get pods -o wide -n NAME
kubectl get svc ovs -n NAME
curl node3:NODEPORT
Open link http://54.215.208.140:NODEPORT/swagger-ui.html
# PV and PVC
mkdir ~/NAME
cd ~/NAME
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/postgres-storage.yaml
sed -i 's/NAME/jai/g' postgres-storage.yaml ### replace jai with your name
cat postgres-storage.yaml
kubectl create -f postgres-storage.yaml
kubectl get pv
kubectl get pvc -n NAME
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ovs/postgres-db-storage.yaml
sed -i 's/NAME/jai/g' postgres-db-storage.yaml ### replace jai with your name
cat postgres-db-storage.yaml
kubectl replace -f postgres-db-storage.yaml -n NAME
kubectl get pods -o wide -n NAME | grep postgres
ssh NODENAME "sudo ls /mnt/data/NAME"
## Monitoring
wget https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/v0.10.0.tar.gz
tar xvfz v0.10.0.tar.gz
cd kube-prometheus-0.10.0/
kubectl create -f manifests/setup
kubectl create -f manifests/
kubectl get pods -n monitoring -o wide | grep grafana
curl POD-IP-ADDRESS:3000
kubectl --namespace monitoring patch svc grafana -p '{"spec": {"type": "NodePort"}}'
kubectl get svc --namespace monitoring | grep grafana
curl CLUSTER-IP:3000
curl node2:NODEPORT
Open Grafana http://Public-IP-Node:NODEPORT
User: admin Password: admin
You can import kubernetes dashboard: https://grafana.com/grafana/dashboards/15757-kubernetes-views-global/
## Add a node to the cluster
sudo hostnamectl set-hostname INSTANCE-NAME
# refresh your session
wget https://raw.githubusercontent.com/Jaibw/docker/main/install_k8s_worker_ubuntu_20.04.sh
sh install_k8s_worker_ubuntu_20.04.sh
sudo kubeadm join 172.31.26.230:6443 --token v3t4po.sb80f2rr6jb1tf9e --discovery-token-ca-cert-hash sha256:a223781a3ee9cf383f6c162f8b6c675203a498d93fe205da0a39d43fbd3ab34d
## Remove node from cluster
master> kubectl get nodes
master> kubectl drain NODE-NAME --delete-local-data --ignore-daemonsets
master> kubectl get nodes
master> kubectl get pods -o wide
master> kubectl cordon NODE-NAME
master> kubectl delete node NODE-NAME
master> kubectl get nodes
## EKSCTL
sudo apt update
sudo apt install awscli
aws confiure
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
sudo apt -y install curl apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt -y install vim git curl wget kubectl=1.20.15-00
kubectl version --client
eksctl version
eksctl create cluster --name demo01 --region us-west-1
mkdir ~/.kube
aws eks update-kubeconfig --region us-west-1 --name demo01
kubectl get nodes
## Loadbalancer demo
controller> mkdir ~/NAME
controller> cd ~/NAME
controller> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/loadbalancer-demo.yaml
controller> sed -i 's/username/NAME/g' loadbalancer-demo.yaml
controller> cat loadbalancer-demo.yaml
controller> kubectl get all
controller> kubectl create -f loadbalancer-demo.yaml
controller> kubectl get all
controller> kubectl describe pod web-NAME-####-####
controller> kubectl describe svc web-NAME
controller> kubectl get svc web-NAME
Open link http://######.us-west-1.elb.amazonaws.com/
## Ingress demo
controller> mkdir ~/NAME
controller> cd ~/NAME
controller> wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/k8s/ingress-demo.yaml
controller> sed -i 's/username/NAME/g' ingress-demo.yaml
controller> cat ingress-demo.yaml
controller> kubectl create -f ingress-demo.yaml
controller> kubectl get all | grep NAME
controller> kubectl get ingress | grep NAME
Open link http://a1de81a94f6184a68a5b4c572b44dbeb-1f8388d56e3c7df0.elb.us-west-1.amazonaws.com/NAME
## Apache Kafka using Docker Compose
wget https://raw.githubusercontent.com/Jaibw/docker-v1/master/docker-compose/apache-kafka.yaml
mv apache-kafka.yaml docker-compose.yml
docker-compose up -d
docker exec broker kafka-topics --bootstrap-server broker:9092 --create --topic quickstart
docker exec --interactive --tty broker kafka-console-producer --bootstrap-server broker:9092 --topic quickstart
# type the message and press Ctrl + D to exit
docker exec --interactive --tty broker kafka-console-consumer --bootstrap-server broker:9092 --topic quickstart --from-beginning
# wait for some time and press Ctrl + C to exit
docker-compose down
## Install OpenShift
wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
tar xvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
cd openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/
sudo mv oc kubectl /usr/local/bin/
cd ~
oc version
docker stop `docker ps -q`
docker rm `docker ps -qa`
docker system prune --all
docker volume prune
sudo vim /etc/systemd/system/multi-user.target.wants/docker.service
## Update … dockerd --insecure-registry=172.30.0.0/16 …
sudo systemctl daemon-reload
sudo systemctl restart docker
oc --help
oc cluster up
oc login -u system:admin
docker images
docker ps
docker ps | grep redis
oc new-app --docker-image=registry.hub.docker.com/library/redis --name=redis
oc get pods
oc get svc
docker ps | grep redis