SiamCafe.net Blog
Technology

Skaffold Dev Internal Developer Platform พัฒนา Kubernetes Apps เร็วขึ้น

skaffold dev internal developer platform
Skaffold Dev Internal Developer Platform | SiamCafe Blog
2026-02-28· อ. บอม — SiamCafe.net· 1,101 คำ

Skaffold ?????????????????????

Skaffold ???????????? command-line tool ????????? Google ????????????????????? developers ?????? continuous development ?????????????????? Kubernetes applications ?????????????????? build, push, deploy loop ??????????????????????????? ???????????????????????? code Skaffold ????????????????????? file changes ???????????? build image ???????????? push ?????? registry ????????? deploy ?????? cluster ??????????????? ?????????????????????????????? commands ?????????

Skaffold ???????????????????????? pluggable ?????????????????? builders ????????????????????? Docker, Jib, Buildpacks, Ko deployers ????????????????????? kubectl, Helm, Kustomize ????????? taggers ????????????????????? gitCommit, sha256, dateTime ????????????????????????????????? project ????????????????????????

????????????????????? Skaffold ????????????????????? Internal Developer Platform (IDP) developers ??????????????????????????????????????? development ????????? consistent ???????????????????????? workflow ???????????????????????? ????????????????????????????????????????????? Kubernetes commands ????????????????????? ?????????????????? skaffold dev ??????????????????????????? code ??????????????????

????????????????????? Skaffold ?????????????????? Development

Setup Skaffold development environment

# === Skaffold Installation ===

# 1. Install Skaffold
# Linux
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
chmod +x skaffold
sudo mv skaffold /usr/local/bin/

# macOS
brew install skaffold

# Windows
choco install skaffold

# Verify
skaffold version
# v2.12.0

# 2. Prerequisites
# - Docker Desktop or containerd
# - kubectl configured with cluster access
# - A Kubernetes cluster (minikube, kind, GKE, EKS)

# 3. Quick Start - Create Project
mkdir myapp && cd myapp

# Create application
cat > main.go << 'GOEOF'
package main

import (
    "fmt"
    "log"
    "net/http"
    "os"
)

func handler(w http.ResponseWriter, r *http.Request) {
    name := os.Getenv("APP_NAME")
    if name == "" {
        name = "World"
    }
    fmt.Fprintf(w, "Hello, %s! Version: v1.0\n", name)
}

func main() {
    http.HandleFunc("/", handler)
    port := os.Getenv("PORT")
    if port == "" {
        port = "8080"
    }
    log.Printf("Starting server on :%s", port)
    log.Fatal(http.ListenAndServe(":"+port, nil))
}
GOEOF

# Create Dockerfile
cat > Dockerfile << 'EOF'
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o server .

FROM alpine:3.19
COPY --from=builder /app/server /server
EXPOSE 8080
CMD ["/server"]
EOF

# Create Kubernetes manifests
mkdir k8s
cat > k8s/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myapp
          ports:
            - containerPort: 8080
          env:
            - name: APP_NAME
              value: "Skaffold"
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  type: ClusterIP
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
EOF

# 4. Create skaffold.yaml
cat > skaffold.yaml << 'EOF'
apiVersion: skaffold/v4beta11
kind: Config
metadata:
  name: myapp
build:
  artifacts:
    - image: myapp
      docker:
        dockerfile: Dockerfile
  local:
    push: false
    useBuildkit: true
manifests:
  rawYaml:
    - k8s/*.yaml
deploy:
  kubectl: {}
portForward:
  - resourceType: service
    resourceName: myapp
    port: 80
    localPort: 8080
EOF

# 5. Start Development
skaffold dev --port-forward

# Now edit main.go ??? Skaffold auto-rebuilds and redeploys!

echo "Skaffold setup complete"

??????????????? Development Workflow

Configure workflows ??????????????????????????? development

# === Skaffold Development Workflows ===

# 1. Multi-Service Project
cat > skaffold.yaml << 'EOF'
apiVersion: skaffold/v4beta11
kind: Config
metadata:
  name: microservices-app
build:
  artifacts:
    - image: api-service
      context: services/api
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: "**/*.py"
            dest: /app
    
    - image: web-frontend
      context: services/web
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: "src/**"
            dest: /app/src
    
    - image: worker-service
      context: services/worker
      docker:
        dockerfile: Dockerfile
  
  local:
    push: false
    useBuildkit: true
    concurrency: 3

manifests:
  helm:
    releases:
      - name: myapp
        chartPath: charts/myapp
        valuesFiles:
          - charts/myapp/values-dev.yaml
        setValues:
          api.image: api-service
          web.image: web-frontend
          worker.image: worker-service

deploy:
  helm: {}

portForward:
  - resourceType: service
    resourceName: myapp-api
    port: 8000
    localPort: 8000
  - resourceType: service
    resourceName: myapp-web
    port: 3000
    localPort: 3000

profiles:
  - name: dev
    activation:
      - command: dev
    patches:
      - op: replace
        path: /build/artifacts/0/docker/dockerfile
        value: Dockerfile.dev

  - name: staging
    build:
      artifacts:
        - image: api-service
          context: services/api
        - image: web-frontend
          context: services/web
        - image: worker-service
          context: services/worker
      googleCloudBuild:
        projectId: my-project
    deploy:
      kubectl:
        defaultNamespace: staging

  - name: production
    build:
      tagPolicy:
        gitCommit:
          variant: Tags
      googleCloudBuild:
        projectId: my-project
    deploy:
      kubectl:
        defaultNamespace: production
EOF

# 2. File Sync (hot reload without rebuild)
# For Python/Node.js apps, sync files directly into running container
# Much faster than full rebuild

# 3. Custom Build Scripts
cat > skaffold-custom.yaml << 'EOF'
apiVersion: skaffold/v4beta11
kind: Config
build:
  artifacts:
    - image: myapp
      custom:
        buildCommand: ./build.sh
        dependencies:
          paths:
            - "src/**"
            - "go.mod"
            - "go.sum"
EOF

echo "Workflows configured"

Internal Developer Platform ????????? Skaffold

??????????????? IDP ???????????? Skaffold

#!/usr/bin/env python3
# idp_skaffold.py ??? IDP with Skaffold Integration
import json
import logging
from typing import Dict, List

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("idp")

class SkaffoldIDP:
    def __init__(self):
        self.templates = {}
    
    def platform_architecture(self):
        return {
            "components": {
                "developer_cli": {
                    "tool": "Skaffold",
                    "commands": {
                        "skaffold dev": "Start dev loop (build+deploy on file change)",
                        "skaffold run": "One-time build and deploy",
                        "skaffold debug": "Build and deploy with debugger attached",
                        "skaffold render": "Generate Kubernetes manifests",
                        "skaffold verify": "Run post-deployment verification",
                    },
                },
                "service_catalog": {
                    "tool": "Backstage",
                    "integration": "Backstage templates generate skaffold.yaml",
                },
                "ci_cd": {
                    "tool": "GitHub Actions + Skaffold",
                    "stages": ["skaffold build", "skaffold test", "skaffold deploy"],
                },
                "environments": {
                    "dev": "Local cluster (minikube/kind) via skaffold dev",
                    "staging": "Shared cluster via skaffold run -p staging",
                    "production": "Production cluster via skaffold deploy -p production",
                },
            },
            "developer_workflow": [
                "1. Clone repo from service catalog",
                "2. Run 'skaffold dev' ??? starts local dev loop",
                "3. Edit code ??? auto-rebuild ??? auto-deploy ??? see changes",
                "4. Run tests: skaffold verify",
                "5. Push to Git ??? CI runs 'skaffold build + test'",
                "6. Merge to main ??? CD runs 'skaffold deploy -p production'",
            ],
        }
    
    def golden_path_template(self):
        """Template for new microservice"""
        return {
            "name": "Go Microservice Template",
            "files_generated": [
                "skaffold.yaml",
                "Dockerfile",
                "Dockerfile.dev (with hot reload)",
                "k8s/deployment.yaml",
                "k8s/service.yaml",
                "k8s/hpa.yaml",
                ".github/workflows/ci.yaml",
                "Makefile",
            ],
            "built_in_features": [
                "Health check endpoints (/healthz, /readyz)",
                "Prometheus metrics (/metrics)",
                "Structured logging (JSON)",
                "Graceful shutdown",
                "OpenTelemetry tracing",
                "Skaffold dev loop",
                "Unit test framework",
                "Linting and formatting",
            ],
        }

idp = SkaffoldIDP()
arch = idp.platform_architecture()
print("Developer Workflow:")
for step in arch["developer_workflow"]:
    print(f"  {step}")

template = idp.golden_path_template()
print(f"\nTemplate: {template['name']}")
print(f"Files: {len(template['files_generated'])}")
print(f"Features: {len(template['built_in_features'])}")

CI/CD Integration

????????? Skaffold ?????? CI/CD pipeline

# === Skaffold CI/CD Integration ===

# GitHub Actions Pipeline
cat > .github/workflows/ci-cd.yml << 'EOF'
name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

env:
  REGISTRY: ghcr.io
  SKAFFOLD_DEFAULT_REPO: ghcr.io/}

jobs:
  build-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      
      - name: Install Skaffold
        run: |
          curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64
          chmod +x skaffold && sudo mv skaffold /usr/local/bin/
      
      - name: Login to Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: }
          password: }
      
      - name: Build Images
        run: skaffold build --file-output=build.json
      
      - name: Run Tests
        run: skaffold test --build-artifacts=build.json
      
      - name: Upload Build Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: build-artifacts
          path: build.json

  deploy-staging:
    needs: build-test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/develop'
    environment: staging
    steps:
      - uses: actions/checkout@v4
      
      - name: Download Build Artifacts
        uses: actions/download-artifact@v4
        with:
          name: build-artifacts
      
      - name: Configure kubectl
        run: |
          echo "}" | base64 -d > kubeconfig
          export KUBECONFIG=kubeconfig
      
      - name: Deploy to Staging
        run: |
          skaffold deploy \
            --profile staging \
            --build-artifacts=build.json \
            --status-check=true \
            --status-check-deadline=300s

  deploy-production:
    needs: build-test
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    environment: production
    steps:
      - uses: actions/checkout@v4
      
      - name: Download Build Artifacts
        uses: actions/download-artifact@v4
        with:
          name: build-artifacts
      
      - name: Deploy to Production
        run: |
          skaffold deploy \
            --profile production \
            --build-artifacts=build.json \
            --status-check=true
      
      - name: Verify Deployment
        run: skaffold verify --profile production
EOF

echo "CI/CD pipeline configured"

Advanced Configuration ????????? Profiles

Advanced Skaffold features

#!/usr/bin/env python3
# skaffold_advanced.py ??? Advanced Skaffold Configuration
import json
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("advanced")

class SkaffoldAdvanced:
    def __init__(self):
        self.configs = {}
    
    def debug_configuration(self):
        """Remote debugging with Skaffold"""
        return {
            "command": "skaffold debug",
            "languages": {
                "go": {
                    "debugger": "Delve",
                    "port": 56268,
                    "config": "Launch type: remote, port: 56268",
                },
                "python": {
                    "debugger": "debugpy",
                    "port": 5678,
                    "config": "attach to localhost:5678",
                },
                "nodejs": {
                    "debugger": "Node Inspector",
                    "port": 9229,
                    "config": "attach to localhost:9229",
                },
                "java": {
                    "debugger": "JDWP",
                    "port": 5005,
                    "config": "Remote JVM Debug, port: 5005",
                },
            },
            "ide_support": ["VS Code", "IntelliJ IDEA", "GoLand"],
        }
    
    def render_and_verify(self):
        """GitOps workflow: render manifests, verify deployments"""
        return {
            "render": {
                "command": "skaffold render --output=rendered.yaml",
                "use_case": "Generate final K8s manifests for GitOps (ArgoCD/Flux)",
                "includes": "Image tags, Helm values, Kustomize overlays applied",
            },
            "verify": {
                "command": "skaffold verify",
                "use_case": "Post-deployment verification tests",
                "config_example": {
                    "verify": [
                        {
                            "name": "health-check",
                            "container": {
                                "name": "health-check",
                                "image": "curlimages/curl:latest",
                                "command": ["curl", "-sf", "http://myapp/healthz"],
                            },
                        },
                        {
                            "name": "integration-test",
                            "container": {
                                "name": "test-runner",
                                "image": "myapp-tests:latest",
                                "command": ["pytest", "tests/integration/"],
                            },
                        },
                    ],
                },
            },
        }
    
    def lifecycle_hooks(self):
        return {
            "hooks": {
                "before_build": "Run linting, generate protobuf, etc.",
                "after_build": "Run security scan on built image",
                "before_deploy": "Run database migrations",
                "after_deploy": "Run smoke tests",
                "before_cleanup": "Backup state, drain connections",
            },
            "example": {
                "deploy": {
                    "kubectl": {},
                    "hooks": {
                        "before": [{"command": ["sh", "-c", "kubectl apply -f migrations/"]}],
                        "after": [{"command": ["sh", "-c", "curl -sf http://localhost:8080/healthz"]}],
                    },
                },
            },
        }

advanced = SkaffoldAdvanced()
debug = advanced.debug_configuration()
print("Debug Support:")
for lang, config in debug["languages"].items():
    print(f"  {lang}: {config['debugger']} on port {config['port']}")

hooks = advanced.lifecycle_hooks()
print(f"\nLifecycle Hooks: {len(hooks['hooks'])} hooks available")

FAQ ??????????????????????????????????????????

Q: Skaffold ????????? Tilt ????????? DevSpace ???????????????????????????????????????????

A: Skaffold ????????? Google ???????????? CLI tool ??????????????? UI ???????????????????????? pipeline (build???test???deploy) pluggable architecture ??????????????? builder/deployer ???????????????????????? ??????????????? CI/CD ??????????????? Tilt ?????? web UI dashboard ???????????? build status, logs real-time ????????? Tiltfile (Starlark) configure declarative + imperative ?????????????????? developer experience ??????????????? DevSpace ???????????? developer experience ????????? devspace.yaml configure ?????? UI, sync files ???????????? built-in port forwarding ?????? ??????????????? development ????????????????????? CI/CD ??????????????? Skaffold ?????????????????????????????? CI/CD integration ??????????????? pluggable Tilt ????????????????????? developer experience ?????????????????????????????? UI DevSpace ??????????????????????????????????????????????????? local development

Q: File Sync ????????? Full Rebuild ???????????????????????????????????????????

A: Full Rebuild ??????????????? code ????????????????????? Skaffold build Docker image ???????????? push ?????? registry deploy container ???????????? ????????????????????? 30 ??????????????????-???????????????????????? ????????????????????? image size File Sync ??????????????? code ????????????????????? Skaffold copy file ?????????????????????????????????????????? running container ?????????????????? ????????? rebuild image ????????????????????? 1-3 ?????????????????? ???????????????????????? interpreted languages (Python, Node.js, Ruby) ????????? process restart ????????????????????? code ???????????????????????????????????? ?????????????????? compiled languages (Go, Java, Rust) ???????????? rebuild ?????????????????? multi-stage build + build cache ??????????????????????????????

Q: Skaffold ?????????????????? production ???????????????????

A: ????????? Skaffold ??????????????????????????????????????????????????????????????? development ??????????????? production ????????? profiles ????????? config ????????????????????????????????? environment dev profile ????????? local build, minikube, file sync staging profile ????????? cloud build, shared cluster production profile ????????? cloud build, gitCommit tag, production cluster CI/CD ????????? skaffold build (build only) + skaffold deploy (deploy only) ?????????????????????????????? GitOps ????????? skaffold render ??????????????? manifests ????????????????????? ArgoCD/Flux deploy ??????????????????????????????????????????????????? Skaffold ?????? production ???????????? Google, Shopify, VMware

Q: Skaffold ???????????????????????? image ???????????? ????????????????????????????

A: ???????????????????????? File Sync ??????????????????????????? interpreted languages ????????????????????? rebuild, Multi-stage Build ????????? build stage ????????? runtime stage ?????? final image size, BuildKit Cache mount cache (go modules, npm packages) ????????????????????? builds, Jib (Java) build Java images ?????????????????????????????? Docker layer caching ??????, Ko (Go) build Go images ????????????????????? ????????????????????? Dockerfile, Local Build ????????? local Docker daemon ????????? remote build ?????? push time, Parallel Build ???????????? concurrency ?????? skaffold.yaml build ???????????? artifacts ???????????????????????? ???????????????????????? Go project ?????????????????? Ko build+deploy ??????????????? 3-5 ?????????????????? ???????????????????????? Docker build 30+ ??????????????????

📖 บทความที่เกี่ยวข้อง

Skaffold Dev Agile Scrum Kanbanอ่านบทความ → Skaffold Dev Interview Preparationอ่านบทความ → Skaffold Dev Multi-tenant Designอ่านบทความ → Skaffold Dev AR VR Developmentอ่านบทความ → Skaffold Dev Container Orchestrationอ่านบทความ →

📚 ดูบทความทั้งหมด →