Istio-v1.12.6部署与bookinfo部署

Istio部署

istioctl部署

defaultdemominimalremoteemptypreview
核心组件
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.6
total 28
drwxr-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 LICENSE
drwxr-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.md
drwxr-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 list
Istio configuration profiles:
    default
    demo
    empty
    external
    minimal
    openshift
    preview
    remote

# 安装
[root@k8s-master-1 yaml]# istioctl install --set profile=demo
This 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-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-egressgateway-57bc7bdf76-frfzn    1/1     Running   0          4m38s
istio-ingressgateway-75db9dbd9d-hm82f   1/1     Running   0          4m38s
istiod-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 svc
NAME          TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
details       ClusterIP   10.0.35.208   <none>        9080/TCP   4m12s
kubernetes    ClusterIP   10.0.0.1      <none>        443/TCP    183d
productpage   ClusterIP   10.0.164.72   <none>        9080/TCP   4m11s
ratings       ClusterIP   10.0.157.24   <none>        9080/TCP   4m12s
reviews       ClusterIP   10.0.78.11    <none>        9080/TCP   4m12s
[root@k8s-master-1 istio-1.12.6]# kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
details-v1-79f774bdb9-crwv5       2/2     Running   0          4m15s
productpage-v1-6b746f74dc-n5pvc   2/2     Running   0          4m14s
ratings-v1-b6994bb9-js6xv         2/2     Running   0          4m15s
reviews-v1-545db77b95-8rphf       2/2     Running   0          4m14s
reviews-v2-7bf8c9648f-j4rfl       2/2     Running   0          4m14s
reviews-v3-84779c7bbc-4bmhv       2/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>.*</title>"
<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 gateway
NAME               AGE
bookinfo-gateway   18s

# 确定ingress ip和端口,如果EXTERNAL-IP值已设置,说明环境正在使用外部负载均衡,可以用其为ingress gateway 提供服务。 如果EXTERNAL-IP值为<none>(或持续显示<pending>), 说明环境没有提供外部负载均衡,无法使用ingress gateway。在这种情况下,你可以使用服务的NodePort访问网关
[root@k8s-master-1 istio-1.12.6]# kubectl get svc istio-ingressgateway -n istio-system
NAME                   TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)                                                                      AGE
istio-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_URL
	INGRESS_HOST=192.168.0.10   
	export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

# 查看访问链接
[root@k8s-master-1 istio-1.12.6]# echo $GATEWAY_URL
192.168.0.10:44332

# 访问测试
[root@k8s-master-1 istio-1.12.6]# curl -s http://${GATEWAY_URL}/productpage | grep -o "<title>.*</title>"
<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 services
	kubectl get destinationrules #-- there should be no destination rules
	kubectl get gateway #-- there should be no gateway
	kubectl get pods #-- the Bookinfo pods should be deleted
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺仔_牛奶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值