본문 바로가기
Cloud/Kubernetes

[Kubernetes] kind로 실습 환경 구성하기

by The Future Engineer, Lucy 2024. 10. 21.

Kind란?

Kind는 로컬 컴퓨터 환경에 쿠버네티스 클러스터를 손쉽고 빠르게 설치하기 위해 만들어진 도구입니다.

Kind는 Go 언어를 기반으로 만들어졌으며, Docker이미지를 기반으로 kubeadm을 이용하여 클러스터를 배포합니다.

자세한 내용은 위 이미지를 통해 kind 공식 홈페이지에서 확인하시면 됩니다.

Kind 설치하기

설치 가이드 원본 URL : https://kind.sigs.k8s.io/docs/user/quick-start/#installation

MacOS

brew install kind

Windows

choco install kind

Linux

curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.15.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe

Kind로 클러스터 생성

클러스터 생성

kind create cluster # Default cluster context 이름은 'kind' 로 생성
kind create cluster --name lucy # cluster context 이름을 'lucy' 로 지정

클러스터 생성 확인

kind get clusters
kubectl cluster-info --context lucy

클러스터 삭제

kind delete cluster # 클러스터 한 개 삭제

kind delete clusters kind-local-cluster # 클러스터 하나 이상 삭제

설정 파일을 이용한 Kind 클러스터 생성

클러스터 생성

설정 파일을 이용한 클러스터 생성

설정파일을 이용해서 kind 클러스터를 생성할 수 있습니다.

kind create cluster --config kind-example-config.yaml

3개 노드 클러스터 생성

3개 노드(1 controller, 2worker) 클러스터 설정

# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

6개 노드 클러스터 생성

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker

쿠버네티스 버전 설정

쿠버네티스 버전에 따른 이미지는 https://github.com/kubernetes-sigs/kind/releases에서 확인 가능합니다.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.16.4@sha256:b91a2c2317a000f3a783489dfb755064177dbc3a0b2f4147d50f04825d016f55
- role: worker
  image: kindest/node:v1.16.4@sha256:b91a2c2317a000f3a783489dfb755064177dbc3a0b2f4147d50f04825d016f55

네트워크 설정

  • Pod Subnet 설정
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  podSubnet: {IP 주소}

기본적으로 IPv4 pod subnet으로 "10.244.0.0/16"을 사용합니다.

  • Service Subnet 설정
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  serviceSubnet: {IP 주소}

기본적으로 IPv4 pod subnet으로 "10.96.0.0/16"을 사용합니다.

  • Default CNI 설정

Caliaco와 같은 3rd party CNI 사용을 위해서는 default CNI 설치를 하지 말아야 합니다..

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  # default CNI가 설치 되지 않는다.
  disableDefaultCNI: true
  • kube-proxy 모드 설정

iptables 또는 IPVS 중에 선택해서 사용 가능하고 default 는 iptables입니다.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  kubeProxyMode: "ipvs"

최종 클러스터 생성

  • 클러스터 yaml 작성
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: cwave-cluster
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  image: kindest/node:{{쿠버네티스 버전}}
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
- role: worker
  image: kindest/node:{{쿠버네티스 버전}}
- role: worker
  image: kindest/node:{{쿠버네티스 버전}}
networking:
  serviceSubnet: {IP 주소}
  podSubnet: {IP 주소}
  • 클러스터 생성
# 생성
kind create cluster  --config {yaml 파일}

# 삭제
kind delete cluster --name {클러스터 이름}
  • 클러스터 접속 정보 확인
kind get kubeconfig --internal --name {클러스터 이름}

클러스터 생성 결과

$ kind create cluster --config .\set-cluster.yaml
Creating cluster "lab-cluster" ...
 • Ensuring node image (kindest/node:v1.31.0) 🖼  ...
 ✓ Ensuring node image (kindest/node:v1.31.0) 🖼
 • Preparing nodes 📦 📦 📦 📦   ...
 ✓ Preparing nodes 📦 📦 📦 📦
 • Writing configuration 📜  ...
 ✓ Writing configuration 📜
 • Starting control-plane 🕹️  ...
 ✓ Starting control-plane 🕹️
 • Installing CNI 🔌  ...
 ✓ Installing CNI 🔌
 • Installing StorageClass 💾  ...
 ✓ Installing StorageClass 💾
 • Joining worker nodes 🚜  ...
 ✓ Joining worker nodes 🚜
Set kubectl context to "kind-lab-cluster"
You can now use your cluster with:

kubectl cluster-info --context kind-lab-cluster

Have a nice day! 👋

'Cloud > Kubernetes' 카테고리의 다른 글

[k8s] Kubernetes 로그 - EFK 구축  (1) 2024.09.28
[k8s] Kubernetes 로그 - EFK 개요  (1) 2024.09.28