天天看點

使用kind在mac本地搭建k8s及istio

作者:碼匠亂炖

之前使用multipass裝ubuntu,然後再用microk8s搭建k8s,這會直接用orbstack及kind在本地搭建k8s及istio

安裝

orbstack

通過orbstack這個位址下載下傳,主要是開銷低,用來替代docker desktop

添加國内源

~/.orbstack/config/docker.json

{
	"registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com",
        "https://registry.hub.docker.com"
    ]
}
           
重新開機orbstack

安裝go

brew install go
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
           

安裝kind

go install sigs.k8s.io/[email protected]
export PATH=$HOME/go/bin:$PATH
kind create cluster
Creating cluster "kind" ...
⢎⡠ Ensuring node image (kindest/node:v1.27.3) 
⢎⠁ Ensuring node image (kindest/node:v1.27.3) 
 ✓ Ensuring node image (kindest/node:v1.27.3) 
 ✓ Preparing nodes 
 ✓ Writing configuration 
⠎⠁ Starting control-plane ️
⠈⠁ Starting control-plane ️
⠈⠱ Starting control-plane ️
⠈⡱ Starting control-plane ️
 ✓ Starting control-plane ️
 ✓ Installing CNI 
 ✓ Installing StorageClass 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Have a nice day! 
           

使用

kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://127.0.0.1:51562
CoreDNS is running at https://127.0.0.1:51562/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

kubectl get pods -A
NAMESPACE            NAME                                         READY   STATUS    RESTARTS   AGE
kube-system          coredns-5d78c9869d-2rjmk                     1/1     Running   0          2m9s
kube-system          coredns-5d78c9869d-n72hp                     1/1     Running   0          2m9s
kube-system          etcd-kind-control-plane                      1/1     Running   0          2m23s
kube-system          kindnet-tjvh9                                1/1     Running   0          2m10s
kube-system          kube-apiserver-kind-control-plane            1/1     Running   0          2m24s
kube-system          kube-controller-manager-kind-control-plane   1/1     Running   0          2m23s
kube-system          kube-proxy-sjg2h                             1/1     Running   0          2m10s
kube-system          kube-scheduler-kind-control-plane            1/1     Running   0          2m23s
local-path-storage   local-path-provisioner-6bc4bddd6b-hpzrd      1/1     Running   0          2m9s
           

安裝istio

curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.5 sh -
           

或者下載下傳https://github.com/istio/istio/releases/download/1.18.2/istio-1.18.2-osx-arm64.tar.gz

解壓,并将istio-1.18.2/bin添加到PATH中

istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete                                                                               Making this installation the default for injection and validation.

kubectl get ns
NAME                 STATUS   AGE
default              Active   75m
istio-system         Active   104s
kube-node-lease      Active   75m
kube-public          Active   75m
kube-system          Active   75m
local-path-storage   Active   75m
➜  ~ kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-egressgateway-75db994b58-jdztx    1/1     Running   0          61s
istio-ingressgateway-79bb75ddbb-965t8   1/1     Running   0          61s
istiod-68cb9f5cb6-jksg5                 1/1     Running   0          115s
           

小結

使用orbstack及kind在本地搭建k8s及istio顯得極為輕量,首先orbstack比multipass起個machine輕量許多,其次kind比k3s,minikube更為輕量,雖然是單節點,但是特别适合學習和研究。

doc

  • orbstack
  • kind
  • 安裝istio

繼續閱讀