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

2024. 10. 21. 22:22·Cloud/Kubernetes

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

# 25.08.08 추가
winget install kubernetes.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 설정

Calico와 같은 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란?  (1) 2024.11.16
[k8s] Kubernetes 로그 - PLG 개요  (1) 2024.11.04
[k8s] Kubernetes 로그 - PLG 구축  (0) 2024.11.04
[k8s] Kubernetes 로그 - EFK 구축  (1) 2024.09.28
[k8s] Kubernetes 로그 - EFK 개요  (1) 2024.09.28
'Cloud/Kubernetes' 카테고리의 다른 글
  • [k8s] Kubernetes 로그 - PLG 개요
  • [k8s] Kubernetes 로그 - PLG 구축
  • [k8s] Kubernetes 로그 - EFK 구축
  • [k8s] Kubernetes 로그 - EFK 개요
The Engineer, Lucy
The Engineer, Lucy
  • The Engineer, Lucy
    Growing up for My Future💕
    The Engineer, Lucy
    • Instagram
    • GitHub
  • 전체
    오늘
    어제
    • 분류 전체보기 (187)
      • Linux (26)
      • Infra (9)
      • Cloud (28)
        • AWS (4)
        • GCP (4)
        • Docker (4)
        • Kubernetes (14)
        • IaC (2)
      • NGINX (1)
      • DevOps (3)
      • Computer Science (17)
        • Data Structure (0)
        • Algorithms (1)
        • Operating System (3)
        • Network (11)
        • Database System (2)
      • Coding Test (97)
        • Algorithms (89)
        • SQL (7)
      • ETC (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 공지사항

  • 링크

    • Lucy's Instagram
    • Lucy's GitHub
  • 인기 글

  • 태그

    K8s
    리눅스
    쿠버네티스
    docker
    Java
    Shell Script
    Shell
    AWS
    프로그래머스
    Baekjoon
    쉘 스크립트
    셸 스크립트
    Kubernetes
    bfs
    리눅스마스터 2급
    백준
    terraform
    도커
    cs 기초 지식 정리
    코딩테스트 공부
    network
    티스토리챌린지
    네트워크
    너비우선탐색
    Linux
    오블완
    자바
    programmers
    다이나믹 프로그래밍
    네트워크 기초 지식
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
The Engineer, Lucy
[k8s] kind로 Kubernetes 실습 환경 구성하기
상단으로

티스토리툴바