2

Istio 大型微服务系统管理工具

 1 year ago
source link: https://mikeygithub.github.io/2023/01/31/yuque/xogp27/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Istio 大型微服务系统管理工具

Istio 大型微服务系统管理工具 _
Mikey 2023年1月31日 晚上

3.5k 字

29 分钟

2 次

image.png

image.png

  1. 在基于的微服务体系结构中,都会存在一些需要解决的问题,例如当我们的不同服务(应用)直接进行交互访问,如何进行流量控制、鉴权、服务熔断、治理等问题,不同的微服务架构实现这些功能方式不一,像 Spring Cloud 与 Netflix OSS 是偏向于通过使用微服务的框架来实现,而基于 Kubernetes 的微服务体系是通过服务网格方式来进行实现

  2. 什么是服务网格(Service Mesh):服务网格指的是专门处理服务通讯的基础设施层,目前比较主流的有 Istio

Istio 是一个服务网格的实现,它使用功能强大的 Envoy 服务代理扩展了 Kubernetes,以建立一个可编程的、可感知的应用程序网络。Istio 与 Kubernetes 和传统工作负载一起使用,为复杂的部署带来了标准的通用流量管理、遥测和安全性。

流量管理:部署服务间路由,故障恢复和负载平衡等功能。
可观测性:提供流量和服务性能的端到端视图。
安全:跨服务进行加密,基于角色的访问和身份验证。

image.png

image.png

  1. 获取 istio
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.16.2 TARGET_ARCH=arm_64 sh -
  1. 移动可执行二进制文件到
cp istioctl /usr/bin/
istioctl version
  1. 安装 istio
istioctl install --set profile=demo -y
  1. 给命名空间添加标签,指示 Istio 在部署应用的时候,自动注入 Envoy 边车代理:
kubectl label namespace default istio-injection=enabled
kubectl apply -f 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
  1. 查看 Service
[root@k8s-master01 bookinfo]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demo ClusterIP 10.105.133.95 <none> 80/TCP 91d
details ClusterIP 10.98.114.171 <none> 9080/TCP 3m26s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 98d
nginx ClusterIP None <none> 80/TCP 14d
productpage ClusterIP 10.102.82.121 <none> 9080/TCP 3m15s
ratings ClusterIP 10.101.219.48 <none> 9080/TCP 3m15s
reviews ClusterIP 10.111.191.190 <none> 9080/TCP 3m15s
  1. 查看 Pod
kubectl get pod
kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>

经上述步骤部署成功后我们需要对其进行提供外部访问,需要创建 Istio 入站网关(Ingress Gateway), 它会在网格边缘把一个路径映射到路由。

  1. 把应用关联到 istio 网关
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
  1. 查看集群是否支持外部负载均衡
kubectl get svc istio-ingressgateway -n istio-system
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                                      AGE
istio-ingressgateway LoadBalancer 10.96.248.193 <pending> 15021:31675/TCP,80:30703/TCP,443:32396/TCP,31400:31654/TCP,15443:30816/TCP 88m

设置 EXTERNAL-IP 的值之后, 您的环境就有了一个外部的负载均衡器,可以将其用作入站网关。 但如果 EXTERNAL-IP 的值为 (或者一直是 状态), 则您的环境则没有提供可作为入站流量网关的外部负载均衡器。 在这个情况下,您还可以用服务(Service)的节点端口访问网关。

  1. 通过节点端口访问网关,设置入站端口
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}')
  1. 设置入站访问入口
export INGRESS_HOST=worker-node-address
//如
export INGRESS_HOST=192.168.100.21
export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')

设置环境变量

export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

查看访问 Endpoint

echo "$GATEWAY_URL"
  1. 验证外部访问
echo "http://$GATEWAY_URL/productpage"
http://192.168.100.21:30703/productpage

创建可视化仪表盘

  1. 创建可视化仪表盘
kubectl apply -f samples/addons
kubectl rollout status deployment/kiali -n istio-system
  1. 访问仪表盘
istioctl dashboard kiali
#上面的只能是集群内部访问,想要外部访问可以指定开发的节点地址
istioctl dashboard kiali --address 192.168.100.21

image.png

image.png

image.png

image.png

  1. 官网 :https://istio.io/latest/zh/

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK