Basic -- Kubernetes:

 

What is Kubernetes?

  • Answer: Kubernetes is an open-source container orchestration platform that automates deploying, scaling, and managing containerized applications. It provides tools for managing microservices, load balancing, automated scaling, and self-healing in production environments.

What are the main components of Kubernetes?

  • Answer: Kubernetes consists of the following main components:

    • Master Node: Controls the Kubernetes cluster, running the API server, scheduler, and controller manager.

    • Worker Nodes: Hosts the containers (pods), including the container runtime (like Docker), kubelet, and kube-proxy.

    • API Server: Exposes the Kubernetes API, which is the entry point for interactions with the cluster.

    • Scheduler: Assigns workloads (pods) to nodes based on resource availability.

    • Controller Manager: Ensures the desired state of the cluster (e.g., ensures that the number of pods running is the same as desired).

    • Etcd: A distributed key-value store that holds cluster configuration and state data.

    • Kubelet: Ensures that containers are running in a pod on the worker nodes.

    • Kube-proxy: Maintains network rules for pod communication within the cluster.

What is a Pod in Kubernetes?

  • Ans

    What is a Deployment in Kubernetes?

    • Answer: A Deployment is a Kubernetes resource used to manage stateless applications. It defines the desired state of a set of pods, ensuring that the correct number of replicas is running. Deployments handle updates, rollbacks, and scaling of the applications.


How does Kubernetes handle scaling?

  • Answer: Kubernetes offers both manual and automatic scaling:

    • Horizontal Pod Autoscaler (HPA): Automatically scales the number of pods based on CPU or memory usage or custom metrics.

    • Vertical Pod Autoscaler (VPA): Automatically adjusts the CPU and memory requests for individual pods.

    • Cluster Autoscaler: Adds or removes nodes to the cluster based on resource usage.

What is a Service in Kubernetes?

  • Answer: A Service is an abstraction that defines a logical set of Pods and a policy for accessing them. Kubernetes Services allow Pods to communicate with each other and expose applications to external traffic. Types of Services:

    • ClusterIP (default): Exposes the service within the cluster.

    • NodePort: Exposes the service on a static port on each node's IP.

    • LoadBalancer: Exposes the service externally via a cloud provider's load balancer.

    • ExternalName: Maps the service to a DNS name outside the cluster.

What is the difference between a ReplicaSet and a Deployment?

  • Answer: A ReplicaSet ensures that a specified number of pod replicas are running at any given time. A Deployment is a higher-level abstraction that manages ReplicaSets, providing additional features like rolling updates, rollbacks, and more. In most cases, you use Deployments instead of ReplicaSets directly.

What is a Namespace in Kubernetes?

  • Answer: A Namespace is a way to divide cluster resources between multiple users or applications. Namespaces provide isolation, enabling multiple teams to share the same cluster without interfering with each other’s resources. You can define resource quotas, access controls, and policies for each namespace.

What is Helm in Kubernetes?

  • Answer: Helm is a package manager for Kubernetes, allowing you to define, install, and manage Kubernetes applications using charts. A Helm chart is a collection of files that describe a set of Kubernetes resources. It simplifies the deployment of complex applications and makes them repeatable.

What is the difference between StatefulSet and Deployment?

  • Answer:

    • StatefulSet is used for managing stateful applications that require stable, unique network identifiers and persistent storage.

    • Deployment is for stateless applications where pods can be replaced freely and do not need stable identities or persistent storage.

What is a ConfigMap and a Secret in Kubernetes?

  • Answer:

    • ConfigMap: Stores non-sensitive configuration data as key-value pairs that can be accessed by Pods. It is suitable for application settings that are not sensitive.

Exactly! A ConfigMap in Kubernetes is used to store non-sensitive configuration data that can be referenced by applications running in Pods. It helps decouple configuration from application code, allowing you to change configurations without modifying the actual application itself.

Exactly! A ConfigMap in Kubernetes is used to store non-sensitive configuration data that can be referenced by applications running in Pods. It helps decouple configuration from application code, allowing you to change configurations without modifying the actual application itself.

Key Features of ConfigMap:

  1. Key-Value Pairs: ConfigMaps store data as simple key-value pairs. The keys are typically configuration options, and the values can be anything from application settings, environment variables, or file content.

  2. Decoupling Configuration: By using ConfigMaps, you can keep configuration separate from your application code. This makes it easier to modify configurations without needing to rebuild or redeploy your application.

  3. Accessing ConfigMaps: Pods can access the data stored in ConfigMaps in various ways:

    • As environment variables within the container.

    • Mounted as files inside the container (this is useful for configuration files).

    • As command-line arguments when starting the container.

  4. Not for Sensitive Data: Since ConfigMaps store plain-text configuration, they are not meant for sensitive data like passwords or tokens. For sensitive data, Kubernetes has a separate resource called Secrets.

    • Secret: Stores sensitive data such as passwords, tokens, and certificates, which are encrypted and made available to pods securely.


What is a DaemonSet in Kubernetes?

  • Answer: A DaemonSet ensures that a specific pod is running on every node in the cluster (or on selected nodes, based on labels). It is commonly used for logging, monitoring agents, or network proxies that need to run on every node.


What is ETCD ?

Etcd is a distributed, consistent key-value store that is primarily used to store configuration data, state information, and metadata for distributed systems. It is a core component of many distributed systems and orchestration tools, most notably Kubernetes.

Key features of Etcd:

  1. Distributed: Etcd runs on a cluster of machines (typically in odd-numbered configurations, like 3 or 5 nodes) to ensure high availability and fault tolerance. Data is replicated across the nodes in the cluster.

  2. Consistency: Etcd uses the Raft consensus algorithm to ensure that the data is consistent across all nodes in the cluster. This means that any change to the data is reflected in the entire cluster in a consistent way, even in the event of network failures or node crashes.

  3. Key-Value Store: Etcd stores data as key-value pairs, where keys are unique identifiers, and values can be any data associated with those keys. This simple structure makes it easy to store configuration data, service discovery information, and system state.

  4. Watch API: Etcd provides a "watch" API, allowing clients to subscribe to changes to specific keys or ranges of keys. This is useful in systems like Kubernetes, where services or pods need to be notified of changes to cluster state in real-time.

Use cases for Etcd:

  • Kubernetes: Etcd is the backing store for Kubernetes, holding the cluster state and configuration information such as pods, services, deployments, and secrets.

  • Service discovery: Etcd is often used to store metadata about available services in a system, allowing other components to discover them.

  • Configuration management: Etcd can be used to store and manage configuration data for distributed applications.

Why is it important?

Etcd is designed to be the source of truth in a distributed system, meaning that all nodes in the system rely on it for consistent, up-to-date data. Its strong consistency guarantees ensure that any changes to configuration or state data are immediately visible across the entire system, making it critical for managing the configuration of distributed application

Why is ETCD Called a distributed system ? 

Etcd is called "distributed" because it is designed to store data across multiple machines, or nodes, in a cluster. The key aspect of a distributed system is that it doesn’t rely on a single machine (or a single point of failure) to function. Instead, Etcd replicates its data across multiple nodes in the cluster, ensuring that the data is available even if some of the nodes fail.

In a distributed system like Etcd:

  1. Replication: The data is duplicated across different machines (nodes), so the system can survive failures.

  2. Fault tolerance: Even if some nodes go down, the system can still operate using the remaining nodes, allowing for continuous availability.

  3. Consistency: Etcd ensures consistency across all nodes, meaning that even though data is spread out, every node sees the same value when reading the data.

  4. Cluster coordination: Etcd is often used for tasks like service discovery, configuration management, and leader election, which require coordination between distributed components in a system.

The distributed nature allows Etcd to be highly available and reliable for use cases like Kubernetes, where it's critical to keep the cluster's configuration and state in sync across multiple machines.

Etcd is a distributed, consistent key-value store that is primarily used to store configuration data, state information, and metadata for distributed systems. It is a core component of many distributed systems and orchestration tools, most notably Kubernetes.

Key features of Etcd:

  1. Distributed: Etcd runs on a cluster of machines (typically in odd-numbered configurations, like 3 or 5 nodes) to ensure high availability and fault tolerance. Data is replicated across the nodes in the cluster.

  2. Consistency: Etcd uses the Raft consensus algorithm to ensure that the data is consistent across all nodes in the cluster. This means that any change to the data is reflected in the entire cluster in a consistent way, even in the event of network failures or node crashes.

  3. Key-Value Store: Etcd stores data as key-value pairs, where keys are unique identifiers, and values can be any data associated with those keys. This simple structure makes it easy to store configuration data, service discovery information, and system state.

  4. Watch API: Etcd provides a "watch" API, allowing clients to subscribe to changes to specific keys or ranges of keys. This is useful in systems like Kubernetes, where services or pods need to be notified of changes to cluster state in real-time.

Use cases for Etcd:

  • Kubernetes: Etcd is the backing store for Kubernetes, holding the cluster state and configuration information such as pods, services, deployments, and secrets.

  • Service discovery: Etcd is often used to store metadata about available services in a system, allowing other components to discover them.

  • Configuration management: Etcd can be used to store and manage configuration data for distributed applications.

Why is it important?

Etcd is designed to be the source of truth in a distributed system, meaning that all nodes in the system rely on it for consistent, up-to-date data. Its strong consistency guarantees ensure that any changes to configuration or state data are immediately visible across the entire system, making it critical for managing the configuration of distributed application

Services :

ClusterIP is a type of Kubernetes Service that provides a stable, internal IP address for communication between services within a Kubernetes cluster. It is the default service type in Kubernetes and is used when you want to expose a service internally within the cluster, but not to the outside world.

Key Characteristics of ClusterIP:

  1. Internal Access: A ClusterIP service is accessible only from within the Kubernetes cluster. It cannot be accessed directly from outside the cluster. It's useful for communication between Pods (applications or services running in the cluster).

  2. Virtual IP: When a ClusterIP service is created, Kubernetes assigns it a stable, virtual IP address (referred to as the ClusterIP). This IP address is used by other services or Pods in the cluster to communicate with the service.

  3. Load Balancing: Kubernetes automatically load-balances traffic across the Pods that are part of the service. This helps distribute the load among the available Pods and ensures that the service remains available even if some Pods fail.

  4. DNS Resolution: Kubernetes supports DNS-based service discovery. When you create a ClusterIP service, Kubernetes automatically creates a DNS entry for the service, which can be resolved by other Pods in the cluster using the service name.

Example Usage:

If you have multiple Pods running a web application (e.g., a backend service), you can create a ClusterIP service to ensure that all Pods are accessible under a single virtual IP. Other services in the same cluster can communicate with the web application via this virtual IP, rather than accessing individual Pods directly.

Example of a ClusterIP Service YAML Definition:


apiVersion: v1 kind: Service metadata: name: my-clusterip-service spec: selector: app: my-app ports: - protocol: TCP port: 80 # Port the service will expose targetPort: 8080 # Port the Pods are listening on type: ClusterIP # This makes it an internal service

Summary:

  • ClusterIP is ideal for services that are needed only within the cluster and do not require external exposure.

  • It's the default and most common service type in Kubernetes when inter-service communication is needed.

  • It enables DNS resolution and load balancing within the cluster, allowing Pods to communicate with each other effectively.

Comments

Popular posts from this blog

Delploy Cluster : Managed K8 & Self Managed K8

ctr | nerdctl | crictl

Deploy To Kubernetes with Jenkins GitOps GitHub Pipeline