0% found this document useful (0 votes)
24 views6 pages

Kuber Net Es

This document provides an overview of Kubernetes, detailing its cluster components, configurations for deploying applications, and comparisons with Docker. It includes practical examples such as using Minikube for local testing, deploying stateless and stateful applications, and managing configurations with ConfigMaps and Secrets. The conclusion emphasizes Kubernetes' capabilities for scalable and high-availability application management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

Kuber Net Es

This document provides an overview of Kubernetes, detailing its cluster components, configurations for deploying applications, and comparisons with Docker. It includes practical examples such as using Minikube for local testing, deploying stateless and stateful applications, and managing configurations with ConfigMaps and Secrets. The conclusion emphasizes Kubernetes' capabilities for scalable and high-availability application management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Kubernetes Summary: Concepts and

Configurations

Contents
1 Introduction 1

2 Kubernetes Cluster Overview 2


2.1 Components of a Kubernetes Cluster . . . . . . . . . . . . . . . . . . . 2
2.2 Real-World Analogy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3 Kubernetes vs. Docker 2

4 Minikube Overview 3
4.1 Minikube with Docker . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4.2 Minikube Setup Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

5 Kubernetes Configuration 3
5.1 Deployments for Stateless Apps . . . . . . . . . . . . . . . . . . . . . . . 4
5.2 StatefulSets for Stateful Apps . . . . . . . . . . . . . . . . . . . . . . . . 4
5.3 Services for Exposing Pods . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.4 ConfigMaps and Secrets . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

6 Demo Project Structure 6


6.1 Project Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
6.2 Key Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

7 Troubleshooting Example 6

8 Conclusion 6

1 Introduction
This document summarizes the key theoretical concepts and configuration de-
tails about Kubernetes, as discussed in a conversation about setting up and un-
derstanding a Kubernetes cluster. It covers the structure of a Kubernetes cluster,
the role of its components, and practical configurations for deploying applica-
tions, with a focus on a demo project involving MongoDB and a web application.

1
2 Kubernetes Cluster Overview
A Kubernetes cluster is a group of computers (nodes) that work together to run
containerized applications, ensuring scalability, high availability, and efficient
resource management.

2.1 Components of a Kubernetes Cluster


• Master Node (Control Plane): The ”boss” that manages the cluster, han-
dling tasks like scheduling, scaling, and monitoring. It includes:

– API Server: Acts as the communication hub, accepting commands


from kubectl to manage the cluster.
– etcd: A key-value store that holds the cluster’s state (e.g., desired vs.
actual state of pods).
– Scheduler: Assigns pods to worker nodes based on resource availabil-
ity.
– Controller Manager: Ensures the desired state is maintained (e.g.,
creating new pods if one fails).

• Worker Nodes: The ”doers” that run the actual applications in containers.
Each worker node has:

– Kubelet: A process that communicates with the master node and man-
ages containers on the node.
– Container Runtime (e.g., Docker, containerd): Runs and manages
containers.
– Pods: The smallest deployable units, each containing one or more con-
tainers.

2.2 Real-World Analogy


Think of a Kubernetes cluster as a restaurant:
• Master Node: The head chef who plans the menu and assigns tasks.

• Worker Nodes: The cooks who prepare the food.

• Kubelet: The recipe book each cook follows, ensuring tasks are done cor-
rectly.

• Pods/Containers: The dishes being prepared, served to customers (users).

3 Kubernetes vs. Docker


• Docker: A tool for creating, running, and managing containers and images.
It lacks built-in features for high availability or scalability.

• Kubernetes: An orchestration platform that manages containers across


multiple nodes, providing:

2
– Scalability: Automatically adds/removes containers based on demand.
– High Availability: Restarts failed containers and ensures redundancy.
– Load Balancing: Distributes traffic evenly across containers.
– Distribution: Spreads containers across nodes to optimize resources.

4 Minikube Overview
Minikube is a tool for running a single-node Kubernetes cluster locally, ideal for
learning and testing. It can run inside a Docker container or a virtual machine
(e.g., VirtualBox).

4.1 Minikube with Docker


• Minikube uses Docker as the container runtime to run application contain-
ers.

• Alternatively, Minikube itself can run as a Docker container, hosting the


entire Kubernetes cluster (master + worker roles) within it.

4.2 Minikube Setup Steps


1. Install Prerequisites:

• Install Docker (e.g., Docker Desktop for Windows/Mac, or sudo apt


install docker.io for Linux).
• Install kubectl (Kubernetes CLI) to interact with the cluster.
• Install Minikube (e.g., via brew install minikube on macOS or curl
on Linux).

2. Start Minikube:
minikube start --driver=docker

This creates a single-node cluster using Docker as the driver.

3. Verify Cluster:
kubectl get nodes
minikube status

4. Access Dashboard (Optional):


minikube dashboard

5 Kubernetes Configuration
Kubernetes uses YAML files to define resources like Deployments, Services, Con-
figMaps, and StatefulSets. These files specify the desired state of the cluster,
which Kubernetes works to maintain.

3
5.1 Deployments for Stateless Apps
Deployments manage stateless applications (e.g., web apps). The replicas field
specifies the number of pod instances, not worker nodes. Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web-container
image: nanajanashia/k8s-demo-app:v1.0
ports:
- containerPort: 3000

The status section, automatically updated by Kubernetes, shows the current


state (e.g., availableReplicas: 3 if all pods are running).

5.2 StatefulSets for Stateful Apps


StatefulSets manage stateful applications (e.g., databases) with persistent storage
and unique identities. Example for MongoDB:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongodb
spec:
serviceName: mongodb-service
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb-container
image: mongo:latest
ports:
- containerPort: 27017

4
volumeMounts:
- name: mongodb-data
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongodb-data
spec:
accessModes: [”ReadWriteOnce”]
resources:
requests:
storage: 1Gi

5.3 Services for Exposing Pods


Services provide a stable endpoint for accessing pods. They use selectors to route
traffic to pods with matching labels. Example:
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer

This exposes the web app externally on port 80, routing to port 3000 on the pods.

5.4 ConfigMaps and Secrets


• ConfigMap: Stores non-sensitive configuration data (e.g., URLs).

• Secret: Stores sensitive data (e.g., database credentials).

Example ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
mongodb-url: ”mongodb://mongodb-service:27017”

Example Secret:
apiVersion: v1
kind: Secret
metadata:
name: mongodb-secret

5
type: Opaque
data:
username: YWRtaW4= % base64 encoded
password: cGFzc3dvcmQ= % base64 encoded

6 Demo Project Structure


The demo project involves deploying a MongoDB database and a web application
in Kubernetes, with external access to the web app.

6.1 Project Files


• ConfigMap: Defines the MongoDB endpoint (e.g., mongodb://mongodb-service:27017

• Secret: Stores MongoDB username and password.

• StatefulSet and Service (MongoDB): Deploys MongoDB with persistent


storage and an internal ClusterIP service.

• Deployment and Service (Web App): Deploys the web app with a Load-
Balancer service for external access.

6.2 Key Considerations


• Use StatefulSet for MongoDB to ensure data persistence.

• Use Deployment for the web app, as it is stateless.

• Ensure the web app uses the ConfigMap and Secret to connect to MongoDB.

7 Troubleshooting Example
When pulling the nanajanashia/k8s-demo-app:v1.0 image, a MongoNetworkError
occurred due to a missing MongoDB service. Solution:
docker run --name mongodb -d mongo
docker run -p 3000:3000 --link mongodb:mongodb nanajanashia/k8s-demo
-app:v1.0

In Kubernetes, ensure the MongoDB service is running and accessible via the
ConfigMap.

8 Conclusion
Kubernetes is a powerful orchestration platform for managing containerized
applications. By understanding its components (master/worker nodes, kubelet,
pods) and configurations (Deployments, StatefulSets, Services, ConfigMaps, Se-
crets), you can deploy scalable and highly available applications. Minikube sim-
plifies local testing, and tools like kubectl provide precise control over the clus-
ter.

You might also like