# run rancher in k3d (with istio) :::info - k3d 的命令說明可以參考 https://hackmd.io/@YuChia/create-k3s-cluster-use-k3d - 筆記內關於 host 相關的名稱請自行依據實際狀況進行調整!! - 此筆記內使用的 istio ingress 為預設安裝的 ingress,如果有自訂 ingress gateway 的話請自行調整 istio gateway 設定 - 以下內容都是在 windows + docker 的環境下完成的 - windows 內可以利用 C:\Windows\System32\drivers\etc\hosts 這個檔案設定 domain ::: ## init k3d & install istio :::warning 1. 因為 rancher 會有 kubernetes 版本支援問題,所以在建立叢集時必須設定使用的 kubernetes 版本 2. 因為 rancher 必須要使用 https 連線,所以 `--port 8443:443@loadbalancer` 不能省略 (頂多 8443 這個 port 可以換成你喜歡的 port) 3. 因為 rancher 要走 https 的關係,ingressgateway 要跟 rancher 安裝在同個 namespace 以避免無法找到憑證的問題,所以並沒有在安裝 isito 的同時一起安裝 > 第三點待確認,基本上 ingressgateway 跟服務安裝在不同的 namespace 應該是沒問題的,不確定是因為要使用憑證的原因還是我的設定錯誤導致無法正常連線 ::: ```bash k3d cluster create service-lab --servers 1 --agents 3 --port 8443:443@loadbalancer --port 8080:80@loadbalancer --api-port 6443 --k3s-arg '--disable=traefik@server:0' --image rancher/k3s:v1.26.9-k3s1 ## 建立好叢集後,kubeconfig 會自動設定到 k3d 建立的叢集 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 # helm install istio-ingressgateway istio/gateway -n istio-system --wait ``` ## install rancher :::info 1. 撰寫此筆記時,Rancher 版本為 v2.7.6 2. 安裝時大致上與 "[此篇筆記](https://hackmd.io/@YuChia/rke2-and-rancher-install-command#Rancher-install)" 差不多 3. rancher 對 cert-manager 版本倚賴的說明與測試狀況可以在 [官方文件](https://ranchermanager.docs.rancher.com/getting-started/installation-and-upgrade/resources/upgrade-cert-manager) 找到 ::: ### 先套用一些需要的 CRD ```bash kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.7.1/cert-manager.crds.yaml ``` ### 設定 helm repo ```bash helm repo add rancher-stable https://releases.rancher.com/server-charts/stable helm repo add jetstack https://charts.jetstack.io helm repo update ``` ### 建立 namespace 與安裝倚賴工具 ```bash kubectl create namespace cattle-system helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.7.1 --wait helm install istio-ingressgateway istio/gateway -n cattle-system --wait ``` ### 安裝 rancher 並取得初次登入的管理者密碼 :::info 如果你想指定安裝版本,可以在安裝時加上 `--version [版號]` 來設定,例如 --version 2.7.6 ::: ```bash helm install rancher rancher-stable/rancher --namespace cattle-system --set hostname=rancher.mydomain.org # 如果你要使用外部憑證 # helm install rancher rancher-stable/rancher --namespace cattle-system --set hostname=rancher.mydomain.org --set external-tls # in linux kubectl get secret --namespace cattle-system bootstrap-secret -o jsonpath="{.data.bootstrapPassword}" | base64 -d # in windows ## 自行用 base64 解碼取得的字串 kubectl get secret --namespace cattle-system bootstrap-secret -o jsonpath="{.data.bootstrapPassword}" ``` ### 套用 istio 路由 先拉我準備好的 k8s 資源 git repo,或是參考我後面使用的路徑,自己下載檔案回來或是重寫一份 ```bash git clone https://github.com/YuChia-Wei/k8s-resource-manifests.git ``` #### 使用 rancher 自簽憑證 ```bash kubectl apply -f ./istio-network/rancher-salf-ssl/Gateway.yaml kubectl apply -f ./istio-network/rancher-salf-ssl/VirtualService.yaml ``` #### 使用外部憑證 :::info 1. 此段設定適用於你有網路設備處理憑證,並且進入內部網路環境時,你希望全部都走 80 port 2. 請確認你在安裝時有下 `--set external-tls` 參數 ::: ```bash kubectl apply -f ./istio-network/rancher-external-ssl/Gateway.yaml kubectl apply -f ./istio-network/rancher-external-ssl/VirtualService.yaml kubectl apply -f ./istio-network/rancher-external-ssl/DistinationRule.yaml ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up