Complete Kubernetes Course Notes
Introduction to Kubernetes
- Course Format: Mix of theoretical explanations and hands-on demos.
- Objective: Give an introduction to Kubernetes and its main components.
- Structure:
- Basic concepts of Kubernetes, its problem-solving capabilities, and architecture.
- Introduction to Minicube for local Kubernetes clusters.
- Usage of kubectl (command-line tool for Kubernetes).
- Understanding Kubernetes YAML configuration files.
- Deployment of a simple application in Kubernetes locally.
- Advanced concepts (namespaces, ingress, Helm, volume persistence, stateful sets, service types).
Section 1: Basic Concepts of Kubernetes
Definition and Importance
- Kubernetes: An open-source container orchestration framework by Google.
- Container Management: Supports Docker and other container technologies, suitable for various environments (physical, virtual, cloud, hybrid).
- Problem Solving: Kubernetes addresses issues of high availability, scalability, and disaster recovery.
Kubernetes Architecture
- Basic Components: Pods, nodes, services, config maps, secrets, deployments, stateful sets, and volumes.
- Pod: Abstraction over containers, smallest deployable unit.
Pod Communication
- Virtual Network: Each pod gets its own internal IP address.
- Services: Static IP addresses for pod communication, load balancing, and association of pods.
- Ingress: Manages external access to the services.
- ConfigMap & Secret: Used for external configuration(sensitive credentials stored in Secrets).
Installation and Setup
- Minicube: Tool for setting up local one-node Kubernetes clusters.
- kubectl: Command-line tool for managing Kubernetes clusters, works for all clusters including local, cloud, and hybrid setups.
Section 2: Minicube and kubectl Installation
Installing Minicube & kubectl
- Prerequisites: Requires hypervisor (VirtualBox, HyperKit, etc).
- Installation Command: Minicube installations come with kubectl dependency.
- Commands Overview:
kubectl
and minicube
CLI commands for managing clusters and deployments.
Verifying Installation
- Checking Nodes:
kubectl get nodes
shows cluster nodes status.
- Starting Cluster: Use
minicube start --vm-driver=<driver-name>
.
Section 3: Basic kubectl Commands and Working with Pods
CRUD Operations
- Creating a Deployment:
kubectl create deployment <name> --image=<image-name>
.
- Scaling Pods:
kubectl scale deployment <name> --replicas=<number>
.
- Editing Deployment:
kubectl edit deployment <name>
updates deployment configs.
- Listing Resources:
kubectl get pods
, kubectl get deployments
, kubectl get services
, etc.
- Logging:
kubectl logs <pod-name>
displays logs of a pod.
- Exec Command:
kubectl exec -it <pod-name> -- /bin/bash
for interactive terminal of a container within a pod.
Managing Configuration with YAML
- Apply Command:
kubectl apply -f <file.yaml>
to create/update resources from a configuration file.
- Configuration Files: Store and manage kubernetes application deployments.
- Editing Configs: Direct edits in YAML files for deployments and services.
Section 4: Understanding Kubernetes Configuration Files
File Structure and Syntax
- Three Parts: Metadata, Specification, and Status.
- Templates and Labels: Used for deployment, service configurations.
- Selectors: Connect services to their respective pods.
- Ports: Defining service ports and target ports for communication.
- Status Section: Auto-generated by Kubernetes.
Section 5: Deploying Applications in Kubernetes
Practical Example
- MongoDB and Express Setup: Demonstrates microservice architecture with dependencies.
- Steps: Setup MongoDB Pod → Create Services → Deployment of Express App → Configure External/Internal Services.
- Use of Secrets & ConfigMaps: External configuration for sensitive data and environment-specific settings.
- Accessing Applications: Through browser using services and Ingress.
Section 6: Advanced Concepts
Namespaces
- Purpose: Organize resources for isolation, multi-tenant environments, and logical separation.
- Default Namespaces:
default
, kube-system
, kube-public
, kube-node-lease
.
- Creating Namespaces:
kubectl create namespace <name>
or via configuration files.
- Setting Namespace Context: Use tools like
kubens
for switching default namespaces.
- Resource Quotas: Limit resources per namespace.
Ingress
- Purpose: Manage external access to services in a cluster.
- Configuration: Includes host, path, backend service, and options for TLS (https).
- Controller: Addons for managing ingress rules.
- Usage: Handle multi-path routing, subdomains, default backends.
Helm
- Features: Package manager, template engine, release management.
- Usage: Facilitate complex deployments using reusable Helm charts.
- Structure: Chart.yaml, values.yaml, templates, dependencies.
- Tiller: (Deprecated) Previously used server component managing releases.
- Version 3: Removes tiller for improved security.
Storage & Volumes
- Types: Persistent Volumes (PV), Persistent Volume Claims (PVC), Storage Classes.
- Purpose: Data persistence across pod restarts, used with stateful sets.
- Dynamic Provisioning: Using storage classes for automated volume creation.
- ConfigMap & Secret: Specific local volumes for configurations and sensitive data.
Stateful Sets
- Purpose: Deployment component for stateful applications.
- Characteristics: Ordered and unique pod identities, unique network identifiers, stable storage.
- Use Cases: Databases and applications with persistent state.
- Configuration: Defined like deployments but with state management features.
Services
- Types: Cluster IP, Headless, NodePort, LoadBalancer.
- Cluster IP: Default, internal communication.
- Headless: Direct communication with individual pods, needed for stateful sets.
- NodePort: Exposes service on each node's IP at a static port.
- LoadBalancer: Cloud provider-managed external load balancer.
Conclusion
- Learning Outcome: Comprehensive knowledge of Kubernetes fundamental and advanced concepts.
- Next Steps: Explore more advanced Kubernetes topics and tools, stay connected on social media.
Feel free to reach out with any questions or to connect on social media!