SiamCafe · Blog
Skaffold Dev Edge Deployment — พัฒนาและ Deploy
บทความ

Skaffold Dev Edge Deployment — พัฒนาและ Deploy

เผยแพร่ 28 พฤษภาคม 2569

Skaffold Edge Deployment

Skaffold Dev Edge Deployment — พัฒนาและ Deploy

Skaffold Dev Loop Edge Deployment K3s Kubernetes Continuous Development Docker Helm Kustomize GitOps Fleet IoT CDN ARM

ComponentCloudEdgeDifference
KubernetesEKS GKE AKSK3s KubeEdgeEdge ใช้ Lightweight K8s
HardwareHigh-end ServerRaspberry Pi NUC Mini PCEdge จำกัด CPU/RAM
Architecturex86_64ARM64 / x86_64Edge อาจเป็น ARM
NetworkStable High-speedUnstable Low-bandwidthEdge Internet ไม่เสถียร
RegistryECR GCR DockerHubLocal Registry MirrorEdge ใช้ Mirror ลด Pull Time

Skaffold Configuration

# === skaffold.yaml for Edge Development ===

# apiVersion: skaffold/v4beta6
# kind: Config
# metadata:
#   name: edge-app
#
# profiles:
#   - name: dev
#     build:
#       artifacts:
#         - image: edge-app
#           docker:
#             dockerfile: Dockerfile
#       local:
#         push: false
#     deploy:
#       kubectl:
#         manifests:
#           - k8s/dev/*.yaml
#
#   - name: edge
#     build:
#       artifacts:
#         - image: edge-app
#           docker:
#             dockerfile: Dockerfile.edge
#             buildArgs:
#               TARGETARCH: arm64
#       local:
#         push: true
#     deploy:
#       helm:
#         releases:
#           - name: edge-app
#             chartPath: charts/edge-app
#             valuesFiles:
#               - values-edge.yaml
#             setValues:
#               resources.limits.cpu: "500m"
#               resources.limits.memory: "256Mi"
#
#   - name: prod-edge
#     build:
#       artifacts:
#         - image: edge-app
#           docker:
#             dockerfile: Dockerfile.edge
#       tagPolicy:
#         gitCommit: {}
#     deploy:
#       kustomize:
#         paths:
#           - k8s/overlays/prod-edge

from dataclasses import dataclass

@dataclass
class SkaffoldProfile:
    profile: str
    builder: str
    deployer: str
    target: str
    use_case: str

profiles = [
    SkaffoldProfile("dev",
        "Docker (local, no push)",
        "kubectl (raw manifests)",
        "Local Minikube/Kind",
        "Local Development ทดสอบเร็ว"),
    SkaffoldProfile("edge-dev",
        "Docker (local, push to edge registry)",
        "kubectl + port-forward",
        "K3s on Edge Device",
        "Dev Loop บน Edge จริง"),
    SkaffoldProfile("edge",
        "Docker (ARM64 cross-compile)",
        "Helm (values-edge.yaml)",
        "K3s Edge Cluster",
        "Deploy ไป Edge Staging"),
    SkaffoldProfile("prod-edge",
        "Docker (git tag, multi-arch)",
        "Kustomize (prod-edge overlay)",
        "K3s Edge Production",
        "Production Edge Deployment"),
]

print("=== Skaffold Profiles ===")
for p in profiles:
    print(f"\n  [{p.profile}]")
    print(f"    Builder: {p.builder}")
    print(f"    Deployer: {p.deployer}")
    print(f"    Target: {p.target}")
    print(f"    Use: {p.use_case}")

Edge Cluster Setup

Skaffold Dev Edge Deployment — พัฒนาและ Deploy
# === K3s Edge Cluster Setup ===

# Install K3s on Edge Node (ARM64 Raspberry Pi / x86 Mini PC)
# curl -sfL https://get.k3s.io | sh -s - \
#   --write-kubeconfig-mode 644 \
#   --disable traefik \
#   --disable servicelb \
#   --node-name edge-node-01

# Get kubeconfig for Skaffold
# scp edge-node:/etc/rancher/k3s/k3s.yaml ~/.kube/edge-config
# Edit server: https://edge-node-ip:6443

# Set context for Skaffold
# export KUBECONFIG=~/.kube/edge-config
# skaffold dev -p edge

# Local Registry Mirror on Edge (reduce pull time)
# docker run -d -p 5000:5000 --name registry \
#   -v /var/lib/registry:/var/lib/registry registry:2
# k3s: registries.yaml
# mirrors:
#   "docker.io":
#     endpoint:
#       - "http://localhost:5000"

@dataclass
class EdgeSetupStep:
    step: int
    action: str
    command: str
    time: str

setup = [
    EdgeSetupStep(1, "Install K3s on Edge",
        "curl -sfL https://get.k3s.io | sh -",
        "2-5 นาที"),
    EdgeSetupStep(2, "Copy kubeconfig",
        "scp edge:/etc/rancher/k3s/k3s.yaml ~/.kube/edge",
        "30 วินาที"),
    EdgeSetupStep(3, "Setup Registry Mirror",
        "docker run -d -p 5000:5000 registry:2",
        "1 นาที"),
    EdgeSetupStep(4, "Configure Skaffold Profile",
        "เพิ่ม edge profile ใน skaffold.yaml",
        "5 นาที"),
    EdgeSetupStep(5, "Start Dev Loop",
        "KUBECONFIG=~/.kube/edge skaffold dev -p edge",
        "ทันที"),
    EdgeSetupStep(6, "Deploy Production",
        "skaffold run -p prod-edge --tag=$(git rev-parse --short HEAD)",
        "2-5 นาที"),
]

print("=== Edge Setup ===")
for s in setup:
    print(f"  Step {s.step}: {s.action}")
    print(f"    Command: {s.command}")
    print(f"    Time: {s.time}")

Multi-Edge GitOps

# === Multi-Edge Deployment with Fleet/ArgoCD ===

@dataclass
class EdgeLocation:
    location: str
    hardware: str
    k3s_version: str
    apps: str
    network: str

locations = [
    EdgeLocation("Bangkok Store #1",
        "Intel NUC i5, 16GB RAM, 256GB SSD",
        "K3s v1.28",
        "POS API, Inventory Sync, Local Cache",
        "Fiber 100Mbps + 4G Failover"),
    EdgeLocation("Chiang Mai Store #2",
        "Raspberry Pi 5, 8GB RAM, 128GB SD",
        "K3s v1.28 (ARM64)",
        "POS API (lite), Inventory Sync",
        "4G LTE Primary"),
    EdgeLocation("Factory IoT Gateway",
        "Jetson Nano, 4GB RAM",
        "K3s v1.28 (ARM64)",
        "Sensor Collector, AI Inference, MQTT Bridge",
        "WiFi + Ethernet"),
    EdgeLocation("CDN Edge PoP",
        "AMD EPYC, 64GB RAM, 1TB NVMe",
        "K3s v1.28",
        "Cache Server, Image Optimizer, WAF",
        "10Gbps Fiber"),
]

print("=== Edge Locations ===")
for l in locations:
    print(f"\n  [{l.location}]")
    print(f"    Hardware: {l.hardware}")
    print(f"    K3s: {l.k3s_version}")
    print(f"    Apps: {l.apps}")
    print(f"    Network: {l.network}")

เคล็ดลับ

  • K3s: ใช้ K3s แทน Full K8s สำหรับ Edge ลด Resource 50%+
  • Mirror: ตั้ง Registry Mirror บน Edge ลด Image Pull Time
  • ARM: ใช้ Multi-arch Build สำหรับ Edge ที่เป็น ARM64
  • Sync: ใช้ Skaffold File Sync สำหรับ Hot Reload ลด Build Time
  • Fleet: ใช้ Fleet/ArgoCD สำหรับ GitOps Multi-edge

Skaffold คืออะไร

CLI Continuous Development Kubernetes Build Push Deploy อัตโนมัติ skaffold dev Docker Buildpacks kubectl Helm Kustomize Profile Environment

อ่านเพิ่ม: MinIO S3 Compatible Storage self-hosted ทดแทน AWS S3 · อ่านเพิ่ม: Terraform สำหรับ Home Lab จัดการ Infrastructure as Code · อ่านเพิ่ม: ESPHome DIY Sensor ทำเซ็นเซอร์ IoT เองราคาถูก