11月13~15日,KubeCon 上海大会召开,云原生是这个秋天最火热的技术。不少同窗来问如何上手 Kubernetes和Istio 服务网格开发。本文将帮助你利用Docker CE桌面版,15分钟在笔记本上从零搭建 Kubernetes + Istio开发环境,开启云原生之旅。php
说明:本文测试经过环境 Docker CE 18.09 (Kubernetes 1.10.3) 以及 Istio 1.0.4css
先决条件,你须要一个 Docker for Mac或者Docker for Windows的安装包,若是没有请下载下载 Docker CE最新版本。因为Kubernetes大量的容器镜像在 gcr.io, 没法在国内保证稳定的访问。咱们提供了一些工具脚本,帮助从阿里云镜像服务下载所需镜像node
首先,nginx
git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop cd k8s-for-docker-desktop
为 Docker daemon 配置 Docker Hub 的中国官方镜像加速 https://registry.docker-cn.com
git
可选操做: 为 Kubernetes 配置 CPU 和 内存资源,建议分配 4GB 或更多内存。github
预先从阿里云Docker镜像服务下载 Kubernetes 所须要的镜像, 能够经过修改 images.properties
文件加载你本身须要的镜像sql
./load_images.sh
开启 Kubernetes,并等待 Kubernetes 开始运行docker
为 Docker daemon 配置 Docker Hub 的中国官方镜像加速 https://registry.docker-cn.com
shell
可选操做: 为 Kubernetes 配置 CPU 和 内存资源,建议分配 4GB 或更多内存。api
预先从阿里云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
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default
说明:若是测试 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
能够经过浏览器访问
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 开始学习吧, 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 应用无缝迁移上云。
原文连接本文为云栖社区原创内容,未经容许不得转载。