Kubernetes for Developers
Kubernetes for Developers
What is Kubernetes?
Kubernetes is an open-source platform designed to automate the
deployment, scaling, and management of containerized applications.
Containerization
Kubernetes is an extension of containerization, which focuses on
encapsulating an application and its dependencies into a container.
Container Runtime Examples:
Docker
CRI-O
Container-d
Containers
A container is an open-source application that includes everything needed
to run: code, runtime, system tools, and libraries.
Example of Virtual Machines (VMs):
VM Setup: Java Runtime, Operating System, Libraries, and
Application.
Microservices
Microservices is an architectural style where applications are built as a
collection of small, independent modules (services).
Advantages of Microservices:
1. Modules are independent and can be managed separately.
2. Communication between modules is facilitated through APIs or
inter-process communication.
Why Kubernetes?
Kubernetes serves as a container orchestration platform that manages:
1. Dying containers (automatic recovery).
2. Replication of containers to ensure high availability and scalability.
Minimum Requirements for Kubernetes Installation
8 GB RAM (minimum)
2 Nodes:
o Master Node: Handles the control plane.
o Worker Node: Executes the workloads.
Example Setup:
Total resources: 24 GB RAM divided as follows:
o 8 GB for VM 1
o 8 GB for VM 2
o 8 GB for VM 3
Minikube (Single-Node Kubernetes)
Minikube provides a single-node Kubernetes cluster for testing and
development purposes.
Minikube Requirements:
4 Cores
4 GB RAM
Suitable for Windows Professional (MicroK8s).
Steps to Install MicroK8s on Windows:
1. Check System Requirements:
o Open Task Manager and verify your system specifications.
2. Install WSL (Windows Subsystem for Linux):
o Open PowerShell as Administrator.
o Run the command:
wsl --install
3. Install MicroK8s:
o Use WSL to proceed with the MicroK8s installation.
MicroK8s provides a lightweight Kubernetes for local development and
testing environments.
Website go through Windows (Pro) https://microk8s.io/
Open-source Container Orchestration tool
Developed by GOOGLE
Trend from Monolith to Microservices
Increased usage of containers
Features do Orchestration tools offer: High Availability, Scalability,
Plaster
Pod: (Packaging of container)
Smallest unit of k8s
Abstraction over container
Usually 1 application per Pod
Each pod gets its own IP Address
New IP Adress on re-creation
Storage on local machine or remote
Master Node (Brain of the Kubernetes) – contain one file (one of the
Component) called as etcd (it decides where you create Pod)
Pod is created in worker Node that will be decided by the Master
Node(etcd)
Worker machine in KSs cluster
Kubelet is one of the component (SERVICE) communicate from
master node – worker node to create Pod
If you have replication (application in different areas) kubeproxy
came into the picture for communication
Service – manual
Volume
Etcd – master node
Kubelet
On Jan 24
Mini Kube
Microk8s - single node 8s cluster
Go to wsl
PS C:\Windows\system32> wsl
To run a command as administrator (user "root"), use "sudo
<command>".
See "man sudo_root" for details.
jyothi@JYOTHISI:/mnt/c/Windows/system32$
KUBERNETES: (K8’s)
Kubernetes is extension of containerization.
Kubernetes (often abbreviated as K8s) is an open-source platform
for managing and orchestrating containerized applications at scale. It
automates the deployment, scaling, and management of containers,
making it a powerful tool for modern cloud-native applications.
Container run times (worker machines):
1. Docker
2. Cri-o
3. Container-d
Kubernetes uses “container-d” as a run time.
Container is an open source
Main reason to choose Containers is flexibility.
MicroServices:
Application splits into a small and different modules.
Modules are independent and interconnected.
Instead of putting total web application into the container, it will be
divided as modulus and then stored in containers because if one
module crashes then the other modulus will not be crashed and
containers can’t store’s large amount of storage, so stored as
modules
Kubernetes is container orchestration/management
When we deploy containers into Kubernetes, it manages the
containers which are died then it replaces.
Kubernetes takes minimum 24gb data for installation (8gb for OS
and other GB for installation)
MiniKube – 1 node Kubernetes.
Requirement of installation of Kubernetes: 4 cores and 4gb ram
(check in Ur laptop at task manager) and windows 11 professional
version (check in settings>about) in laptop.
Requirement for Micro Kubernetes: cores:2, ram-4gb, windows prof
Microk8s – wsl win 11 home.
ARCHITECTURE OF KUBERNETES:
• Open-source container orchestrion tool
• Developed by google
• Helps you manage containerized applications
• In different deployment environments
• Trend from monolith (entire website relays on only one series
of code) to microservices, increased usage of containers.
• It also supports the local and remote modes
Features:
• High Availability
• Scalability
• Load balancing and Disaster recovery
• Extensibility
Pod:
Kubernetes uses the Pod concept where the container goes and saves
into the pod. (it’s better to put 1 container in 1 pod).
• Smallest unit of k8’s
• Abstraction over container
• Usually 1 application per pod
• Each pod gets its own IP
• New IP address on re-creation
• It’s a case of automatic IP address
Service:
• Manual/static IP address in Kubernetes is called as Service.
• Manual IP address doesn’t change on new re-creations.
• IP is a automatic IP address and service is a manual IP address
Volume:
It can be a local or remote storage
NODE:
A node can be a physical machine (bare metal) or a virtual machine
(e.g., AWS EC2, Google Compute Engine, or Azure VM).
Each node runs the essential services required to host and manage
containers.
Nodes communicate with the control plane to report their status and
receive instructions.
Node Types
Nodes in Kubernetes are classified based on their role:
a. Master Node
• Manages the Kubernetes cluster.
• Responsible for scheduling, orchestration, and state
management.
• Runs control plane components like API Server, Scheduler,
Controller Manager, and etcd.
• Typically, workloads (pods) are not run on the master node
unless explicitly allowed.
b. Worker Node
• Executes the actual workloads (containers in pods).
• Hosts applications and services that make up the Kubernetes-
managed system.
• Communicates with the master node to receive and run tasks.
Node Components:
1) Kubelet: Communication between master and worker node,
it’s a service, ensures that containers in a pod are running according
to the specifications provided by the control plane.
2) Kube Proxy: Implements network rules for communication
between worker to worker (pods and services)
3) Container run times:
In Kubernetes, Master Nodes and Worker Nodes are the two primary
roles in a cluster. Together, they form the architecture of Kubernetes
and ensure the efficient management of containerized workloads.
Master node is a brain of Kubernetes because ETCD presents in
master node.
Pods are created in a worker node.
ETCD:
Etcd is a distributed, consistent, and highly available key-value store
used by Kubernetes to store all its cluster state and configuration
data. It is an essential part of the Kubernetes control plane, as it acts
as the single source of truth for the cluster.
STEPS:
Go to windows->type as poweshell->right click ->run as
administrator->type commands as:
wsl –-install
# wsl (comes to linux)
# sudo snap install microk8s --classic (enter password of laptop
not pin)
// $ -> use sudo infront of any command in $ mode.
# wsl -u root
# microk8s start
# microk8s kubectl get nodes (status shows as ready)
// in above command, Microk8s is not part of kubernetes, it is just a
layer to use the Kubernetes.
// we can also replace the above command with this command ->
# alias kubectl=”microk8s kubectl”
// after using this command in place of the above microk8s
command from next command we don’t need to use the microk8s
before all the commands.
# kubectl get nodes
# kubectl get nodes -o wide // -o wide is only used with the get
command (it gives more information about when we use -o wide)
microk8s start
2 microk8s kubectl get nodes
3 alias kubectl="microk8s kubectl"
4 kubectl get nodes
5 kubectl get nodes -o wides
6 kubectl get nodes -o wide
7 microk8s enable dashboard
8 microk8s dashboard-proxy
9 microk8s start
10 micok8s kubectl get nodes
11 microk8s kubectl get nodes
12 alias kubectl="microk8s kubectl"
13 kubectl get nodes
14 kubectl get nodes -o wide
15 microk8s enable dashboard
16 microk8s dashboard-proxy
17 microk8s kubectl -n kube-system get deployments
18 microk8s kubectl -n kube-system describe deployment
kubernetes-dashboard
19 microk8s kubectl -n kube-system get pods
20 microk8s dashboard-proxy
21 microk8s start
22 alias kubectl="microk8s kubectl"
23 kubectl get nodes
24 kubectl get all
25 kubectl get nodes -o wide
26 microk8s enable dashboard
27 microk8s dashboard-proxy
28 microk8s inspect
29 microk8s disable dashboard
30 microk8s enable dashboard
31 microk8s kubectl -n kube-system get pods
32 microk8s kubectl -n kube-system delete deployment
kubernetes-dashboard
33 microk8s enable dashboard
34 microk8s kubectl -n kube-system get events --sort-
by=.metadata.creationTimestamp
35 microk8s stop
36 microk8s start
37 microk8s disable dashboard
38 microk8s kubectl delete ns kube-system
39 microk8s enable dashboard
40 clear
41 microk8s enable dashboard
42 microk8s dashboard-proxy
43 microk8s reset
44 snap remove microk8s
45 snap install microk8s --classic
46 microk8s start
47 microk8s kubectl get nodes
48 alias kubectl="microk8s kubectl"
49 kubectl get nodes
50 kubectl get nodes -o wide
51 microk8s enable dashboard
52 microk8s dashboard-proxy
53 microk8s enable dashboard
54 microk8s dashboard-proxy
55 microk8s start
56 microk8s kubectl get nodes
57 kubectl get nodes -o wide
58 microk8s kubectl get nodes -o wide
59 alias kubectl="microk8s kubectl"
60 kubectl get nodes
61 microk8s enable dashboard
62 microk8s dashboard-proxy
63 kubectl create deployement thub
64 kubectl create deployment thub
65 kubectl create deployment thub image=nginx
66 kubectl create deployment thub --image=nginx
67 kubectl get deployments
68 kubectl get deployments -o wide
69 kubectl get pods
70 kubectl get pods -o wide
71 kubectl get replicaset
72 kubectl get replicaset -o wide
73 kubectl get pods
74 kubectl describe pod
eyJhbG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OiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXR
lcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlL
XN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bn
Qvc2VjcmV0Lm5hbWUiOiJtaWNyb2s4cy1kYXNoYm9hcmQtdG9
rZW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3Nlc
nZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVyb
mV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2Nvd
W50LnVpZCI6ImUxZjM4Y2U0LTc5NjItNGM0MS1hZTUxLTMw
NzhlNzgxNjBlOCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3Vu
dDprdWJlLXN5c3RlbTpkZWZhdWx0In0.OMrBFANhhPB_ypkuS
Fl9BS1j29GuJBcsyxE8HH0yHo6XinCBVM4eTrWVtsIgiOAmmK
_MSac0h4_t53EqzlUHi2A5SFv4A8XWP-
dMwxx5YmMBKO8xRnXAQoGlW3Qhg3PFYohzlsZM-
eJH2gMFCkk32wf-
aTW7iFiTml8DDDRun55LoW8U_ok2X5cFZX-pphIAj-
0JH7MvqHqBfeV0pvxFXdLDU93FKN1bbqU8gWyvQJMpxd8aBh
KfKMU6YyICpa1nAuC5_R_TBI_FXpwD6ybj-
nC4KYlcD3BteFKH2Xym6ySTtg4FcEzvd5bitDtqwZm4VY_gnt-
97rkhSyZ1bcKT3g
78 kubectl describe deployment thub
79 systemctl kubectl create
80 kubectl version --client
81 kubectl create
82 systemctl kubectl create
83 kubectl edit deployment
84 kubectl get deployment thub
85 kubectl get replicaset
86 kubectl get pods
87 kubectl exec -it thub-94bb49d78-8kd8m --it -- /bin/bash
88 kubectl exec -it thub-94bb49d78-8kd8m -- it -- /bin/bash
89 kubectl exec -it thub-94bb49d78-8kd8m /bin/bash
90 kubectl exec -it thub-94bb49d78-8kd8m -- /bin/bash
91 kubectl edit deployment my-app
92 kubectl apply -f my-app-deplo.yaml
93 kubectl edir
94 kubectl edit
95 ls
96 systemctl kubectl create
97 cat my-app-deplo.yaml
98 kubectl get pods
99 kubectl edit deployment thub
100 clear
101 kubectl apply -f
https://k8s.io/examples/application/guestbook/redis-leader-
deployment.yaml
102 kubectl get pods
103 kubectl apply -f
https://k8s.io/examples/application/guestbook/redis-leader-
service.yaml
104 kubectl get service
105 kubectl apply -f
https://k8s.io/examples/application/guestbook/redis-follower-
deployment.yaml
106 kubectl get pods
107 kubectl apply -f
https://k8s.io/examples/application/guestbook/redis-follower-
service.yaml
108 kubectl get servic
109 kubectl get service
110 kubectl apply -f
https://k8s.io/examples/application/guestbook/frontend-
deployment.yaml
111 kubectl get pods -l app-guestbook -l tier-frontend
112 kubectl get pods -l app-guestbook -l tier=frontend
113 kubectl apply -f
https://k8s.io/examples/application/guestbook/frontend-service.yaml
114 kubectl get service
115 kubectl port-forward svc/frontend 8080:80
116 kubectl get pods
117 kubectl port-forward svc/frontend 8080:80
118 kubectl get pods
119 kubectl port-forward svc/frontend 8080:80
120 microk8s start
121 microk8s kubectl get nodes
122 alias kubectl="microk8s kubectl"
123 kubectl get nodes
124 kubectl get nodes -o wide
125 microk8s enable dashboard
126 microk8s dashboard-proxy
127 kubectl create deployment jyothi --image=nginx
128 kubectl get deployment
129 kubectl get deployment -o wide
130 kubectl get pods
131 kubectl get pods -o wide
132 kubectl get replicaset -o wide
133 kubectl describe deployment jyothi
134 kubectl get pod
135 kubectl describe pod jyothi-7766bb4988-v6299
136 kubectl get deployments
137 kubectl describe deployment jyothi
138 kubectl edit deployment jyothi
139 nano /tmp/kubectl-edit-2349766263.yaml
140 kubectl get pods
141 nano /tmp/kubectl-edit-2349766263.yaml
142 kubectl get pods
143 kubectl get replicaset
144 kubectl get pods
145 kubectl exec -it jyothi-7766bb4988-v6299 --/bin/bash
146 kubectl exec -it jyothi-7766bb4988-v6299 -- /bin/bash
147 ls
148 ld -l my*
149 cd /mnt/c/Users/jyoth/Downloads
150 ls
151 kubectl apply -f my-app-deplo.yaml
152 kubectl apply -f /mnt/c/Users/jyoth/Downloads/my-app-
deplo.yaml
153 kubectl get deployments
154 kubectl describe deployment my-app
155 kubectl get pods
156 kubectl get service
157 kubectl apply -f my-app-service.yaml
158 kubectl get service
159 kubectl apply -f my-app-ingress.yaml
160 kubectl get ingress
161 kubectl apply -f my-app.yaml
162 kubectl get ingress
163 kubectl describe node
164 kubectl get service
165 kubectl get pods
166 kubectl describe pod jyothi-7766bb4988-v6299
167 kubectl get deployment
168 kubectl get deployment s
169 kubectl get deployments
170 kubectl describe deployment jyothi
171 kubectl get services
172 kubectl describe service my-app-service
173 kubectl describe node
174 kubectl get pods
175 kubectl get service
---
## Prerequisites
## Steps
```bash
wsl --install
4. Once installed, launch WSL (which brings you into the Linux shell).
5. Type the following command to install MicroK8s:
sudo snap install microk8s --classic
(Enter the password of your laptop, not the PIN)
Conclusion
This guide showcases my recent accomplishment in deploying
Nginx using MicroK8s and Kubernetes. By following the above
steps, I was able to deploy, scale, and manage the Nginx application
while also utilizing various Kubernetes commands and YAML files
for configuration management.
### Instructions for Use:
This guide will walk you through the steps to deploy Nginx on
MicroK8s using Windows Subsystem for Linux (WSL) and
Kubernetes commands.
---
## Prerequisites
---
## Steps
```bash
wsl --install
4. Once installed, launch WSL (which brings you into the Linux shell).
5. Type the following command to install MicroK8s:
sudo snap install microk8s --classic
(Enter the password of your laptop, not the PIN)
Conclusion
This guide walked you through the steps to deploy Nginx using
MicroK8s, configure it using Kubernetes commands, and view the
application through the dashboard and browser. You can now
manage your Kubernetes resources with ease.