Kubernetes
Kubernetes Overview and kubectl
* What is Kubernetes?
- Kubernetes (K8S) is an open-source tool for managing containers, developed by Google.
- It allows you to deploy, manage, and scale containerised applications automatically.
* Why Kubernetes?
Before containers:
- Developers created applications and passed them to the Operations team.
- Ops teams faced challenges with setups, dependencies, and configurations.
With containers (like Docker):
- Developers bundle applications and dependencies into images.
- These images work the same in any environment (development, testing, production).
- However, managing many containers requires automation; this is where orchestration comes in.
* What is Container Orchestration?
- Deploying containers
- Connecting containers
- Scaling containers up or down
- Managing failures
- Allocating resources
- Kubernetes is one orchestration tool among others, like Docker Swarm and Apache Mesos.
- Managing failures
- Allocating resources
- Kubernetes is one orchestration tool among others, like Docker Swarm and Apache Mesos.
* Key Benefits of Kubernetes
- Load balancing: it spreads traffic across containers.
- Auto-scaling: it adds or removes containers based on demand.
- Node scaling: it adjusts hardware without any downtime.
- Declarative configuration: it uses simple YAML files.
* Core Kubernetes Concepts
- Auto-scaling: it adds or removes containers based on demand.
- Node scaling: it adjusts hardware without any downtime.
- Declarative configuration: it uses simple YAML files.
* Core Kubernetes Concepts
- A worker machine, either physical or virtual.
- It runs containers and was previously called a minion.
2. Cluster
- A group of multiple nodes.
It offers:
- High availability
- Load sharing
- Fault tolerance
- Fault tolerance
3. Master Node (Control Plane)
- This node manages the cluster.
It is responsible for:
- Monitoring nodes
- Scheduling containers
- Handling failures
- Maintaining cluster state
- Handling failures
- Maintaining cluster state
4. kubectl (Kube Control CLI)
- This command-line tool lets you interact with Kubernetes.
Common commands include:
- kubectl run: Deploy an application
- kubectl cluster-info: View cluster details
- kubectl get nodes: List all nodes
- kubectl get nodes: List all nodes
* Summary
Kubernetes helps you:
- Run containers efficiently
- Manage failures automatically
- Scale applications smoothly
- Handle infrastructure with straightforward configuration files
- Scale applications smoothly
- Handle infrastructure with straightforward configuration files
- It is the industry standard for container orchestration.
Lab : kubectl
* How many nodes are part of cluster?
The Kubernetes control plane URL can be found by running the command
Create a Pod named nginx-pod using the nginx image.
Is pod running?
Kubernetes Pods
* What is a Pod?
- It holds your application container, usually one container per Pod.
- Kubernetes does not run containers directly on nodes; it runs Pods.
- 1 Pod = 1 Application Instance
- A Pod usually has one container running one instance of your application.
- For example, a single Nginx container inside a Pod.
* Scaling Applications
- Do not add more containers to the same Pod.
- Do create new Pods with the same container image.
- Scaling up means creating more Pods.
- Scaling down means deleting Pods.
* Pods Across Nodes
- If one node is full, Kubernetes schedules Pods on other nodes in the cluster.
- More demand means more Pods, which may lead to more nodes.
* Can a Pod Have Multiple Containers?
- Yes, but only when they perform supporting tasks, not for scaling.
Examples:
- Main Web App container
- Helper container, like a logs processor or file parser
These containers:
- Run together inside the same Pod
- Start and stop together
- Share the same network and storage
- This arrangement is known as sidecar containers.
* Deploying Pods
You can use the kubectl run command:
- kubectl run nginx --image=nginx
This command:
- Creates a Pod
- Pulls the container image from Docker Hub or your private repository
- Runs the container inside the Pod
* Viewing Pods
Use this command:
- kubectl get pods
Pod states include:
- ContainerCreating means the container image is being downloaded.
- Running means the Pod is up and running successfully.
* Summary
- Pods are the basic building blocks in Kubernetes.
- One Pod equals one instance of your app.
- To scale, increase or decrease the number of Pods, not the containers inside a Pod.
- Pods can have multiple containers, but only when they work together.
- Using kubectl commands makes it easy to deploy and manage Pods.
Lab : Pods
* How many pods exist on the system?
* Create a new pod with the nginx image.
Which nodes are these pods placed on?
What is the state of the pod webapp?
YAML Basics
* What is YAML?
- YAML stands for YAML Ain’t Markup Language.
- It is used to represent configuration data.
- It is easier to read than XML and JSON because of its clean, indentation-based structure.
YAML vs XML vs JSON
- XML uses opening and closing tags and is heavy.
- JSON uses curly braces {} and brackets [].
- YAML is simple, clean, and human-readable; it uses indentation instead of brackets.
* YAML Key-Value Format
Basic structure:
- key: value
Examples:
fruit: apple
vegetable: carrot
liquid: water
meat: chicken
* Important:
- Use a space after the colon.
- No quotes are needed unless there are special characters.
* YAML Lists (Arrays)
Lists are represented using dashes (-):
fruits:
- apple
- banana
- mango
* YAML Dictionaries (Objects)
- A dictionary is a group of key-value pairs under one item:
banana:
calories: 105
fat: 0.4
carbs: 27
* Important:
- Indentation defines structure.
- All children must have an equal number of spaces.
- Incorrect spacing causes a syntax error.
Example of wrong indentation:
banana:
calories: 105
fat: 0.4 # ❌ Wrong; extra spaces!
* Nested Structures
- YAML can contain lists inside dictionaries and dictionaries inside lists:
Example:
fruits:
- name: banana
nutrition:
calories: 105
carbs: 27
- name: grape
nutrition:
calories: 62
carbs: 16
This shows:
- A list of fruits, where each item is a dictionary and each dictionary contains another dictionary.
* Key Rules to Remember
- It uses indentation to define hierarchy.
- No tabs, only spaces.
- Consistent indentation is crucial.
- It has a clean, human-readable format.
Comments
Post a Comment