πŸ”§ DevOps

Skaffold

A tool for automating Kubernetes application development

Detailed Explanation

Skaffold is a tool developed by Google that automates local development and CI/CD for Kubernetes applications. When it detects code changes, it automatically builds, pushes, and deploys, greatly shortening the developer's inner loop.

Skaffold's core features are File Sync and hot reload. Instead of rebuilding the entire image when code changes, it syncs only the changed files to the running container, so you can see the changes within seconds. It supports various build tools such as Docker, Jib, Buildpacks, and Kaniko, and is integrated with Helm, Kustomize, and kubectl to support various deployment methods.

Code Example

Basic skaffold.yaml Configuration

# skaffold.yaml
apiVersion: skaffold/v4beta5
kind: Config
metadata:
  name: my-app
build:
  local:
    push: false
    useBuildkit: true
  artifacts:
  - image: my-app
    context: .
    docker:
      dockerfile: Dockerfile
    sync:
      manual:
      - src: "src/**/*.js"
        dest: /app
      - src: "src/**/*.css"
        dest: /app
deploy:
  kubectl:
    manifests:
    - k8s/*.yaml
portForward:
- resourceType: deployment
  resourceName: my-app
  port: 3000
  localPort: 3000
profiles:
- name: dev
  activation:
  - command: dev
  build:
    local:
      push: false
  deploy:
    kubectl:
      manifests:
      - k8s/dev/*.yaml
- name: prod
  build:
    googleCloudBuild:
      projectId: my-project
  deploy:
    helm:
      releases:
      - name: my-app
        chartPath: charts/my-app
        valuesFiles:
        - values-prod.yaml

Multi-Service Project Setup

# skaffold.yaml - λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ ꡬ성
apiVersion: skaffold/v4beta5
kind: Config
metadata:
  name: microservices-app
build:
  artifacts:
  - image: api-gateway
    context: services/api-gateway
    docker:
      dockerfile: Dockerfile
  - image: user-service
    context: services/user
    docker:
      dockerfile: Dockerfile
  - image: order-service
    context: services/order
    docker:
      dockerfile: Dockerfile
  tagPolicy:
    gitCommit:
      ignoreChanges: true
deploy:
  kustomize:
    paths:
    - k8s/overlays/dev
test:
- image: user-service
  structureTests:
  - ./test/container-structure-test.yaml
verify:
- name: integration-test
  container:
    name: integration-test
    image: curlimages/curl
    command: ["/bin/sh"]
    args: ["-c", "curl -f http://api-gateway/health"]

Development Workflow

#!/bin/bash
# Skaffold 개발 μ›Œν¬ν”Œλ‘œμš°

# 개발 λͺ¨λ“œ μ‹€ν–‰ (파일 κ°μ‹œ + μžλ™ 배포)
skaffold dev --port-forward

# νŠΉμ • ν”„λ‘œνŒŒμΌλ‘œ μ‹€ν–‰
skaffold dev -p dev --tail

# ν•œ 번만 λΉŒλ“œν•˜κ³  배포
skaffold run

# 디버그 λͺ¨λ“œ (원격 디버깅 지원)
skaffold debug --port-forward

# 둜컬 ν΄λŸ¬μŠ€ν„°μ— λ Œλ”λ§λœ λ§€λ‹ˆνŽ˜μŠ€νŠΈ 확인
skaffold render

# νŠΉμ • λͺ¨λ“ˆλ§Œ λΉŒλ“œ
skaffold build -m user-service

# 배포된 λ¦¬μ†ŒμŠ€ 정리
skaffold delete

Practical Conversation

Junior Developer

"Developing with Kubernetes locally means running docker build and kubectl apply every single time, and it's such a hassle."

Senior developer

"Try Skaffold. With just skaffold dev, everything from detecting file changes to deployment is automated. When you save your code, it's reflected in the cluster within 3 seconds."

Junior Developer

"Doesn't building images take a long time?"

Senior developer

"If you set up File Sync, it doesn't rebuild the image; it syncs only the changed files to the container. Using it together with nodemon in a Node.js project is really fast."

DevOps engineer

"You can use the same skaffold.yaml in CI/CD too. If you separate only the environment-specific settings with profiles, local and production build settings are managed consistently."

Cautions

  • Local cluster required: To make the most of Skaffold, you need a local cluster such as minikube, kind, or Docker Desktop Kubernetes.
  • File Sync limitations: A full build is required when binaries change or dependencies are added. Configure the sync patterns appropriately.
  • Resource usage: File watching and continuous builds can lead to high CPU/memory usage.
  • Production separation: Clearly separate the dev profile and the prod profile so that you do not accidentally deploy to production.
  • Multi-service complexity: As microservices multiply, use the module (-m) option to develop only the services you need.

Learn More