> For the complete documentation index, see [llms.txt](https://notes.nomanaziz.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.nomanaziz.me/devops/orchestration/kubernetes/1.-main-k8s-components.md).

# 1. Main K8s Components

### Pod

* Smallest unit of K8s
* Abstraction over container
* Usually 1 application per Pod
* Each Pod gets its own IP address
* New IP address on re-creation
  * E.g, DB dies and new DB is created which will get new IP address

<figure><img src="/files/dawbb58oaU6mMF3ymKWs" alt=""><figcaption></figcaption></figure>

### [Service](/devops/orchestration/kubernetes/10.-k8-services.md) & [Ingress](/devops/orchestration/kubernetes/6.-k8s-ingress.md)

* Permanant IP address
  * Can be attached to each pod
* Lifecycle of Pod and Service are not connected
  * If Pod dies then service and its ip remains

#### External Service

* Service which is accessible externally using url
* Format of url is [http://ip:port](https://notes.nomanaziz.me/devops/orchestration/kubernetes/http:/ip:port)

#### Internal Service

* Service which should not be accessible externally
* Have same format of url [http://ip:port](https://notes.nomanaziz.me/devops/orchestration/kubernetes/http:/ip:port)

#### Ingress

* Solves the problem of having static ip, port and protocol assigned to external services
* Assigns a domain name and certificate to requests
* Acts as a reverse proxy&#x20;

<figure><img src="/files/CmqtYaNWloRauZDXuMa8" alt=""><figcaption></figcaption></figure>

### ConfigMap & Secret

#### ConfigMap

Problem :-

* Suppose DB url was configured inside my-app and its image was built and pushed to dockerhub
* Now, the DB url gets changed and image must be modified, rebuilt and pushed to dockerhub then pulled into pod and restart

Solution :-

* Thats where **ConfigMap** comes in, we can store such external configuration of our app and attach it to the pod.

<figure><img src="/files/UgZRTkNEokCRvBwyhcYb" alt=""><figcaption></figcaption></figure>

#### Secret

* Works to solve similar problem as ConfigMap
* ConfigMap stores configuration in plain text format so it should not be used to store secrets such as username, passwords, etc.
* Secret should be used instead
* Things are stored in base64 encoded format
* Built in security mechanism is not enabled by default

***

### [Volumes](/devops/orchestration/kubernetes/8.-k8-volumes.md)

* Used for data storage, same concept as docker since k8s does not manage data persistance
* Storage can be on **local** machine or **remote** storage outside of k8s cluster

***

### Deployment & [StatefulSet](/devops/orchestration/kubernetes/9.-k8-statefulset.md)

#### Deployment (Replication)

* Solves the problem of single point of failure
  * In case Pod dies
* We replication everything on another node for fault tolerance or load balancer
* Replica is connected to same service
* We don't create another pod but define **blueprint** for pods
* It is an abstraction layer on top of pods.
* In practice deployment is used instead of pods.
* **DBs can't be replicated via deployment**
  * Because database has a state
  * To avoid data inconsistencies
* **Should be used for StateLess apps**

#### StatefulSet

* Solves the DB replication problem of Deployment
* **Should be used for StateFul apps or Databases**
* Deploying StatefulSet is not easy
* DBs are often hosted outside of K8s cluster

<figure><img src="/files/RefpobjM9Wqt7R1GUy01" alt=""><figcaption></figcaption></figure>

#### Layers of Abstraction

<figure><img src="/files/u4UQzmsjvilB1G54WkZg" alt=""><figcaption></figcaption></figure>
