Mac M1使用kind创建k8s

mtain 2025年07月03日 5次浏览

1. 安装kind

# For Intel Macs
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-darwin-amd64
# For M1 / ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-darwin-arm64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind

或者使用brew

brew install kind

2. 创建kind集群

kind.config

apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 32000
    hostPort: 32000
    listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
    protocol: tcp # Optional, defaults to tcp
- role: worker

执行创建命令:

kind create cluster --config=kind.config

image.png

设置kubectl集群的信息:

kubectl cluster-info --context kind-kind

image.png

查看节点

kubectl get node
NAME                 STATUS   ROLES           AGE     VERSION
kind-control-plane   Ready    control-plane   6m51s   v1.33.1
kind-worker          Ready    <none>          6m40s   v1.33.1

3. 安装NGINX Ingress Controller

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

# 查看安装状态
kubectl get all --namespace ingress-nginx

安装不了也可不安装,本地环境可以使用kubectl port-forward做端口转发

kubectl port-forward service/nginx-service 1080:80

Forwarding from 127.0.0.1:1080 -> 80
Forwarding from [::1]:1080 -> 80
Handling connection for 1080
Handling connection for 1080

还可以使用nodePort,访问时:kind容器ip:nodePort端口

还可以在创建kind集群时,指定暴露一些端口

参考地址:https://ansible.readthedocs.io/projects/awx-operator/en/latest/installation/kind-install.html#kind-install