K8s, also known as Kubernetes, is an open-source platform for managing containerized applications. It is developed by Google and managed by CNCF. Itβs a container orchestration system which functions by running all applications in containers so the system updates and patches wonβt affect the applications as well as put security layers in place.
Its used acorss industries such as :
- Devops
- Machine learning
- Etc..
To automate development,scalling and management of containerized applications
Internals
K8s manages multiple containers using an Object-based model .
Container: A isolated environnement where the the application resides and runPOD: Includes multiple Containers inside itNode: Consists of one or multiple PodsCluster: Includes multiple Nodes
Container
A container is an isolated environment that includes dependencies and resources for an application to run properly unlike virtual machines. Containers donβt include the kernel and use a host kernel, hence making them lightweight.
POD
In K8s, containers are part of a POD and there can be multiple Pods. The POD handles resources and communications of the containers. By default, containers in the same pod can communicate with each other. However, we can restrict that using an Network policies.
Node
There are 2 types of nodes in a K8s cluster
Master NodeWorker Node
Master Node
The master node hosts the K8s control plane which serves as a management layer for K8s and is made up of multiple system processes. It manages things such as activities within the cluster and the overall state of the cluster as well as Schedule workloads and makes sure a desired configuration is maintained.Control plane is a collection of system processes that manage the cluster such as :
Kube-Apiserver: Exposes the k8sAPI; runs on port6443Kube-Scheduler: Assigns Pods to nodes based on resources and constraints; runs on port10251Kube-Control-Manager: Runs controllers to maintain cluster state; runs on port 10252Cloud-Controller-Manger: Manages cloud specific integrationsEtcd: Distributed key-value store for cluster data (often runs as a Pod instead of a system process); runs on port2379(client) and2380(peer communication)
Worker Nodes
Worker nodes execute the actual applications, and they receive instructions from the master nodes and ensure the desired state is achieved.
NOTEWhen we install K8s on a system, it is considered a node.
Example graph of a worker node which includes 2 pods : 
Cluster
Everything in k8s runs inside the cluster (system process, nodes etc .) and the api acts as a gateway between the outside/inside environment unless something is deliberately exposed via services, for example.
Cluster graph
In the graph below is shown a cluster which includes a master node and multiple worker nodes (which include multiple pods. 
K8s API
API is an endpoint provided by an application, so the end user can send instructions to it. Itβs like a control panel for an application with pre-defined options. The API defines things such as :
- What a user will be able to control
- How it will be controlled
- Communication formats and rules
The kube-Apiserver is responsible for hosting K8s api, which is hosted on port 6443 and uses https. 
Objects
The API resource serves as an endpoint that houses a specific collection of api objects. In k8s api these objects include essential elements such as :
PodsServices- Etcβ¦
Operations
There are Operations that we can perform on the objects avaliable such as :
GETRetrieves information or list resourcesPOSTCreates a new ResourcePUTUpdates an existing ResourcePATCHApplies partial updates to a resource (changes)DELETERemoves a resource
Communication
We communicate with the API by sending an API Call and receiving an API Response. When we communicate with k8s api using a tool such as kubectl to list available pods, for example, it can look like this under the hood :
GET /api/v1/namespaces/default/pods HTTP/1.1
Host: <API-SERVER-IP>:6443
Authorization: Bearer <JWT-TOKEN>
Accept: application/jsonThe application receives the instructions and responds with the results .
{
"kind": "PodList",
"apiVersion": "v1",
"metadata": {"resourceVersion": "12345"},
"items": [
{
"metadata": {
"name": "nginx-pod",
"namespace": "default",
"uid": "a1b2c3d4"
},
"spec": {
"containers": [{"name": "nginx", "image": "nginx:latest"}]
},
"status": {
"phase": "Running",
"podIP": "10.244.0.2"
}
}
]
}NOTEWe donβt have to specifically use
kubectlin order to communicate with K8s api. We can also use tools such ascurlto do the same. What matters is the format of the request, authentication and client validation.
Authentication
K8s supports various methods for authentication, such as Client certificate and Bearer Tokens using authentication proxy or HTTP to verify userβs identity. Once the user is authenticated, K8s enforces authorization decisions using RBAC (Role-based access control). This technique involves assigning specific roles to Users/Groups or a process to determine which actions they can perform on which available resources.
Anonymous Requests
Every worker node in K8s runs a kubelet, a Mini-API usually on port 10250that accepts the request from the K8s API. In older k8s distributions (prev1.14), Kubelet is allowed anonymous access by default, meaning we can bypass the K8s api (Hence its verification and authentication rules) and directly communicate with a worker node. Any request made to the Kubelet without a valid client certificate is considered an anonymous request.
If anonymous access is allowed, it can be an issue because a user/process that can reach the kubelets APIcan make requests and receive responses which can reveal sensitive information.
Example of a request made to a kubelet to get list of pods using curl :
curl -k https://<NODE-IP>:10250/pods Anonymous request allows us to :
- List all pods
- Read container logs
- Bypassing K8s RBAC
- Cluster Reconnaissance
And if the kubelet is misconfigured to allow the exec feature anonymously, even RCE. To check if we are allowed to do remote code execution in a pod, we can use kubeletctl, a client for kubelet.
Setting up k8s
K8s can be deployed using various ways depending on our use case :
minikube: Provides a single node and is fast,lightweight and easy to reset.kubeadm: Can be used on both on premises or cloudEks/Aks: Cloud-managed k8s; no infrastructure management requiredK3s/k0s: Runs on low-power Devices
Requirements
K8s can be deployed on windows,linux or mac and require a container engine such as docker,containerd etc β¦
Minikube
We will utilize minikube to setup a local testing environment. Its perfect for personal use due to being lightweight and fast.
Installation
- We get the
minkubeimage
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64- Install it using
install
sudo install minikube-linux-amd64 /usr/local/bin/minikube- Execute
minikubeto start the cluster
minikube start --driver=dockerSetting up nginx
- Verify
minikubeis working usingkubelctl get podsand then we deploy nginx.
kubectl create deployment nginx --image=nginx:latest- Make it accessible
kubectl expose deployment nginx --port=80 --type=NodePort- Verify that nginx is running
minikube service nginx
Now we can simply go to the link provided in the results and see nginx web-server .



