Computer Virtualization คือ — เทคโนโลยี
Computer Virtualization
Virtualization Hypervisor Type 1 Type 2 VM Container Docker Kubernetes VDI Cloud Computing KVM ESXi Proxmox VirtualBox Hardware Abstraction
| Technology | Type | Overhead | Isolation | Use Case |
|---|---|---|---|---|
| VMware ESXi | Type 1 | ต่ำ | สูงมาก | Enterprise |
| Proxmox VE | Type 1 | ต่ำ | สูงมาก | Home Lab/SME |
| VirtualBox | Type 2 | ปานกลาง | สูง | Desktop Dev |
| Docker | Container | ต่ำมาก | ปานกลาง | Microservices |
| KVM/QEMU | Type 1 | ต่ำ | สูงมาก | Linux Server |
Hypervisor และ VM
=== Virtualization Technologies ===
อ่านเพิ่ม: MLOps Pipeline Container Orchestration — จัดการ ML Pipeline · อ่านเพิ่ม: Helm Chart Template Pub Sub Architecture — คู่มือฉบับสมบูรณ์ · อ่านเพิ่ม: Cilium CNI Monitoring และ Alerting — คู่มือฉบับสมบูรณ์ 2026
Type 1 — Bare-metal Hypervisor
┌──────────┬──────────┬──────────┐
│ VM 1 │ VM 2 │ VM 3 │
│ Ubuntu │ Windows │ CentOS │
├──────────┴──────────┴──────────┤
│ Hypervisor (ESXi) │
├────────────────────────────────┤
│ Hardware (Server) │
└────────────────────────────────┘
Type 2 — Hosted Hypervisor
┌──────────┬──────────┐
│ VM 1 │ VM 2 │
├──────────┴──────────┤
│ VirtualBox/VMware │
├─────────────────────┤
│ Host OS (Windows) │
├─────────────────────┤
│ Hardware (Desktop) │
└─────────────────────┘
KVM — ติดตั้งบน Linux
sudo apt install qemu-kvm libvirt-daemon-system virt-manager
sudo systemctl enable libvirtd
sudo usermod -aG libvirt $USER
# สร้าง VM ด้วย virt-install
virt-install \
--name ubuntu-vm \
--ram 4096 \
--vcpus 2 \
--disk size=50 \
--os-variant ubuntu22.04 \
--cdrom /path/to/ubuntu-22.04.iso \
--network bridge=br0 \
--graphics vnc
Proxmox VE — Web UI
ISO: https://www.proxmox.com/downloads
ติดตั้งบน USB Boot
เข้า Web UI: https://proxmox-ip:8006
สร้าง VM: Datacenter > Node > Create VM
from dataclasses import dataclass
from typing import List
@dataclass
class Hypervisor:
name: str
type: str
license: str
max_vms: int
live_migration: bool
ha: bool
storage: str
hypervisors = [
Hypervisor("VMware ESXi", "Type 1", "Commercial", 1024, True, True, "VMFS, vSAN, NFS"),
Hypervisor("Proxmox VE", "Type 1", "Open Source", 500, True, True, "ZFS, Ceph, LVM"),
Hypervisor("Microsoft Hyper-V", "Type 1", "Windows License", 1024, True, True, "CSV, SMB"),
Hypervisor("KVM/QEMU", "Type 1", "Open Source", 500, True, True, "LVM, Ceph, NFS"),
Hypervisor("VirtualBox", "Type 2", "Free/Commercial", 100, False, False, "VDI, VMDK"),
Hypervisor("VMware Workstation", "Type 2", "Commercial", 100, False, False, "VMDK"),
]
print("=== Hypervisor Comparison ===")
for h in hypervisors:
migrate = "Yes" if h.live_migration else "No"
print(f" [{h.type}] {h.name} ({h.license})")
print(f" Max VMs: {h.max_vms} | Live Migration: {migrate} | Storage: {h.storage}")
Container vs VM
=== Container vs VM ===
Container Architecture
┌───────┬───────┬───────┐
│ App 1 │ App 2 │ App 3 │
├───────┴───────┴───────┤
│ Container Runtime │
│ (Docker/containerd) │
├───────────────────────┤
│ Host OS (Linux) │
├───────────────────────┤
│ Hardware │
└───────────────────────┘
Docker — Basic Commands
docker pull ubuntu:22.04
docker run -d --name web -p 80:80 nginx
docker exec -it web bash
docker stop web && docker rm web
# Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
docker build -t myapp:1.0 .
docker run -d -p 8000:8000 myapp:1.0
Kubernetes — Container Orchestration
kubectl create deployment web --image=nginx --replicas=3
kubectl expose deployment web --port=80 --type=LoadBalancer
kubectl scale deployment web --replicas=5
kubectl get pods -o wide
@dataclass
class Comparison:
feature: str
vm: str
container: str
comparisons = [
Comparison("Boot Time", "นาที", "วินาที"),
Comparison("RAM Usage", "GB (Full OS)", "MB (App Only)"),
Comparison("Disk Usage", "GB", "MB-GB"),
Comparison("Isolation", "สูงมาก (Hardware)", "ปานกลาง (Kernel)"),
Comparison("OS Support", "Any OS", "Linux (mainly)"),
Comparison("Density", "10-50 VMs/Host", "100-1000 Containers/Host"),
Comparison("Management", "vCenter/Proxmox", "Docker/Kubernetes"),
Comparison("Use Case", "Legacy, Multi-OS", "Microservices, CI/CD"),
Comparison("Security", "สูงมาก", "ดี (ใช้ gVisor/Kata เพิ่ม)"),
]
print("\n=== VM vs Container ===")
print(f" {'Feature':<20} {'VM':<25} {'Container'}")
for c in comparisons:
print(f" {c.feature:<20} {c.vm:<25} {c.container}")
Cloud และ VDI
# === Cloud Computing & VDI ===
# Cloud Virtualization Stack
# IaaS: AWS EC2, Azure VM, GCP Compute Engine
# PaaS: Heroku, Google App Engine, Azure App Service
# SaaS: Gmail, Office 365, Salesforce
# FaaS: AWS Lambda, Azure Functions, GCP Cloud Functions
# VDI — Virtual Desktop Infrastructure
# ใช้ Virtual Machine เป็น Desktop
# User เข้าผ่าน Thin Client หรือ Browser
# Citrix, VMware Horizon, Microsoft AVD
cloud_services = {
"AWS EC2": {"type": "IaaS", "vm_type": "Xen/Nitro", "pricing": "On-demand/Reserved/Spot"},
"Azure VM": {"type": "IaaS", "vm_type": "Hyper-V", "pricing": "Pay-as-you-go/Reserved"},
"GCP Compute": {"type": "IaaS", "vm_type": "KVM", "pricing": "On-demand/Committed"},
"Proxmox VE": {"type": "On-premise", "vm_type": "KVM/LXC", "pricing": "Free + Support"},
"VMware vSphere": {"type": "On-premise", "vm_type": "ESXi", "pricing": "Per-CPU License"},
}
print("Cloud & On-premise:")
for name, info in cloud_services.items():
print(f" [{info['type']}] {name}")
print(f" VM Type: {info['vm_type']} | Pricing: {info['pricing']}")
# Resource Planning
@dataclass
class VMPlan:
workload: str
vcpu: int
ram_gb: int
disk_gb: int
count: int
monthly_cost: float
plan = [
VMPlan("Web Server", 2, 4, 50, 3, 45),
VMPlan("API Server", 4, 8, 100, 2, 80),
VMPlan("Database", 8, 32, 500, 2, 200),
VMPlan("Redis Cache", 2, 16, 50, 2, 60),
VMPlan("CI/CD Runner", 4, 8, 100, 3, 80),
VMPlan("Monitoring", 2, 4, 200, 1, 40),
]
print(f"\n\n=== VM Resource Planning ===")
total_cost = 0
for p in plan:
cost = p.monthly_cost * p.count
total_cost += cost
print(f" {p.workload} x{p.count}: {p.vcpu}vCPU / {p.ram_gb}GB RAM / {p.disk_gb}GB — /mo")
print(f"\n Total: /mo")
เคล็ดลับ
- Type 1: ใช้ Type 1 Hypervisor สำหรับ Production
- Container: ใช้ Container สำหรับ Microservices ไม่ต้อง VM ทุกอย่าง
- Lab: สร้าง Home Lab ด้วย Proxmox VE ฟรี เรียนรู้ได้เยอะ
- Snapshot: ใช้ Snapshot ก่อนเปลี่ยนแปลง Rollback ได้
- Resource: อย่า Over-provision CPU/RAM วางแผนให้เหมาะสม
Virtualization คืออะไร
สร้าง Virtual Hardware CPU Memory Storage Network Hypervisor VM Container Server Desktop Network Storage ประหยัด