본문 바로가기
K8S

[kubernetes] kind 설치 및 간단한 실행방법

by Rainbound-IT 2025. 9. 6.
반응형

목차

    1) 사전 준비

    • Docker Desktop 설치 (WSL2 백엔드 권장). Docker가 켜져 있어야 합니다.
    • kubectl 설치 (없다면 함께 설치).

    Windows (PowerShell)

    # Docker Desktop 설치(수동 설치 권장), 설치 후 실행
    
    # kubectl
    winget install -e --id Kubernetes.kubectl        # 또는
    choco install kubernetes-cli -y                  # 또는
    scoop install kubectl
    
    # kind
    choco install kind -y                            # 또는
    scoop install kind                               # 또는
    winget install -e --id Kubernetes.kind
    
    

    macOS

    brew install kubectl kind

    Linux

    curl -Lo ./kind <https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64> \\
      && chmod +x ./kind && sudo mv ./kind /usr/local/bin/kind
    # kubectl은 패키지/공식 가이드로 설치

    설치 확인

    kind version
    kubectl version --client
    docker version

    2) 가장 빠른 시작 (단일 노드)

    kind create cluster --name dev
    kubectl cluster-info --context kind-dev
    kubectl get nodes

    삭제:

    kind delete cluster --name dev

    3) 실전용 멀티노드 + 포트 매핑 (Ingress 테스트용)

    아래 설정은 컨트롤플레인 1 + 워커 2, 호스트의 80/443을 노드포트로 매핑해 Ingress 컨트롤러 실습에 편합니다.

    kind-multi.yaml

    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    name: dev
    nodes:
    - role: control-plane
      extraPortMappings:
        - containerPort: 30080   # Ingress HTTP(NodePort) -> Host 80
          hostPort: 80
          protocol: TCP
        - containerPort: 30443   # Ingress HTTPS(NodePort) -> Host 443
          hostPort: 443
          protocol: TCP
    - role: worker
    - role: worker
    # 필요 시 Docker 브리지 서브넷/PodCIDR 조정:
    # networking:
    #   apiServerAddress: "0.0.0.0"
    #   podSubnet: "10.244.0.0/16"
    
    

    생성:

    kind create cluster --config kind-multi.yaml
    kubectl get nodes -o wide

    4) Ingress 컨트롤러 빠른 설치 (ingress-nginx 예)

    kind에서는 LoadBalancer가 없으므로 Ingress를 NodePort로 사용하거나 MetalLB를 추가합니다. 먼저 간단히 NodePort 방식:

    # ingress-nginx 설치 (커뮤니티 매니페스트)
    kubectl apply -f <https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml>
    
    # 준비 확인
    kubectl -n ingress-nginx get pods

    간단 테스트 앱:

    kubectl create deployment web --image=nginxdemos/hello
    kubectl expose deployment web --port=80
    
    cat <<'EOF' | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      ingressClassName: nginx
      rules:
      - host: localhost
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80
    EOF
    
    # 접속 (호스트)
    curl -s <http://localhost/>
    
    

    위 extraPortMappings 덕분에 호스트 80/443으로 바로 접근됩니다.


    5) LoadBalancer가 꼭 필요할 때 (MetalLB)

    # CRDs/컨트롤러 설치
    kubectl apply -f <https://raw.githubusercontent.com/metallb/metallb/v0.14.5/config/manifests/metallb-native.yaml>
    
    # kind Docker 브리지 대역에서 사용 가능한 IP 범위를 지정 (예: 172.18.255.200-172.18.255.250)
    # 실제 브리지 대역은 `docker network inspect kind`로 확인
    cat <<'EOF' | kubectl apply -f -
    apiVersion: metallb.io/v1beta1
    kind: IPAddressPool
    metadata: { name: default-address-pool, namespace: metallb-system }
    spec:
      addresses:
      - 172.18.255.200-172.18.255.250
    ---
    apiVersion: metallb.io/v1beta1
    kind: L2Advertisement
    metadata: { name: default, namespace: metallb-system }
    spec: {}
    EOF
    
    # 이제 Service type: LoadBalancer 사용 가능
    kubectl expose deploy web --type=LoadBalancer --name web-lb --port 80
    kubectl get svc web-lb -w
    
    

    6) 로컬 이미지 빠르게 쓰기 (빌드 → kind 클러스터로 push 없이 주입)

    # 로컬에서 Docker 이미지 빌드
    docker build -t myapp:dev .
    
    # kind 노드로 바로 로드 (ECR/Docker Hub push 불필요)
    kind load docker-image myapp:dev --name dev
    
    # 배포에서 image: myapp:dev 로 사용

    7) 자주 쓰는 kubectl/컨텍스트

    # 컨텍스트 확인/전환
    kubectl config get-contexts
    kubectl config use-context kind-dev
    
    # 리소스 보기
    kubectl get all -A
    kubectl describe deploy web
    kubectl logs deploy/web
    
    # 포트포워딩 (Ingress 없이 빠르게 확인)
    kubectl port-forward deploy/web 8080:80

    8) 윈도우/WSL2 팁 & 트러블슈팅

    • Docker Desktop → Settings → Resources 에서 CPU/메모리를 충분히 할당(예: CPU 4, RAM 6~8GB).
    • WSL2 커널 업그레이드 및 wsl --update 권장.
    • 회사 보안툴/프록시로 이미지 Pull 실패 시 사내 레지스트리 미러 설정 고려.
    • 포트 충돌 시 extraPortMappings의 hostPort를 다른 번호로 바꾸세요.
    • eBPF 실험(Cilium 등)은 로컬 커널/권한 이슈가 있을 수 있어, 간단 실습은 kind + ingress-nginx, 심화 성능/보안은 EKS/실서버에서 재현을 권장.
    반응형

    댓글