Kubernetes Overview
Tags: kubernetes, devops, containers, beginners
Published: 2024-01-19 14:50:03

#### What is Kubernetes?

Kubernetes (K8s) is an open-source container orchestration tool developed by Google. It facilitates the management of containerized applications across various deployment environments, including physical machines, cloud, and virtual machines.

_Problem Kubernetes Solves_:

The shift from monolith to Microservices involves encapsulating applications/services in multiple or thousands of containers, necessitating effective container management. Monoliths represent a single, large application, while Microservices break it down into smaller, independent services.

_Features of Orchestration Tools_:

- High availability or no downtime
- Scalability for optimal performance
- Disaster recovery with easy backup and restore

#### Kubernetes Architecture:

A Kubernetes cluster comprises at least one master node (virtual or physical) and several worker nodes. Key components in the master node include the API Server, Controller Manager, Scheduler, and Etcd for maintaining the cluster's current state.

Worker nodes run applications, and the virtual network enables communication between nodes.

_Main Kubernetes Components_:

**Node and Pod**:
- Node: Virtual or physical machine
- Pod: An abstraction of a container, with each pod typically containing a single application.
- Pods communicate using IP addresses and are ephemeral.

**Service**:
- A component with a permanent IP, ensuring consistency even if pods change. External services communicate externally, while internal services are the default type.

**Ingress**:
- Positioned before services, it creates a dedicated load balancer for Kubernetes, enhancing security. It allows the use of domains instead of IP-like numbers.

**ConfigMap and Secret**:
- ConfigMap: ConfigMaps in Kubernetes provide a means to inject configuration data into pods of an application.
- Secret: Similar to ConfigMap but used for storing sensitive data, encrypted for security.

**Volume**:
- Physical storage on local or remote machines, ensuring data persistence even if applications restart.

**Deployment**:
- A blueprint for 'my-app' pods, defining the number of replicas. Ideal for stateless apps, providing easy scalability.
 
_[Example of deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)_

```
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
```
**Distributed Systems and Containers**:

Replicating applications becomes simpler with permanent IPs, avoiding constant adjustments when pods change. Load balancing directs requests to less busy pods.

**Database Considerations**:

Databases, due to state/data, can't be replicated via deployment. StatefulSet, designed for stateful apps or databases, manages pods that can update data. Hosting databases outside the cluster is a recommended approach for consistency.



**References: **

[TechWorld with Nana](https://www.youtube.com/watch?v=s_o8dwzRlu4)

[kubernetes documentation ](https://kubernetes.io/docs/concepts/overview/#why-you-need-kubernetes-and-what-can-it-do)