天天看點

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

11月13~15日,KubeCon 上海大會召開,雲原生是這個秋天最火熱的技術。很多同學來問如何上手 Kubernetes和Istio 服務網格開發。本文将幫助你利用Docker CE桌面版,15分鐘在筆記本上從零搭建 Kubernetes + Istio開發環境,開啟雲原生之旅。

說明:本文測試通過環境 Docker CE 18.09 (Kubernetes 1.10.3) 以及 Istio 1.0.4

先決條件,你需要一個 Docker for Mac或者Docker for Windows的安裝包,如果沒有請下載下傳下載下傳 Docker CE最新版本。由于Kubernetes大量的容器鏡像在 gcr.io, 無法在國内保證穩定的通路。我們提供了一些工具腳本,幫助從阿裡雲鏡像服務下載下傳所需鏡像

首先,

git clone https://github.com/AliyunCont...

cd k8s-for-docker-desktop

Docker for Mac 開啟 Kubernetes

為 Docker daemon 配置 Docker Hub 的中國官方鏡像加速 https://registry.docker-cn.com

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

可選操作: 為 Kubernetes 配置 CPU 和 記憶體資源,建議配置設定 4GB 或更多記憶體。

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

預先從阿裡雲Docker鏡像服務下載下傳 Kubernetes 所需要的鏡像, 可以通過修改 images.properties 檔案加載你自己需要的鏡像!

./load_images.sh

開啟 Kubernetes,并等待 Kubernetes 開始運作

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

Docker for Windows 開啟 Kubernetes

為 Docker daemon 配置 Docker Hub 的中國官方鏡像加速 https://registry.docker-cn.com

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

可選操作: 為 Kubernetes 配置 CPU 和 記憶體資源,建議配置設定 4GB 或更多記憶體。

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

預先從阿裡雲Docker鏡像服務下載下傳 Kubernetes 所需要的鏡像, 可以通過修改 images.properties 檔案加載你自己需要的鏡像

使用 Bash shell

./load_images.sh

使用 PowerShell

.load_images.ps1

說明: 如果因為安全政策無法執行 PowerShell 腳本,請在 “以管理者身份運作” 的 PowerShell 中執行 Set-ExecutionPolicy RemoteSigned 指令。

開啟 Kubernetes,并等待 Kubernetes 開始運作

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

配置 Kubernetes

可選操作: 切換Kubernetes運作上下文至 docker-for-desktop

kubectl config use-context docker-for-desktop

驗證 Kubernetes 叢集狀态

kubectl cluster-info

kubectl get nodes

部署 Kubernetes dashboard

kubectl create -f https://raw.githubusercontent...

kubectl create -f kubernetes-dashboard.yaml

開啟 API Server 通路代理

kubectl proxy

通過如下 URL 通路 Kubernetes dashboard

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default

說明:如果測試 Istio,不需要安裝 Ingress,如果需要 Ingress 可以參考 https://github.com/AliyunCont... 中 Ingress相關章節

安裝 Helm

可以根據文檔安裝 helm https://github.com/helm/helm/...

在 Mac OS 上安裝

Use homebrew on Mac

brew install kubernetes-helm

Install Tiller into your Kubernetes cluster

helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --skip-refresh

update charts repo (Optional)

helm repo update

在Windows上安裝

Use Chocolatey on Windows

choco install kubernetes-helm

Install Tiller into your Kubernetes cluster

helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --skip-refresh

update charts repo (Optional)

helm repo update

配置 Istio

可以根據文檔安裝 Istio https://istio.io/docs/setup/k...

下載下傳 Istio 1.0.4 并安裝 CLI

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

cd istio-1.0.4/

export PATH=$PWD/bin:$PATH

在Windows上,您可以手工下載下傳Istio安裝包,或者把getLatestIstio.ps1拷貝到你希望下載下傳 Istio 的目錄,并執行 - 說明:根據社群提供的安裝腳本修改而來

.getLatestIstio.ps1

通過 Helm chart 安裝 Istio

helm install install/kubernetes/helm/istio --name istio --namespace istio-system

檢視 istio 釋出狀态

helm status istio

為 default 名空間開啟自動 sidecar 注入

kubectl label namespace default istio-injection=enabled

kubectl get namespace -L istio-injection

安裝 Book Info 示例

kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

确認示例應用在運作中

export GATEWAY_URL=localhost:80

curl -o /dev/null -s -w "%{http_code}n" http://${GATEWAY_URL}/productpage

可以通過浏覽器通路

http://localhost/productpage

說明:如果目前80端口已經被占用或保留,我們可以編輯 install/kubernetes/helm/istio/values.yaml 檔案中

Gateway 端口進行調整,比如将 80 端口替換為 8888 端口

## You can add custom gateway ports
- port: 8888  # Changed from 80
  targetPort: 80
  name: http2
  nodePort: 31380
           

然後執行如下指令并生效

kubectl delete service istio-ingressgateway -n istio-system

helm upgrade istio install/kubernetes/helm/istio

學習 Istio

大家參照 Istio 開始學習吧, https://istio.io/zh/docs/exam...

15分鐘在筆記本上搭建 Kubernetes + Istio開發環境Use homebrew on MacInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)Use Chocolatey on WindowsInstall Tiller into your Kubernetes clusterupdate charts repo (Optional)

删除執行個體應用

samples/bookinfo/platform/kube/cleanup.sh

解除安裝 Istio

helm del --purge istio

kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system

總結

阿裡雲Kubernetes服務 (ACK) 已經對 Istio提供了支援,并将Istio和阿裡雲進行了深度整合,比如可以通過阿裡雲日志服務支援基于Jaeger的全鍊路監控,基于雲監控提升Istio可觀測性和報警能力等。後續也将進一步簡化Kubernetes和Istio的開發者體驗,讓大家友善地把 Kubernetes + Istio 應用無縫遷移上雲。

繼續閱讀