Kubernetes Notes 15 Oct 2023
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
https://www.devopsschool.com/blog/?s=kubernetes
Kubernetes
=================================
What is Kubernetes?
-----------------------------------
Orch tool for Container
Dev in Go
FREE and OS
mgmt by cncf
1.27
===================================
Why Kubernetes?
-----------------------------------
-> Computing
-> storage
- net
- lb
- dns
- db
- monitoing
- cert
====================================
Container
=================
Why we use AWS? - Write in 5 Pages
-> Computing
-> storage
- net
- lb
- dns
- db
- monitoing
- cert
==================================
VMS
===========================================================
How it works?
===========================================================
YOU --------> COntrol Plane ------> Worker Node(S)
------------------
Master node VMS
Workstation================================================
k8 Cluster
How to setup COntrol Plane?
Executable
-------------------------
Kubelet - Agent running in each node
kubeadm - K8 Admin tool
kubectl - k8 client
Docker - container
CNI - networking
apps
-------------------------
API server ======> 100s of api == 100s of feature
Controller mgr === Monitor k8 cluster and updte api
Schedualr = Schedule work to Worker
eTCD - PS
Proxy - Networking
CoreDNS - DSN and DIscovery
API --> URL -----> APP C -> PUT
R - GET
U - POST
D - DELETE
How to Setup Worker Node>
Executable
-------------------------
Kubelet
kubeadm
kubectl
Docker
CNI
apps
-------------------------
Proxy
How to Setup Workstation?
------------------------
kubectl
======================================================================================
What is POD?
============================================
AWS
VMS EBS|eFS|S3 RDS|DB LB ASG DNS
K8
POD volume Service Service Deployment DNS
Compute Unit
---Contains COntainers
s===============================
Workstation + Master Worker
=================== ======================
1 2
===========================================================
PS -----> VMS--> AWS ----> Container -----> Kuber
How to request APIserver for API resources
Namespace
POD
Deployment
Services
FORUMLA
C
YAML
create -f yaml
CMD
create
R
YAML
get -f yaml
CMD
get
U
YAML
apply -f yaml
CMD
edit
D
YAML
delete -f yaml
CMD
delete
Troubleshooting and Debugging Commands:
describe Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
cp Copy files and directories to and from containers
docker logs
docker attach
docker exec
docker -p
docker cp
proxy Run a proxy to the Kubernetes API server
auth Inspect authorization
debug Create debugging sessions for troubleshooting workloads and nodes
kubectl port-forward --address 0.0.0.0 pod/rajesh 8888:80
apiVersion: v1
kind: Pod
metadata:
name: rajesh
labels:
app: helloworld
spec:
containers:
- name: devopsschool1
image: scmgalaxy/nginx-devopsschoolv1
ports:
- name: nginx-port
containerPort: 80
1 clear
2 cd
3 git clone https://github.com/certifications-tutorials/cks-course-environment/
4 cd cks-course-environment/
5 clear
6 ls
7 cd cluster-setup/
8 ls
9 cd latest/
10 ls
11 chmod 755 install_master.sh
12 ./install_master.sh
13 clear
14 cd
15 clear
16 ls
17 kubectl get nodes
18 kubectl get pods --all-namespaces
19 ckear
20 clear
21 kubectl
22 clear
23 kubectl get nodes
24 kubectl
25 kubectl api-resources
26 clear
27 kubectl get ns
28 kubectl get pods -n=kube-system
29 kubectl
30 clear
31 kubectl get ns
32 kubectl create ns dev
33 kubectl get ns
34 kubectl edit ns dev
35 kubectl get ns
36 kubectl get ns --show-lables
37 kubectl get ns --show-labels
38 clea
39 clear
40 history
41 kubectl delete ns dev
42 kubectl get ns
43 clear
44 kubectl api-resources
45 clear
46 kubectl api-resources | grep ns
47 clear
48 ls
49 cd
50 vi pod.yaml
51 kubectl get pods
52 kubectl get pods -n=dev
53 kubectl create -f pod.yaml
54 kubectl get pods -n=dev
55 kubectl get pods
56 kubectl get ns
57 kubectl create ns dev
58 clear
59 kubectl get ns
60 kubectl create -f pod.yaml
61 kubectl create -f pod.yaml -n=dev
62 clear
63 kubectl get pods
64 kubectl get pods -n=dev
65 vi pod.yaml
66 kubectl get pods --show-labels
67 kubectl apply -f pod.yaml
68 kubectl get pods --show-labels
69 history
70 clear
71 kubectl api-resources
72 clear
73 kubectl api-resources
74 clear
75 kubectl get pods
76 kubectl edit pod rajesh
77 kubectl delete -f pod.yaml
78 kubectl get pods
79 kubectl create -f pod.yaml
80 kubectl get pods
81 kubectl get pods -o wide
82 kubectl describe pod rajesh
83 clear
84 ls
85 clear
86 lsw
87 cler
88 clear
89 kubectl
90 clear
91 kubectl get pods
92 kubectl describe pod rajesh
93 clear
94 kubectl logs rajesh
95 kubectl get pods -o wide
96 curl http://192.168.1.4
97 kubectl logs rajesh
98 curl http://192.168.1.4
99 kubectl logs rajesh
100 kubectl attach rajesh
101 cler
102 clear
103 kubectl exec rajesh ls
104 kubectl exec -it rajesh /bin/bash
105 cler
106 clear
107 kubectl port-forward -h
108 clear
109 kubectl port-forward --address 0.0.0.0 pod/rajesh 8888:80
110 clear
111 ls
112 kubectl cp pod.yaml rajesh:/tmp
113 kubectl exec rajesh ls /tmp
114 history
=================================================================
PS VM Cont POD
====================================================================
PID1 PID1 PID1 Container ---RESTART
========================================================================
Deployment
Service
==============================================================
Deployment
=================================================
Replication
Controller
Versioning
v1
v2
Rollout
Rollback
kubectl create deployment my-dep --image=scmgalaxy/nginx-devopsschoolv1 --replicas=10
kubectl scale --replicas=3 deployment/my-dep
kubectl rollout undo deploy/my-dep --to-revision=1
113 kubectl exec rajesh ls /tmp
114 history
115 clear
116 kubectl get pods
117 vi pod.yaml
118 kubect apply -f pod.yaml
119 kubectl apply -f pod.yaml
120 kubectl get pods
121 kubectl describe pod rajesh
122 kubectl get pods
123 clear
124 history
125 kubectl
126 kubectl uncordon -h
127 clear
128 kubectl
129 clear
130 kubectl get pods
131 cleaer
132 clear
133 ls
134 kubectl
135 clear
136 kubectl create -h
137 clear
138 kubectl create deploy -h
139 clear
140 kubectl get depoy
141 kubectl get deploy
142 kubectl create deployment my-dep --image=scmgalaxy/nginx-devopsschoolv1 --replicas=10
143 kubectl get deploy
144 kubectl get pods
145 clear
146 ls
147 kubectl get pods
148 kubectl edit deploy my-dep
149 kubectl get pods
150 kubectl get pods -o wide
151 kubectl describe pod my-dep-7d597cfb66-27bck
152 clear
153 ls
154 kubectl get pods -o wide
155 kubectl scale
156 kubectl scale -h
157 clear
158 kubectl scale --replicas=3 deployment/my-dep
159 kubectl get pods -o wide
160 clear
161 kubectl get pods -o wide
162 ls
163 clear
164 kubectl get pods -o wide
165 kubectl delete pod my-dep-7d597cfb66-6tcpn my-dep-7d597cfb66-fp8h9 my-dep-7d597cfb66-rw9lw
166 kubectl get pods -o wide
167 kubectl rollout -h
168 kubectl rollout history deploy/my-dep
169 clear
170 kubectl get pods -o wide
171 curl http://192.168.1.27
172 kubectl scale --replicas=30 deployment/my-dep
173 cler
174 clear
175 kubectl get pods -o wide
176 clear
177 kubectl get pods -o wide
178 clear
179 kubectl get pods -o wide
180 clear
181 kubectl rollout history deploy/my-dep
182 kubectl rollout status deploy/my-dep
183 kubectl edit deploy/my-dep
184 kubectl rollout history deploy/my-dep
185 kubectl rollout status deploy/my-dep
186 clear
187 kubectl rollout history deploy/my-dep
188 kubectl get pods -o wide
189 curl http://192.168.1.70
190 clear
191 kubectl rollout -h
192 kubectl rollout undo -h
193 clear
194 kubectl rollout history deploy/my-dep
195 kubectl rollout undo deploy/my-dep --to-revision=1
196 kubectl get pods -o wide
197 clear
198 kubectl get pods -o wide
199 kubectl get pods -o wide \
200 kubectl get pods -o wide
201 curl http://192.168.1.94
202 history
=============================================
versioning
OPT1 k8
deploy 1.1 git 1
1.2 2
1.3 3
Service
==========================================================
=== LB
==== NETWROK LB
--------------------------------------------------
BALANCE POD
kubectl expose deployment my-dep --port=8000 --target-port=80
CLustor --> NodePort
kubectl patch service rj -p '{"spec": {"type": "NodePort"}}'
======================================================================
COMPUTER - pod - deploy
Discovery - service
Storage --- pv - pvc - sc
A n A ---> role crle rolebing sa, '
-- secret, configmap
------------
job
cronjobs
203 clear
204 kubectl get pods -o wide
205 clear
206 kubectl get svc
207 kubectl expose -h
208 clear
209 kubectl expose deployment my-dep --port=80 --target-port=8000
210 kubectl get svc
211 kubectl describe svc my-dep
212 curl http://10.104.95.0
213 curl http://10.104.95.0:8000
214 clear
215 kubectl expose deployment my-dep --port=8000 --target-port=80
216 kubectl expose deployment my-dep --port=8000 --target-port=80 --name rj
217 kubectl get svc
218 curl http://10.102.201.238:8000
219 kubectl patch service rj -p '{"spec": {"type": "NodePort"}}'
220 kubectl get svc
221 curl http://10.102.201.238:8000
222 clear
223 kubectl api-resources
224 history
Opt 1 ----> minikube
https://www.devopsschool.com/blog/?s=minikube
Opt 2 - 2 VM in laptop --- Ubuntu20
Kubernetes 1.23.6 Cluster Setup Master and Worker in Ubuntu 20.04
Opt 3 - EKS --- on aws
CUSTER == Multiple Node
each node
many pods
=================================================
k8
=================================================
40+
============================================================
AWS
VM -> EBS|EFS|RDS
K8
POD --> PV|PVC
Kubernetes PersistentVolume, PersistentVolumeClaim, volume using hostPath
Statefulness