Cgroups
Cgroups
I/O for a group of processes. Think of it like a manager who ensures each team (processes) gets
the resources they need to work efficiently.
Cgroups:
Benefits:
In summary, cgroups help manage resources for groups of processes, ensuring efficient use and
preventing resource contention.
Container:
Containers are like lightweight, portable boxes that hold everything an application needs to run:
1. *Code*: The application itself
2. *Dependencies*: Libraries and frameworks required by the app
3. *Settings*: Configuration files and environment variables
- You pack everything the app needs into the container (box)
- The container is self-contained and portable
- You can move it to any environment (ship it to any server)
- The app runs consistently, regardless of the surrounding environment
Containers provide:
In summary, containers package apps and their dependencies into a portable, self-contained unit,
making it easy to develop, deploy, and manage applications consistently across different
environments.
1. _Easy to deploy_: Containers make it simple to move apps between environments (dev, test,
prod).
2. _Fast deployment_: Containers start up quickly, unlike virtual machines.
Containers make app development, deployment, and management easier, faster, and more
efficient!
CGroup:
Here's how a container communicates with the base OS kernel using cgroups:
1. *Container Runtime*: The container runtime (e.g., Docker, CRI-O) creates a new container
and associates it with a cgroup.
2. *Cgroup Creation*: The container runtime creates a new cgroup or uses an existing one, and
assigns it to the container.
3. *System Calls*: The container makes system calls to the kernel, requesting resources (e.g.,
CPU, memory, I/O).
4. *Cgroup Hooks*: The kernel checks the cgroup configuration and applies resource limits and
constraints.
5. *Resource Allocation*: The kernel allocates resources to the container based on the cgroup
settings.
6. *Monitoring and Enforcement*: The kernel monitors the container's resource usage and
enforces the cgroup limits.
a. Request resources
b. Get resource usage metrics
c. Set cgroup parameters
1. *System calls*: Containers use system calls to request resources and services from the kernel.
2. *Cgroup file system*: The kernel exposes cgroup configuration and metrics through a virtual
file system.
3. *Container runtime APIs*: Container runtimes provide APIs for containers to interact with the
kernel and cgroups.
By using cgroups, containers can efficiently communicate with the base OS kernel to manage
resources, ensuring efficient and secure resource allocation.
K8s
Here's an explanation of Kubernetes in layman terms, step by step, for each component:
*Step 1: Pods*
*Step 2: Deployments*
*Step 3: Services*
*Step 6: Namespaces*
*Step 7: Nodes*
- A Node is like a worker machine in your cluster.
- It runs Pods and provides resources like CPU and memory.
*Step 8: Clusters*
*Step 3: Pods*
*Step 5: Services*
*Step 7: Networking*
- The Control Plane is like the "air traffic control" of the cluster.
- It includes the Master Node, Deployments, and Services, working together to manage the
cluster.
*Master Node:*
*Worker Node:*
1. *Kubelet*: The "Pod Manager" - runs and manages Pods on the Worker Node.
2. *Kube-Proxy*: The "Network Agent" - handles networking for Pods.
3. *Container Runtime*: The "Container Engine" - runs containers (e.g., Docker).
4. *Pods*: The "Application Containers" - run your applications.
In simple terms:
- The Master Node is like the "brain" of the cluster, making decisions and controlling the cluster.
- The Worker Node is like the "hands" of the cluster, running the applications and providing
resources.
The Master Node components work together to manage the cluster, while the Worker Node
components work together to run the applications.
*What is CRI-O?*
CRI-O is a container runtime that helps Kubernetes manage containers. Think of it like a
"container engine" that runs your applications.
_Labels_
Labels are like "tags" or "keywords" that you attach to objects (like Pods or Nodes) in your
Kubernetes cluster. They help you organize and filter objects based on specific characteristics.
_Annotations_
Annotations are like "notes" or "comments" that you add to objects in your Kubernetes cluster.
They provide additional information about the object, but don't affect its behavior.
_Selectors_
Selectors are like "filters" that help you select objects based on their labels. You can use selectors
to:
Set-based Selectors are like "advanced filters" that allow you to select objects based on sets of
labels. You can use set-based selectors to:
- Match objects with any of the specified labels (e.g., "env=production" or "env=staging")
- Match objects with all of the specified labels (e.g., "env=production" and "app=nginx")
- Match objects with none of the specified labels (e.g., "env!=production")
In simple terms:
_Workloads_
Workloads are like "jobs" that you want to run in your Kubernetes cluster. They represent the
applications or tasks that you want to execute.
_Deployments_
Deployments ensure that your Workload is running correctly and can scale or update as needed.
_ReplicaSets_
ReplicaSets are like "teams" of identical Workloads. They ensure that a specified number of
replicas (copies) of a Workload are running at any given time.
Example: If you want to run 3 replicas of a web server, a ReplicaSet ensures that 3 copies are
always running, even if one fails.
In simple terms: