Skip to content

Latest commit

 

History

History
252 lines (146 loc) · 11.7 KB

101-7.md

File metadata and controls

252 lines (146 loc) · 11.7 KB

Kubernetes Cluster Overview

Node Types in Kubernetes Cluster

1. Master Nodes

The master node hosts the control plane components, which are responsible for managing the cluster and orchestrating its operations.

API Server

  • Provides the Kubernetes API, the primary interface for interacting with the cluster.
  • Processes RESTful API requests, performs authentication and authorization, and updates the cluster state stored in etcd.

Scheduler

  • Assigns pods to nodes based on resource requirements, node constraints, and other factors specified in the pod's configuration.
  • Ensures pods are scheduled onto suitable nodes within the cluster.

Controller Manager

  • Includes various controllers responsible for managing different aspects of the cluster's state and performing reconciliation loops.
  • Examples of controllers: Replication Controller, ReplicaSet Controller, Endpoint Controller.

There are many different types of controllers. Some examples of them are:

  • Node controller: Responsible for noticing and responding when nodes go down.
  • Job controller: Watches for Job objects that represent one-off tasks, then creates Pods to run those tasks to completion.
  • EndpointSlice controller: Populates EndpointSlice objects (to provide a link between Services and Pods).
  • ServiceAccount controller: Create default ServiceAccounts for new namespaces.

etcd

  • A distributed key-value store that serves as the cluster's backing store for all persistent data.
  • Stores the cluster's configuration data, state information, and metadata about objects such as pods, services, and nodes.

2. Worker Nodes

Worker nodes (also known as worker or minion nodes) are responsible for running the actual workloads, including containers/pods.

Runtime

  • The container runtime, such as Docker or containerd, runs containerized applications within pods on the worker node.
  • Manages the lifecycle of containers, including image downloading, container creation, starting, stopping, and deleting.

Kubelet

  • An agent that runs on each worker node, responsible for managing containers, pods, and their associated resources.
  • Communicates with the Kubernetes API server to receive instructions about pod deployment, management, and health monitoring.

kube-proxy

  • A network proxy that runs on each worker node, responsible for implementing Kubernetes networking services.
  • Maintains network rules on nodes and performs network address translation (NAT) for pods to ensure proper routing within the cluster.

Key Components of Kubernetes

Pod

A Kubernetes pod is a collection of one or more Linux® containers and is the smallest unit of a Kubernetes application. Pods share volume and network resources and specify how to run the containers.

Deployment & ReplicaSet

ReplicaSet

  • Ensures a specified number of pod replicas are running at any given time.

Deployment

  • Manages ReplicaSets and Pods.
  • Provides declarative updates to pods and ReplicaSets, ensuring a specified number of pods are running at any given time.
  • Offers features like scaling, rolling updates, and rollback functionality.

Namespaces

namespaces provide a mechanism for isolating groups of resources within a single cluster. Names of resources need to be unique within a namespace, but not across namespaces. Namespace-based scoping is applicable only for namespaced objects (e.g. Deployments, Services, etc.) and not for cluster-wide objects


DaemonSet

A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created.

Some typical uses of a DaemonSet are:

  • running a cluster storage daemon on every node
  • running a logs collection daemon on every node
  • running a node monitoring daemon on every node

ReplicaSet vs DaemonSet

ReplicaSet: Ensures a specified number of Pod replicas are running at any given time.

DaemonSet: Ensures that a copy of a specific Pod runs on all (or some) nodes in the cluster.


Jobs and CronJob

Jobs

A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created. Suspending a Job will delete its active Pods until the Job is resumed again.

A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot).

You can also use a Job to run multiple Pods in parallel.

CronJob

A CronJob creates Jobs on a repeating schedule.

CronJob is meant for performing regular scheduled actions such as backups, report generation, and so on. One CronJob object is like one line of a crontab (cron table) file on a Unix system. It runs a Job periodically on a given schedule, written in Cron format.


ConfigMaps & Secrets

ConfigMap

A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.

A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.

  • Use a ConfigMap for setting configuration data separately from application code.

Secrets

A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a Pod specification or in a container image. Using a Secret means that you don't need to include confidential data in your application code.

Because Secrets can be created independently of the Pods that use them, there is less risk of the Secret (and its data) being exposed during the workflow of creating, viewing, and editing Pods. Kubernetes, and applications that run in your cluster, can also take additional precautions with Secrets, such as avoiding writing sensitive data to nonvolatile storage.

You can use Secrets for purposes such as the following:

Set environment variables for a container. Provide credentials such as SSH keys or passwords to Pods. Allow the kubelet to pull container images from private registries.

  • ConfigMaps: Typically used to store configuration data, such as environment variables.
  • Secrets: Store sensitive data, such as passwords and API keys.

StatefulSets

A StatefulSet is a special type of workload object used to manage stateful applications. Unlike Deployments, which are designed for stateless applications, StatefulSets are used when the application requires stable, unique network identities, persistent storage, and ordered deployment, scaling, and updates.

Using StatefulSets StatefulSets are valuable for applications that require one or more of the following.

  • Stable, unique network identifiers.
  • Stable, persistent storage.
  • Ordered, graceful deployment and scaling.
  • Ordered, automated rolling updates.

Pod Management Policies StatefulSet allows you to relax its ordering guarantees while preserving its uniqueness and identity guarantees via its .spec.podManagementPolicy field.

OrderedReady Pod Management OrderedReady pod management is the default for StatefulSets. It implements the behavior described above.


Volumes

In a Kubernetes cluster, files in a container are considered short-lived. If the pod is gone, the data it had is also gone. Kubernetes volumes solve this problem. A volume is a directory accessible to the containers in a pod, and the data in the volume will persist regardless of what happens to the containers.

Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)

  • Persistent Volume (PV): A piece of storage in the Kubernetes cluster.
  • Persistent Volume Claim (PVC): A request for storage by a user.

Services

A Service is an abstraction layer that defines a logical set of Pods and a policy by which to access them. Services enable decoupling of the network connectivity from the lifecycle of Pods. There are different types of Services in Kubernetes, each serving a specific purpose.

Key Concepts

  • Selectors: Services use label selectors to identify the set of Pods they should forward traffic to.
  • Endpoints: A Service creates a list of endpoints that it maps to the selected Pods.

Purpose

Kubernetes Services provide a stable endpoint (IP address and DNS name) to access one or multiple Pods.


K8s Versions

version number follows the Semantic Versioning (SemVer) convention, which consists of three parts:

major.minor.patch.

Major version

Indicates a major release that includes significant changes or new features that might be incompatible with previous versions. A change in the major version suggests breaking changes that could potentially require modifications to your existing deployments or configurations.

Minor version (5):

Denotes a minor release that adds new functionality or features in a backward-compatible manner. It might also include improvements and enhancements, but without breaking the existing functionality.

Patch version (8):

Represents a patch release that typically includes bug fixes, security patches, or other minor updates that are backward-compatible. These changes are intended to improve the stability and performance of the existing features without adding new functionality.

So, version 2.5.8 of Kubernetes can be broken down as:

2: Major version, indicating significant changes or potential incompatibility with previous major versions.
5: Minor version, indicating backward-compatible new features and improvements.
8: Patch version, indicating backward-compatible bug fixes and minor updates.

Keep Up with Updates:

  • Regularly update your Kubernetes components to benefit from the latest features, performance improvements, and security patches. Delaying updates can expose your cluster to known vulnerabilities and compatibility issues.

Kubernetes Ports and Objects

Port Object Description
6443 API Server Kubernetes API server listens on this port for API requests from kubectl, other components, and external clients.
2379 etcd etcd server client requests (cluster store).
2380 etcd etcd server peer communication (used for clustering).
10250 Kubelet Kubelet API (for communicating with the API server).
10255 Kubelet (Read-Only) Read-only Kubelet API (deprecated, use 10250 instead).
10257 Kube Controller Manager Kubernetes controller manager listens on this port for secure communication.
10259 Kube Scheduler Kubernetes scheduler listens on this port for secure communication.
10256 Kube Proxy Kube proxy metrics (for monitoring and debugging).
10254 Ingress Controller Default port for health checks for NGINX ingress controller.
30000-32767 NodePort Services Ports used by NodePort services to expose applications outside the cluster.

Note: Ports may vary depending on the specific configuration and the chosen networking solution.


Resource Limitations

Requests and Limits

  • Request: The amount of resources that will get reserved for you.
  • Limit: The amount of resources that will get limited to and can't take more.