Kubernetes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Basics of Kubernetes

What is Kubernetes?

Kubernetes, often abbreviated as K8s, is an open-source platform that helps manage and
automate the deployment, scaling, and operation of containerized applications.

It’s like having a conductor for an orchestra, making sure all the instruments (containers)
play in harmony to create a beautiful symphony (your application) without any manual
intervention

Automating Deployment
Management of Containerized Apps
Scaling

Note: It supports different infrastructure.

Kubernetes solves several key problems related to managing


containerized applications:

1. Scalability: It automatically scales applications up or down based on demand, ensuring


efficient use of resources.
2. High Availability: It ensures your application is always running by automatically
restarting failed containers and distributing them across multiple nodes.
3. Resource Management: It optimizes the use of hardware resources by efficiently
scheduling containers.
4. Deployment Automation: It simplifies the deployment process, allowing for continuous
integration and continuous deployment (CI/CD).
5. Self-Healing: It automatically replaces or reschedules containers that fail, ensuring
minimal downtime.
6. Load Balancing: It distributes network traffic evenly across all containers, ensuring no
single container is overwhelmed.

Architecture of Kubernetes

Node: A node is a worker machine that runs containerized applications. It can be either
physical machines or virtual machines, and they work together to form a cluster. Each node
contains the necessary services to run pods and is managed by the master components of
the Kubernetes control plane. Here are the key components of a node.
Pod: A pod is the smallest deployable unit. It can contain one or more containers that share
storage, network resources, and a specification for how to run the containers. Think of a pod
as a group of containers that work together and share the same environment.

Different Components of Kubernetes

Master Node / Control Plane

1. API Server: The main control center that handles all requests to the Kubernetes
cluster.
2. ETCD: The database that stores all the important data about the cluster.
3. Kube Controller: The manager that ensures everything in the cluster is running
smoothly and also responsible for managing the state of the cluster.
4. Scheduler: The planner that decides which node (computer) will run each new
container. It schedule the resource in Kubernetes Cluster.
5. Cloud Control Manager: The Cloud Controller Manager (CCM) in Kubernetes is part
of the control plane that integrates the cluster with cloud provider services. It handles
cloud-specific tasks like:
Node management (adding/removing cloud-based nodes)
Load balancer creation for external traffic
Route management for cross-node communication
Persistent volume management for cloud storage

Worker Node / Data Plane

1. Kubelet: An agent that ensures containers are running in a pod.


2. Kube-proxy: A network proxy that maintains network rules and handles communication
between pods and services.
3. Container Runtime: The software responsible for running containers, such as Docker.

Feature of Kubernetes

1. Automated Rollouts and Rollbacks: Kubernetes can automatically roll out changes to
your application or its configuration and roll back changes if something goes wrong.
2. Service Discovery and Load Balancing: It can automatically expose a container
using the DNS name or their own IP address and balance the load across multiple
containers.
3. Storage Orchestration: Kubernetes can automatically mount the storage system of
your choice, whether from local storage, public cloud providers, or network storage
systems.
4. Self-Healing: It restarts containers that fail, replaces and reschedules containers when
nodes die, and kills containers that don’t respond to user-defined health checks.
5. Secret and Configuration Management: Kubernetes lets you manage sensitive
information, such as passwords, OAuth tokens, and SSH keys, without rebuilding your
container images.
6. Batch Execution: It can manage batch and CI workloads, replacing failed containers if
desired.
7. Horizontal Scaling: Kubernetes can scale applications up and down automatically
based on CPU usage or other metrics.

Important Questions that usually asked in Interview


Question - 1

What is the difference between Docker and Kubernetes

Docker is a platform for building, packaging, and running containers. It enables


developers to create containerized applications, ensuring consistency across different
environments.
Kubernetes is a container orchestration platform. It manages large clusters of
containers (including those created by Docker), automating tasks like scaling,
networking, and deployment.

Question - 2

Architecture of Kubernetes

1. Control Plane (Master Node):

Manages the entire cluster and makes global decisions about scheduling and scaling

Key components:

API Server:
The main gateway for all Kubernetes operations. It processes REST requests from
users and internal components.
etcd:
The cluster’s database. It stores all configuration data and the current state of the
cluster.
Controller Manager:
Ensures the desired state of the system is maintained (e.g., keeping the correct
number of pods running).
Scheduler:
Decides which worker node to run each new pod on, based on resource
availability.
Cloud Controller Manager:
Connects Kubernetes with cloud services (e.g., load balancers, storage).

2. Data Plane (Worker Nodes:)

Run the application containers and report back to the control plane.

Key components:

Kubelet:
The agent on each worker node that ensures containers are running according to
the instructions from the control plane.
Kube-proxy:
Manages network rules for pods to communicate with each other and the outside
world.
Container Runtime (e.g., Docker, containerd):
Responsible for running the actual containers.

3. Pods:

The smallest unit of deployment in Kubernetes.


A pod typically runs one or more containers (like Docker containers). Pods are
where the actual application code runs.

Question - 3
What are the main difference between the Docker Swarm and Kubernetes?
Docker Swarm and Kubernetes are both container orchestration tools, but they have some
key differences in terms of functionality, scalability, and complexity:

Ease of Setup:
Docker Swarm: Easier to set up and configure.
Kubernetes: More complex and requires additional setup.
Scalability:
Docker Swarm: Suitable for small to medium clusters.
Kubernetes: Designed for large-scale, production environments.
Load Balancing:
Docker Swarm: Basic, automatic load balancing.
Kubernetes: Advanced load balancing with more control.
Storage:
Docker Swarm: Basic persistent storage support.
Kubernetes: Advanced storage management and dynamic provisioning.
Auto scaling:
Docker Swarm: No native auto scaling.
Kubernetes: Built-in auto scaling for pods and clusters.

Question - 4

What is the difference between Docker Container and a Kubernetes pod?

1. Definition:

Docker Container:
A lightweight, standalone executable package that includes everything needed to
run a piece of software (code, runtime, system tools, libraries). It's a single unit of
an application running in isolation.
Kubernetes Pod:
A higher-level abstraction that wraps one or more containers together. Pods
represent the smallest deployable unit in Kubernetes and manage multiple
containers as a single entity.

2. Scope:
Docker Container:
Refers to a single instance of a running container. It is isolated from other
containers and the host system.
Kubernetes Pod:
Can contain one or more tightly coupled containers that share the same network
and storage. Containers in the same pod can communicate easily with each other,
and they are always scheduled and deployed together.

3. Networking:
Docker Container:
Each container has its own network namespace and IP address.
Kubernetes Pod:
Containers within a pod share the same IP address and port space, allowing easy
communication between containers within the same pod.

4. Lifespan:
Docker Container:
Containers are created, run, and destroyed independently.
Kubernetes Pod:
Pods are ephemeral and can be automatically recreated if they fail or are
terminated, as part of Kubernetes’ self-healing capability.

5. Use Case:
Docker Container:
Ideal for running single, isolated microservices or applications.
Kubernetes Pod:
Used when multiple containers need to work together (e.g., a web server
container and a logging agent container) as part of the same application instance.

Question - 5
What is a namespace in Kubernetes ?
-> In Kubernetes, Namespace is a logical isolation of resources so that multiple project team
in a company can work on same Kubernetes cluster but each of them having dedicated
namespace so that no body interrupt the work of the other team or project.

Question - 6

What is the role of Kube proxy?


-> Kube-proxy is a key component in the Kubernetes architecture responsible for managing
network communication within the cluster. It runs on each worker node and enables
efficient networking for pods and services.

*Main Functions of Kube-proxy:

1. Service Routing:
Kube-proxy forwards traffic from external clients or other pods to the correct pod
by maintaining network rules and handling service-to-pod mapping.
2. Load Balancing:
When multiple pods are behind a service, kube-proxy ensures load balancing
across them, distributing incoming traffic evenly to avoid overloading any single
pod.
3. Network Rules Management:
It sets up iptables or IPVS (IP Virtual Server) rules to forward traffic to the correct
pod. This allows Kubernetes services to abstract a group of pods and present
them as a single IP.
4. Handling Cluster Networking:
Kube-proxy enables communication between different nodes and pods in the
cluster, managing networking for services across nodes.

Question - 7

What are the difference types of services within Kubernetes ?


-> There are four different types of services that a user can create.

1. ClusterIP Mode:
Purpose: Internal access only.
Use When: You want services to be reachable only within the cluster.
Example: An internal database service.
2. NodePort Mode:
Purpose: External access via a port on each node.
Use When: You need to access the service from outside the cluster by connecting
to any node’s IP and a specific port.
Example: Testing an application from outside the cluster.
3. LoadBalancer Mode:
Purpose: External access with load balancing.
Use When: You want to expose your service to the internet with automatic load
balancing.
Example: A production web application.
4. ExternalName Mode:
Purpose: Maps to an external service.
Use When: You need to refer to an external service using a DNS name.
Example: Accessing an external API or database.

In short:

Cluster IP = Internal access only.


Node Port = External access via a fixed port.
Load Balancer = External access with automatic load balancing.
External Name = Maps to an external DNS name.

Question - 8

What is the role of Kubelet?


Kubelet manages the containers that are scheduled to run on that node. It ensures that the
containers are running and healthy, and that the resources they need are available.

Kubelet communicate with the Kubernetes API server to get information about the containers
that should be running on the node, and then stars and stops the containers as needed to
maintain the desired state. It also monitors the containers to ensure that they are running
correctly, and restarts them if necessary.

The Kubelet is a crucial component of a Kubernetes cluster that runs on every worker node.
Its primary roles are:

1. Container Management:
Ensures that containers are running as specified in the Pod configurations. It
starts, stops, and maintains the desired state of containers.
2. Communication:
Regularly communicates with the Kubernetes API server to report the status of the
node and its pods. It receives instructions and updates from the control plane.
3. Pod Lifecycle Management:
Manages the lifecycle of pods on the node, including creating, updating, and
deleting pods based on the configurations provided.
4. Health Checks:
Performs health checks on containers and ensures they are running correctly. It
can restart containers if they fail.

Question - 9

You might also like