> 文档中心 > Istio-v1.12.6部署与bookinfo部署

Istio-v1.12.6部署与bookinfo部署


Istio部署

istioctl部署

default demo minimal remote empty preview
核心组件
istio-egressgateway
istio-ingressgateway
istiod
# 下载包wget https://github.com/istio/istio/releases/download/1.12.6/istio-1.12.6-linux-amd64.tar.gz# 拷贝命令[root@k8s-master-1 ~]# cp istio-1.12.6/bin/istioctl /usr/bin# 目录结构[root@k8s-master-1 ~]# ll istio-1.12.6total 28drwxr-x---  2 root root    22 Mar 29 04:51 bin# bin/目录下,包含istioctl的客户端文件。istioctl工具用于手动注入Envoy sidecar代理。-rw-r--r--  1 root root 11348 Mar 29 04:51 LICENSEdrwxr-xr-x  5 root root    52 Mar 29 04:51 manifests-rw-r-----  1 root root   827 Mar 29 04:51 manifest.yaml-rw-r--r--  1 root root  5866 Mar 29 04:51 README.mddrwxr-xr-x 21 root root  4096 Mar 29 04:51 samples  # samples/目录下,有示例应用程序drwxr-xr-x  3 root root    57 Mar 29 04:51 tools# 查看存在那些配置[root@k8s-master-1 istio-1.12.6]# istioctl profile listIstio configuration profiles:    default    demo    empty    external    minimal    openshift    preview    remote# 安装[root@k8s-master-1 yaml]# istioctl install --set profile=demoThis will install the Istio 1.12.6 demo profile with ["Istio core" "Istiod" "Ingress gateways" "Egress gateways"] components into the cluster. Proceed? (y/N) y✔ Istio core installed   ✔ Istiod installed    ✔ Ingress gateways installed     ✔ Egress gateways installed      ✔ Installation complete      Making this installation the default for injection and validation.Thank you for installing Istio 1.12.  Please take a few minutes to tell us about your install/upgrade experience!  https://forms.gle/FegQbc9UvePd4Z9z7# 卸载istioctl manifest generate --set profile=demo | kubectl delete --ignore-not-found=true -f -# 查看运行的pod[root@k8s-master-1 yaml]# kubectl get pods -n istio-systemNAME READY   STATUS    RESTARTS   AGEistio-egressgateway-57bc7bdf76-frfzn    1/1     Running   0   4m38sistio-ingressgateway-75db9dbd9d-hm82f   1/1     Running   0   4m38sistiod-7b78cd84bb-6blxp   1/1     Running   0   5m42s

Istio在线bookinfo

  • 在线书店-bookinfo该应用由四个单独的微服务构成,这个应用模仿在线书店的一个分类,显示一本书的信息,页面上会显示一本书的描述,书籍的细节(ISBN、页数等),以及关于这本书的一些评论
  • Bookinfo 应用分为四个单独的微服务:
    • productpage. 这个微服务会调用 detailsreviews 两个微服务,用来生成页面。
    • details. 这个微服务中包含了书籍的信息。
    • reviews. 这个微服务中包含了书籍相关的评论。它还会调用 ratings 微服务。
    • ratings. 这个微服务中包含了由书籍评价组成的评级信息。
  • reviews 微服务有 3 个版本
    • v1 版本不会调用 ratings 服务。
    • v2 版本会调用 ratings 服务,并使用 1 到 5 个黑色星形图标来显示评分信息。
    • v3 版本会调用 ratings 服务,并使用 1 到 5 个红色星形图标来显示评分信息

在这里插入图片描述

​ 要在 Istio 中运行这一应用,无需对应用自身做出任何改变。 您只要简单的在 Istio 环境中对服务进行配置和运行,具体一点说就是把 Envoy sidecar 注入到每个服务之中。 最终的部署结果将如下图所示

在这里插入图片描述

​ 所有的微服务都和 Envoy sidecar 集成在一起,被集成服务所有的出入流量都被 sidecar 所劫持,这样就为外部控制准备了所需的 Hook,然后就可以利用 Istio 控制平面为应用提供服务路由、遥测数据收集以及策略实施等功能

部署

# Istio 默认自动注入 Sidecar. 请为 default 命名空间打上标签 istio-injection=enabled[root@k8s-master-1 yaml]# kubectl label namespace default istio-injection=enabled# 使用 kubectl 部署应用,会启动全部的四个服务,其中也包括了 reviews 服务的三个版本(v1、v2 以及 v3)[root@k8s-master-1 istio-1.12.6]# kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml# 确认所有的服务和 Pod 都已经正确的定义和启动[root@k8s-master-1 istio-1.12.6]# kubectl get svcNAME   TYPE CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGEdetailsClusterIP   10.0.35.208   <none> 9080/TCP   4m12skubernetes    ClusterIP   10.0.0.1      <none> 443/TCP    183dproductpage   ClusterIP   10.0.164.72   <none> 9080/TCP   4m11sratingsClusterIP   10.0.157.24   <none> 9080/TCP   4m12sreviewsClusterIP   10.0.78.11    <none> 9080/TCP   4m12s[root@k8s-master-1 istio-1.12.6]# kubectl get podsNAME  READY   STATUS    RESTARTS   AGEdetails-v1-79f774bdb9-crwv52/2     Running   0   4m15sproductpage-v1-6b746f74dc-n5pvc   2/2     Running   0   4m14sratings-v1-b6994bb9-js6xv  2/2     Running   0   4m15sreviews-v1-545db77b95-8rphf2/2     Running   0   4m14sreviews-v2-7bf8c9648f-j4rfl2/2     Running   0   4m14sreviews-v3-84779c7bbc-4bmhv2/2     Running   0   4m14s# 要确认 Bookinfo 应用是否正在运行,请在某个 Pod 中用 curl 命令对应用发送请求,例如 ratings:[root@k8s-master-1 istio-1.12.6]#  kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o ".*"<title>Simple Bookstore App</title>

访问测试

​ 现在 Bookinfo 服务启动并运行中,您需要使应用程序可以从外部访问 Kubernetes 集群,例如使用浏览器。可以用 Istio Gateway 来实现这个目标

# 为应用程序定义 Ingress 网关:kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml# 确认网关创建完成[root@k8s-master-1 istio-1.12.6]# kubectl get gatewayNAME AGEbookinfo-gateway   18s# 确定ingress ip和端口,如果EXTERNAL-IP值已设置,说明环境正在使用外部负载均衡,可以用其为ingress gateway 提供服务。 如果EXTERNAL-IP值为(或持续显示), 说明环境没有提供外部负载均衡,无法使用ingress gateway。在这种情况下,你可以使用服务的NodePort访问网关[root@k8s-master-1 istio-1.12.6]# kubectl get svc istio-ingressgateway -n istio-systemNAME     TYPE    CLUSTER-IP    EXTERNAL-IP   PORT(S)AGEistio-ingressgateway   LoadBalancer   10.0.66.219   <pending>     15021:48114/TCP,80:44332/TCP,443:47475/TCP,31400:41888/TCP,15443:37629/TCP   25m# 若自身环境未使用外部负载均衡器,需要通过 node port 访问。可以通过以下命令获取Istio Gateway的地址export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')export TCP_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].nodePort}')# 设置GATEWAY_URLINGRESS_HOST=192.168.0.10   export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT# 查看访问链接[root@k8s-master-1 istio-1.12.6]# echo $GATEWAY_URL192.168.0.10:44332# 访问测试[root@k8s-master-1 istio-1.12.6]# curl -s http://${GATEWAY_URL}/productpage | grep -o ".*"<title>Simple Bookstore App</title>

在这里插入图片描述

​ 用浏览器打开网址http://$GATEWAY_URL/productpage,也就是192.168.40.180:30871/productpage来浏览应用的 Web 页面。如果刷新几次应用的页面,就会看到 productpage 页面中会随机展示 reviews 服务的不同版本的效果(红色、黑色的星形或者没有显示)

卸载bookinfo

# 删除路由规则,并销毁应用的 Pod[root@k8s-master-1 istio-1.12.6]# sh samples/bookinfo/platform/kube/cleanup.sh# 确认应用已经关停kubectl get virtualservices #-- there should be no virtual serviceskubectl get destinationrules #-- there should be no destination ruleskubectl get gateway #-- there should be no gatewaykubectl get pods #-- the Bookinfo pods should be deleted