--- tags: kubernetes, docker, k3d, k3s --- # k3d init :::danger k3d 是社群開發的 k3s in docker 的快速建立叢集的工具,方便在 docker 內使用 k3s 建立 kubernetes 叢集 由於是純社群開發的工具,且因為是跑在 docker 內部,我會建議用在 kubernetes 上的服務開發用途,而非正式服務部署 ::: * [k3s官網](https://k3s.io/) * [k3d 官網](https://k3d.io/) * [在k3d上快速安装Istio,助你在本地灵活使用K8S!](https://dockone.io/article/9917) * [K3d and Istio (Service Mesh - Governing the data plane)](https://gist.github.com/rafi/ebc50f0b0cd12dc061e4c69b3ee2521c) :::info 前置作業:安裝 docker ::: 使用 k3d 建立 k8s 叢集,只有開放 k8s api server port 的命令 :::warning 這邊的 cluster 建立命令資訊如下 叢集名稱 = service-lab api server (master node) 數量 = 1 agent server (worker node) 數量 = 6 以下命令有開本機的 8080 port 配對到 k3s 的 loadbalance (80 port),有需要開其他 port 可以另外設定 ::: 因為我這邊使用的服務都有搭配 istio 做事,跟 k3d 內建的網路工具 traefik 有衝突,所以要關掉 ```bash k3d cluster create service-lab --servers 1 --agents 6 --port 8443:443@loadbalancer --port 8080:80@loadbalancer --api-port 6443 --k3s-arg '--disable=traefik@server:0' ``` 如果沒有要關的話,命令如下 ```bash k3d cluster create service-lab --servers 1 --agents 6 --api-port 6443 --port 8080:80@loadbalancer ``` ```bash # 建立完叢集才想到要暴露 k8s 服務的進入 port 的時候可以這樣加 k3d cluster edit service-lab --port-add 8080:80@loadbalancer # or when create cluster k3d cluster create service-lab --servers 1 --agents 6 --port 8080:80@loadbalancer --api-port 6443 --k3s-arg '--disable=traefik@server:0' ``` 移除 Cluster ```bash= k3d cluster delete service-lab ``` 停止 Cluster ```bash= k3d cluster stop service-lab ``` 啟動 Cluster ```bash= k3d cluster start service-lab ``` # istio install (use helm) :::info 用這個只是為了快速把 k3d 中的 istio 環境弄起來,"`我個人`" 比較偏好使用 istioctl 安裝 istio 該如何選擇安裝方式可以參考 [istio 官方對各項安裝方式的說明與介紹](https://istio.io/latest/about/faq/#setup) ::: REF: https://istio.io/latest/docs/setup/platform-setup/k3d/ ```bash helm repo add istio https://istio-release.storage.googleapis.com/charts helm repo update kubectl create namespace istio-system helm install istio-base istio/base -n istio-system --wait helm install istiod istio/istiod -n istio-system --wait # optional #kubectl label namespace istio-system istio-injection=enabled helm install istio-ingressgateway istio/gateway -n istio-system --wait ```