做者:justminenode
头条号:大数据与云原生linux
微信公众号:大数据与云原生git
创做不易,在知足创做共用版权协议的基础上能够转载,但请以超连接形式注明出处。github
为了方便你们阅读,能够关注头条号或微信公众号,后续全部的文章将在移动端首发,想学习更多云原生知识,请关注我。shell
随着微服务架构的流行,服务网格技术得到了业界的普遍关注,做为实现云原生的重要积木,各大厂商也纷纷开始布局,Amazon在2019年4月份推出了App Mesh;Google、IBM、Lyft联合开发了Istio。json
Istio做为下一代服务网格的总体解决方案,获得了业界的广泛承认,站在kubernetes巨人的肩膀上,极大地提升了分布式应用的研发和运维效率。ubuntu
2020是云原生普及的一年,如何部署、使用、运维Istio又是必需要学习知识,本篇但愿带给你们一个完美的入门体验。api
从Istio最新发布列表下载最新发布版本1.4.3压缩包,及其命令行工具(Istioctl),以下:浏览器
# 建立工做目录 mkdir -p /root/service-mesh/istio && cd /root/service-mesh/istio; # 下载 wget https://github.com/istio/istio/releases/download/1.4.3/istioctl-1.4.3-linux.tar.gz; ## istio也能够演示的时候在下载 wget https://github.com/istio/istio/releases/download/1.4.3/istio-1.4.3-linux.tar.gz;
话外音:请下载相同版本的Istioctl和Istio,避免没法预料的问题。安全
tar -vxzf istioctl-1.4.3-linux.tar.gz && cp istioctl /usr/local/bin;
为了知足不一样的安装需求,Istio内置了一系列的安装配置文件,生产环境建议以default
安装配置文件为起点。
话外音:可使用
istioctl profile list
命令查看内置配置文件列表,而后使用istioctl profile dump [配置文件名称]
打印配置文件内容。
# 安装 default # istioctl manifest apply --set profile=default - Applying manifest for component Base... ✔ Finished applying manifest for component Base. - Applying manifest for component Galley... - Applying manifest for component IngressGateway... - Applying manifest for component Citadel... - Applying manifest for component Kiali... - Applying manifest for component Prometheus... - Applying manifest for component Policy... - Applying manifest for component Pilot... - Applying manifest for component Injector... - Applying manifest for component Telemetry... ✔ Finished applying manifest for component IngressGateway. ✔ Finished applying manifest for component Citadel. ✔ Finished applying manifest for component Prometheus. ✔ Finished applying manifest for component Policy. ✔ Finished applying manifest for component Galley. ✔ Finished applying manifest for component Injector. ✔ Finished applying manifest for component Pilot. - Finished applying manifest for component Kiali. ✔ Finished applying manifest for component Telemetry. # 验证 # kubectl get pod -n istio-system NAME READY STATUS RESTARTS AGE istio-citadel-7c959c8d59-hssf4 1/1 Running 0 100m istio-galley-5479df66b5-tr5hf 2/2 Running 0 100m istio-ingressgateway-7c95796d59-s5sc2 1/1 Running 0 100m istio-pilot-656556b575-7zzht 2/2 Running 0 100m istio-policy-5b9b9f5cd9-788rg 2/2 Running 6 100m istio-sidecar-injector-7dbcc9fc89-554vg 1/1 Running 0 100m istio-telemetry-7d5b5947db-tgbmg 2/2 Running 6 100m prometheus-685585888b-5f77l 1/1 Running 0 100m
等待几分钟,当全部的组件状态都为Running时,表示安装成功。
经过将基础设施转移到Istio,使得应用开发者无需重复建设基础设施,只需专一于业务逻辑。Istio负责管理整个应用服务集合,这些服务集合组成的网络拓扑就叫服务网格,Istio提供了kiali来可视化整个服务网格。
# KIALI_USERNAME=$(read -p 'Kiali Username: ' uval && echo -n $uval | base64); Kiali Username: 用户名 # KIALI_PASSPHRASE=$(read -sp 'Kiali Passphrase: ' pval && echo -n $pval | base64); Kiali Passphrase: 密码 # cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Secret metadata: name: kiali namespace: istio-system labels: app: kiali type: Opaque data: username: $KIALI_USERNAME passphrase: $KIALI_PASSPHRASE EOF
# istioctl manifest apply --set values.kiali.enabled=true [...] ✔ Finished applying manifest for component Kiali. [...]
使用NodePort方式暴露kiali服务到互联网,以下:
话外音:应该根据
k8s
环境选择不一样联网方式,生产环境建议暴露为LoadLalancer
。
# kubectl -n istio-system edit svc kiali [...] spec: ports: - name: http-kiali [...] nodePort: 9527 type: NodePort [...]
浏览器键入地址http://[ip]:9527/kiali
,键入上面建立的凭证,登陆成功,以下:
本节将部署一个多语言异构化的微服务示例(Bookinfo),让你们对服务网格有一个清晰的认识。
productpage
微服务
调用details
和reviews
微服务,提供图书单品完整信息。
details
微服务
提供图书详细信息。
reviews
微服务
提供图书评论信息。
一共有三个版本。v1版本不会调用ratings
微服务;v2版本调用ratings
服务,并将每一个等级显示为1到5个黑色星号;v3版本调用ratings
服务,并将每一个等级显示为1到5个红色星号。
ratings
微服务
提供图书星级评分信息。
一图胜千言,总体架构以下:
将Bookinfo部署到k8s默认命名空间,即default。
kubectl label namespace default istio-injection=enabled
# 进入工做目录,解压刚刚下载的Istio root@just: cd /root/service-mesh/istio && tar -vxzf istio-1.4.3-linux.tar.gz # 使用kubectl部署到k8s root@just: kubectl apply -f istio-1.4.3/samples/bookinfo/platform/kube/bookinfo.yaml service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created deployment.apps/reviews-v2 created deployment.apps/reviews-v3 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created
# 为Bookinfo部署入口网关 root@just: kubectl apply -f istio-1.4.3/samples/bookinfo/networking/bookinfo-gateway.yaml gateway.networking.istio.io/bookinfo-gateway created virtualservice.networking.istio.io/bookinfo created # 获取网关地址 root@just: export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}') root@just: export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') root@just: export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT # 获取图书单品页地址 echo http://${GATEWAY_URL}/productpage
不停地刷新图书单品页,kiali会实时地绘制服务网格,以下:
基于权重流量的实时控制,以下:
对于服务的可观察性,kiali还提供了不少其余的功能,这也是Istio相较于其余服务网格框架的优点,这里就不展现了。
本篇使用Istioctl搭建了一套完整的Istio系统,先从战略上鸟瞰Istio,进一步从战术上学习Istio将更加容易,做为一个完整解决方案,后面系列将一步步学习如何运用Istio的链接、安全、控制、可观察性全面地治理分布式应用。
话外音:到目前为止,你们应该明白Istio是个什么东东了吧。
https://github.com/istio/istio/releases
https://istio.io/docs/setup/additional-setup/config-profiles
https://istio.io/docs/setup/getting-started
https://istio.io/docs/setup/install/istioctl/#customizing-the-configuration
https://istio.io/docs/reference/commands/istioctl
https://istio.io/docs/ops/diagnostic-tools/istioctl
https://istio.io/news/releases/1.4.x/announcing-1.4.3
https://istio.io/docs/examples/bookinfo
https://istio.io/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports
若是有什么疑问和看法,欢迎评论区交流。
若是你以为本篇文章对您有帮助的话,感谢您的【推荐】。
若是你对云原生感兴趣的话能够【关注我】。