Google Code Prettify

2023年10月28日 星期六

install Kubernetes cluster@Macbook M2

要認真的安裝一個正式營運環境可以用的 K8s cluster,一定是需要許多實體機器 (bare metal) 或是 VM,但是,僅僅要測試用的話,有許多的方法,這裡要使用 Kind 在 Macbook M2 上安裝一個含有一個 control-plane、三個 worker node 的 Kubernetes cluster。

1. 安裝 Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. 安裝 Docker

brew install --cask docker

3. 安裝 Kind

brew install kind

4. 創建 Kind 配置文件,如下: (存檔為 kind-config.yaml)

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0
- role: worker
  image: kindest/node:v1.28.0
image 的版本可以在 https://hub.docker.com/r/kindest/node/tags 找到。

5. 創建 Kubernetes cluster

kind create cluster --name my-cluster --config kind-config.yaml


用 docker ps 及 kubectl get nodes 檢查一下 K8s cluster 是否正常運作。

Kind 是在 Docker 上架設 K8s cluster,所以和完全用 bare metal 或 VM 架設的仍會有所不同,包括要連入那些 node,不是透過 ssh,而是用 docker exec -it 指令。


如果要刪除 cluster,指令如下:
kind delete cluster --name my-cluster