• 快速部署istio(入门)


    试验环境是一个3节点的k8s集群(一个master两个worker),k8s版本是1.8.0。

    先看效果图
    在这里插入图片描述

    1.下载istio

    转到Istio 版本页面下载操作系统的安装文件,或自动下载并解压最新版本(Linux 或 macOS):

    $ curl -L https://istio.io/downloadIstio | sh -
    
    • 1

    要是下载不下来就到istio的发布页面https://github.com/istio/istio/releases/下载安装包,用sftp上传到master节点,并解压缩:

    tar -zxvf istio-1.14.3-linux-amd64.tar.gz
    
    • 1

    进入解压缩后的安装包目录:

    cd istio-1.14.3
    
    tree -L 1
    .
    ├── bin       二进制文件istioctl
    ├── LICENSE
    ├── manifests
    ├── manifest.yaml
    ├── README.md
    ├── samples   该目录下包含示例的应用程序(yaml)
    └── tools
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    将istioctl添加到系统PATH环境变量:

    export PATH=$PWD/bin:$PATH
    
    • 1

    2.安装istio

    对于此安装,我们使用demo 配置文件。选择它具有一组良好的测试默认值,但还有其他配置文件用于生产或性能测试。生产环境部署istio时建议使用default profile,而演示和评估istio建议部署demo profile。

    istioctl install --set profile=demo -y
    ✔ Istio core installed
    ✔ Istiod installed
    ✔ Egress gateways installed
    ✔ Ingress gateways installed
    ✔ Installation complete
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    安装完成后,查看一下namespace istio-system下的Pod和Service:

      kubectl get pod -n istio-system
      
    NAME                                    READY   STATUS    RESTARTS   AGE
    grafana-6fbd7fb4cd-8m45g                1/1     Running   0          28m
    istio-egressgateway-c577988fd-9rdhb     1/1     Running   1          154m
    istio-ingressgateway-7f78c4d95d-m86rv   1/1     Running   1          154m
    istiod-65dfd45474-mzglb                 1/1     Running   1          155m
    jaeger-78775f676f-rg2zn                 1/1     Running   0          28m
    kiali-774555c697-nf7s4                  1/1     Running   0          28m
    prometheus-9c555c848-jzpkg              2/2     Running   0          28m
    
    
    kubectl get svc -n istio-system
    
    
    NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                      AGE
    grafana                ClusterIP      10.102.3.100             3000/TCP                                                                     28m
    istio-egressgateway    ClusterIP      10.99.36.224             80/TCP,443/TCP                                                               154m
    istio-ingressgateway   LoadBalancer   10.105.48.20          15021:32333/TCP,80:31806/TCP,443:30052/TCP,31400:32126/TCP,15443:30997/TCP   154m
    istiod                 ClusterIP      10.99.67.187             15010/TCP,15012/TCP,443/TCP,15014/TCP                                        155m
    jaeger-collector       ClusterIP      10.103.123.76            14268/TCP,14250/TCP,9411/TCP                                                 28m
    kiali                  ClusterIP      10.107.205.129           20001/TCP,9090/TCP                                                           28m
    prometheus             ClusterIP      10.99.164.3              9090/TCP                                                                     28m
    tracing                ClusterIP      10.108.27.105            80/TCP,16685/TCP                                                             28m
    zipkin                 ClusterIP      10.111.136.10            9411/TCP                                                                     28m
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    可以看出部署了istiod, istio-ingressgateway, istio-egressgateway

    因为后边要部署的示例应用是部署在default namespace中的,下面给default namespace添加istio-injection=enabled标签,指示后续在此namespace部署应用时,自动注入envoy sidecar(边车)代理。

    kubectl label namespace default istio-injection=enabled
    namespace/default labeled
    
    • 1
    • 2

    3.部署示例应用

    下面部署bookinfo示例应用,bookinfo这个应用是一个在线书店的演示系统

    部署Bookinfo示例应用程序

    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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    应用程序将启动。随着每个 pod 准备就绪,Istio sidecar 将随之部署。

    kubectl get services
    
    NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
    details       ClusterIP   10.98.209.177           9080/TCP   155m
    kubernetes    ClusterIP   10.96.0.1               443/TCP    117d
    productpage   ClusterIP   10.108.233.14           9080/TCP   155m
    ratings       ClusterIP   10.102.56.130           9080/TCP   155m
    reviews       ClusterIP   10.108.140.23           9080/TCP   155m
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    kubectl get pods
    
    NAME                              READY   STATUS    RESTARTS   AGE
    details-v1-96959d5b9-zjktn        2/2     Running   2          156m
    productpage-v1-864f666bf9-zr2qf   2/2     Running   2          156m
    ratings-v1-5ffd6f78d9-pbc4g       2/2     Running   2          156m
    reviews-v1-79d4597cbf-jzkjf       2/2     Running   2          156m
    reviews-v2-dfd4d6b59-qwl85        2/2     Running   1          156m
    reviews-v3-c8964d889-nmgc2        2/2     Running   2          156m
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    重新运行之前的命令,等待所有 pod 报告 READY2/2和 STATUSRunning后再进行下一步。这可能需要几分钟,具体取决于您的平台。

    验证到目前为止一切正常。运行以下命令,通过检查响应中的页面标题来查看应用程序是否在集群内运行并提供 HTML 页面:

    $ kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o ".*"
    
    
    Simple Bookstore App
    
    • 1
    • 2
    • 3
    • 4

    此时Bookinfo应用虽然已经部署,但还不能被外界访问。需要创建Ingress Gateway(Istio入站网关)在网格边缘把一个路径映射到路由。

    将应用关联到istio网关:

    kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
    
    gateway.networking.istio.io/bookinfo-gateway created
    virtualservice.networking.istio.io/bookinfo created
    
    • 1
    • 2
    • 3
    • 4

    确保配置没有问题:

    istioctl analyze
    
    ✔ No validation issues found when analyzing namespace: default.
    
    • 1
    • 2
    • 3

    4.从集群外部访问bookinfo应用

    因为这里使用的k8s集群没有cloud driver和外部负载均衡器,Service istio-ingressgateway的ExternalIP是处于Pending状态的。

    kubectl get svc istio-ingressgateway -n istio-system
    
    NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)     AGE
    istio-ingressgateway   LoadBalancer   10.105.48.20        15021:32333/TCP,80:31806/TCP,443:30052/TCP,31400:32126/TCP,15443:30997/TCP   163m
    
    • 1
    • 2
    • 3
    • 4

    设置入口端口:

    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
    • 2

    GKE:

    $ export INGRESS_HOST=workerNodeAddress
    
    • 1
     export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')
    
    • 1
    1. 设置GATEWAY_URL

      $ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
      
      • 1
    2. 确保 IP 地址和端口已成功分配给环境变量:

      $ echo "$GATEWAY_URL"
      192.168.1.107:31806
      
      • 1
      • 2

    验证外部访问

    通过使用浏览器查看 Bookinfo 产品页面,确认可以从外部访问 Bookinfo 应用程序。

    • 运行以下命令以检索 Bookinfo 应用程序的外部地址。

      $ echo "http://$GATEWAY_URL/productpage"
      
      • 1
    • 将上一个命令的输出粘贴到您的 Web 浏览器中,并确认显示 Bookinfo 产品页面。

    • 使用istio-ingressgateway的NodePort从集群外部访问bookinfo应用,这里其http的NodePort是31806。 浏览器打开http://192.168.1.107:31806/productpage确保可以打开bookinfo的应用界面。

    5.部署和查看Istio仪表板

    Istio 集成了几个不同的遥测应用程序。这些可以帮助您了解服务网格的结构、显示网格的拓扑以及分析网格的健康状况。

    使用以下说明部署Kiali仪表板以及PrometheusGrafanaJaeger

    安装Kiali 和其他插件并等待它们被部署。

    kubectl apply -f samples/addons
    kubectl rollout status deployment/kiali -n istio-system
    
    Waiting for deployment "kiali" rollout to finish: 0 of 1 updated replicas are available...
    deployment "kiali" successfully rolled out
    
    • 1
    • 2
    • 3
    • 4
    • 5

    等待kiali部署完成后,使用istioctl dashboard --address 0.0.0.0 kiali命令启动istio dashboard kiali的监听,外部访问kiali(master节点ip:20001/kiali)。
    在这里插入图片描述

    本文基于istio官方文档https://istio.io/latest/zh/docs/setup/getting-started/。

  • 相关阅读:
    【2023年11月第四版教材】第16章《采购管理》(第二部分)
    游戏内存优化
    springcloud-Eureka
    使用HTML制作静态网站 中国传统文化 丝绸之路 (学生网页设计作业源码)
    2.1_2进程的状态与转换
    Tekton 设计简介 及 实践
    强化自主可控,润开鸿发布基于RISC-V架构的开源鸿蒙终端新品
    Nginx01-HTTP简介与Nginx简介(安装、命令介绍、目录介绍、配置文件介绍)
    MyBatis学习:#占位符和 $占位符的区别
    本地缓存 guava
  • 原文地址:https://blog.csdn.net/crayon0/article/details/126234153