[Kubernetes] Cluster API 맛만 보기
어쩌다가
진짜 이전에 스쳐 지나가면서 들었던 Cluster API가 갑자기 생각났다.
그냥 그랬다.
그래서 그냥 진짜 개념만 맛만 보려고 공식 독스랑 훑어봤다.
Cluster API는 무엇인가요?
오퍼레이터 패턴으로 Cluster를 설치하는 방식이라고 한다.
중앙에 관리 클러스터를 배치하고 해당 클러스터에 Cluster API Controller를 배포한다.
이 Cluster API Controller는 추상 클래스와 유사한 역할을 한다.
근데 왜? Cluster는 벤더 매니지드 클러스터 일 수도 있고, 직접 구축한 온프렘 클러스터일 수도 있고, 로컬 클러스터일 수도 있기 때문이다.
어떻게 쓰나요?
# EKS 예시
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: cluster-eks
spec:
clusterNetwork:
pods:
cidrBlocks: [192.168.0.0/16]
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
kind: AWSManagedCluster
name: cluster-eks
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
kind: AWSManagedControlPlane
name: cluster-eks
# Docker 클러스터 예시
kind: DockerCluster
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
metadata:
name: my-cluster-docker
---
kind: Cluster
apiVersion: cluster.x-k8s.io/v1beta1
metadata:
name: my-cluster
spec:
infrastructureRef:
kind: DockerCluster
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
name: my-cluster-docker
이렇게 EKS나 Docker 클러스터의 예시가 보인다.
위의 예시처럼, 여러 벤더를 대상으로 관리를 지원한다.
Docker 클러스터의 경우에는 Docker 프로바이더를 위한 환경변수를 주입하고, Management 클러스터와 Workload 클러스터를 세팅한다.
## Clustercli 설치
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.4/clusterctl-darwin-arm64 -o clusterctl
chmod +x ./clusterctl
sudo mv ./clusterctl /usr/local/bin/clusterctl
clusterctl version
## Management cluster 설치
export CLUSTER_TOPOLOGY=true
clusterctl init --infrastructure docker
## Workload cluster 설치
clusterctl generate cluster capi-quickstart --flavor development \
--kubernetes-version v1.31.0 \
--control-plane-machine-count=3 \
--worker-machine-count=3 \
> capi-quickstart.yaml
kubectl apply -f capi-quickstart.yaml
kubectl get cluster
# NAME CLUSTERCLASS PHASE AGE VERSION
# capi-quickstart quick-start Pending 15m v1.31.0
Cluster API가 관리하는 영역은 다음과 같은데, 흔히 우리가 서비스 레벨로 운영하던 쿠버네티스를 클러스터 단위로 라이프사이클을 관리하기 위한 선언적 API 다.
- vm 정의를 위한 Machine
- 컨트롤 플레인, 워커노드 구성-관리를 위한 MachineSet
- 인프라 구성과 함께 MachineSet을 관리하기 위한 MachineDeployment
- Pod - ReplicaSet - Deployment 관계로 봐도 된다.
구성요소를 살펴보면 아래와 같은 CRD들이 정의되어 있다.
- Bootstrap Provider
- ControlPlane Provider
- Core
- ClusterClass
- AddOns
GitHub - crossplane-contrib/cross-capi-metal
Contribute to crossplane-contrib/cross-capi-metal development by creating an account on GitHub.
github.com
또, 요렇게 크로스플레인이랑 통합되는 케이스가 있는 것 같다.
Terraform 같은 IaC 대신 선언적으로 클러스터를 관리한다는 개념에서 유사하게 볼 수 있을 것 같은데, 여기까지는 아직 잘 모르겠다.
참고 자료
Introduction - The Cluster API Book
Cluster API is a Kubernetes sub-project focused on providing declarative APIs and tooling to simplify provisioning, upgrading, and operating multiple Kubernetes clusters. Started by the Kubernetes Special Interest Group (SIG) Cluster Lifecycle, the Cluster
cluster-api.sigs.k8s.io
Controllers - The Cluster API Book
Cluster API has a number of controllers, both in the core Cluster API and the reference providers, which move the state of the cluster toward some defined desired state through the process of controller reconciliation. Documentation for the CAPI controller
cluster-api.sigs.k8s.io