11月13~15日,KubeCon 上海大會召開,雲原生是這個秋天最火熱的技術。不少同窗來問如何上手 Kubernetes和Istio 服務網格開發。本文將幫助你利用Docker CE桌面版,15分鐘在筆記本上從零搭建 Kubernetes + Istio開發環境,開啓雲原生之旅。html
說明:本文測試經過環境 Docker CE 18.09 (Kubernetes 1.10.3) 以及 Istio 1.0.4node
先決條件,你須要一個 Docker for Mac或者Docker for Windows的安裝包,若是沒有請下載下載 Docker CE最新版本。因爲Kubernetes大量的容器鏡像在 gcr.io, 沒法在國內保證穩定的訪問。咱們提供了一些工具腳本,幫助從阿里雲鏡像服務下載所需鏡像git
首先,github
git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop cd k8s-for-docker-desktop
爲 Docker daemon 配置 Docker Hub 的中國官方鏡像加速 https://registry.docker-cn.com
docker
可選操做: 爲 Kubernetes 配置 CPU 和 內存資源,建議分配 4GB 或更多內存。shell
預先從阿里雲Docker鏡像服務下載 Kubernetes 所須要的鏡像, 能夠經過修改 images.properties
文件加載你本身須要的鏡像api
./load_images.sh
開啓 Kubernetes,並等待 Kubernetes 開始運行瀏覽器
爲 Docker daemon 配置 Docker Hub 的中國官方鏡像加速 https://registry.docker-cn.com
安全
可選操做: 爲 Kubernetes 配置 CPU 和 內存資源,建議分配 4GB 或更多內存。微信
預先從阿里雲Docker鏡像服務下載 Kubernetes 所須要的鏡像, 能夠經過修改 images.properties
文件加載你本身須要的鏡像
使用 Bash shell
./load_images.sh
使用 PowerShell
.\load_images.ps1
說明: 若是由於安全策略沒法執行 PowerShell 腳本,請在 「以管理員身份運行」 的 PowerShell 中執行Set-ExecutionPolicy RemoteSigned
命令。
開啓 Kubernetes,並等待 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.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
或
kubectl create -f kubernetes-dashboard.yaml
開啓 API Server 訪問代理
kubectl proxy
經過以下 URL 訪問 Kubernetes dashboard
說明:若是測試 Istio,不須要安裝 Ingress,若是須要 Ingress 能夠參考 https://github.com/AliyunContainerService/k8s-for-docker-desktop 中 Ingress相關章節
能夠根據文檔安裝 helm https://github.com/helm/helm/blob/master/docs/install.md
# 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
# 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 https://istio.io/docs/setup/kubernetes/
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 install install/kubernetes/helm/istio --name istio --namespace istio-system
helm status istio
default
名空間開啓自動 sidecar 注入kubectl label namespace default istio-injection=enabled kubectl get namespace -L istio-injection
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
能夠經過瀏覽器訪問
說明:若是當前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 開始學習吧, https://istio.io/zh/docs/examples/bookinfo/
samples/bookinfo/platform/kube/cleanup.sh
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 應用無縫遷移上雲。
原文連接 更多技術乾貨 請關注阿里云云棲社區微信號 :yunqiinsight