Junior
What is Kubernetes?
sobes.tech AI
Answer from AI
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, which simplifies both declarative configuration and automation. Essentially, it is a container orchestrator.
Key concepts of Kubernetes:
- Pods: The smallest deployable object, a group of one or more containers (most often Docker) that share network space, storage, and resources.
- Deployments: Declarative representation of Pods, allowing you to describe the desired state of an application and manage the lifecycle of Pods. Supports updates and rollbacks.
- Services: An abstraction that defines a logical set of Pods and access policies to them. Provides a stable IP address and DNS name for the group of Pods, even if Pods are created and destroyed.
- Namespaces: Virtual clusters within a physical cluster, used for logical resource isolation (Pods, Services, Deployments) and role-based access.
- ReplicaSets: Ensure that a specified number of Pod copies (replicas) are always running. Usually used indirectly through Deployments.
- StatefulSets: Designed for managing stateful applications (e.g., databases), providing stable network identities and persistent storage for Pods.
- Volumes: A way to provide persistent storage for Pods, retaining data even after the Pod is terminated or restarted.
Cluster architecture of Kubernetes:
- Control Plane (Master node):
kube-apiserver: Provides the Kubernetes API, the single entry point for interacting with the cluster.etcd: A distributed, consistent key-value store used for persistent cluster state storage.kube-scheduler: Responsible for assigning new Pods to available worker nodes.kube-controller-manager: Controllers managing various aspects of the cluster (e.g., replication, endpoints).cloud-controller-manager(optional): Interacts with the cloud provider to manage resources (e.g., load balancers, persistent volumes).
- Worker Nodes:
kubelet: An agent running on each worker node, responsible for interacting with the Control Plane and managing containers in Pods.- Container Runtime (e.g., Docker, containerd, CRI-O): Software responsible for running containers.
kube-proxy: A network proxy running on each node, maintaining network rules for Pods and Services, ensuring traffic routing.
# Example of a Deployment definition in Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
spec:
replicas: 3 # Run 3 instances of Pod
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: my-docker-registry/my-app:latest # Container image used
ports:
- containerPort: 80 # Port of the application inside the container
Kubernetes automates deployment, scaling, update management, and self-healing of containerized applications.