Kubespray로 Kubernetes 클러스터 생성하기
사전 작업
- 최소 필요 조건
- 2 CPU
- 2 GB memory
- 모든 노드에 대한 고유한 호스트 이름, MAC 주소, prodcut_uuid
ip link
sudo cat /sys/class/dmi/id/product_uuid
awk '{printf "%-20s %-20s %-20s %-20s\n", $1, $2, $3, $4}' /proc/cgroups
모든 subsystem의 enabled
값이 1
이어야 합니다.
프로젝트 생성
컨테이너 사용하기
kubespray의 기본 기능만 사용하면서 인벤토리만 관리하면 된다면 컨테이너를 활용하는 것이 편리합니다.
kubespray/
└── inventory/
podman run --rm -it \
--mount type=bind,src=$PWD/inventory,dst=/myinventory \
quay.io/kubespray/kubespray:v2.28.1 \
cp -rfp /kubespray/inventory/sample/. /myinventory
kubespray/
└── inventory/
├── group_vars/
│ └── ...
└── hosts.yaml
아래 명령어로 컨테이너 내에서 작업을 하면 됩니다.
podman run --rm -it \
--mount type=bind,src=${PWD}/inventory,dst=/kubespray/inventory \
-e ANSIBLE_HOST_KEY_CHECKING=False \
-e ANSIBLE_TIMEOUT=60 \
-e ANSIBLE_LOAD_CALLBACK_PLUGINS=True \
-e ANSIBLE_STDOUT_CALLBACK=yaml \
quay.io/kubespray/kubespray:v2.28.1 \
bash
인벤토리 작성
Reference
- 인벤토리 작성은 Inventory 문서를 참고하시면 됩니다.
inventory/hosts.yaml
all:
hosts:
<hostname>:
ansible_host: <host>
ip: <ip>
etcd:
hosts:
<hostname>:
kube_control_plane:
hosts:
<hostname>:
kube_node:
hosts:
<hostname>:
bastion:
hosts: {}
k8s_cluster:
children:
kube_control_plane:
kube_node:
all
hosts
<hostname>
- Node의 호스트 이름입니다.
- 일치하지 않으면 설정한 값으로 변경됩니다.
ansible_host: <ip|hostname>
- ansible이 접속할 주소입니다.
ip: <ip>
- Node의 IP 주소입니다.
클러스터 생성
./
├── inventory/
│ ├── group_vars/
│ │ ├── all/
│ │ │ ├── all.yml
│ │ │ └── ...
│ │ ├── k8s_cluster/
│ │ │ ├── addons.yml
│ │ │ ├── k8s-cluster.yml
│ │ │ └── ...