Kubernetes Tutorial
Overview
Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. It orchestrates containerized applications across a cluster of machines, providing tools for managing containerized applications.
Key Concepts
1. Cluster
A Kubernetes cluster consists of a set of nodes that run containerized applications. Each cluster has a master node and worker nodes.
2. Pod
A Pod is the smallest deployable unit in Kubernetes. It can contain one or more containers that share the same network namespace and storage.
3. Deployment
A Deployment manages a set of identical Pods, ensuring that the specified number of Pods are running and available.
4. Service
A Service exposes a set of Pods as a network service. It provides load balancing and service discovery.
5. Namespace
Namespaces provide a mechanism for isolating groups of resources within a single cluster.
Basic Commands
1. kubectl version
Check the version of kubectl
and the Kubernetes cluster.
2. kubectl get nodes
List all nodes in the cluster.
Example
3. kubectl get pods
List all Pods in the current namespace.
Example
4. kubectl create
Create a resource from a file or from stdin.
Example
Create a Pod from a YAML file:
5. kubectl apply
Apply a configuration change to a resource.
Example
Update a Deployment with a new configuration:
6. kubectl delete
Delete a resource.
Example
Delete a Pod:
7. kubectl describe
Show detailed information about a resource.
Example
8. kubectl logs
Print the logs for a container in a Pod.
Example
Example YAML Files
Pod Definition
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
ports:
- containerPort: 80
Deployment Definition
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Service Definition
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Namespaces
Namespaces help you organize resources in a cluster.
Create a Namespace
List Namespaces
Use a Namespace
Summary
This tutorial introduces fundamental Kubernetes concepts and commands. Kubernetes simplifies container orchestration and management, making it easier to deploy and scale applications. For more detailed information, refer to the official Kubernetes documentation.