zoukankan      html  css  js  c++  java
  • K8S集群部署istio

    简介

    Istio 提供一种简单的方式来为已部署的服务建立网络,该网络具有负载均衡、服务间认证、监控等功能,而不需要对服务的代码做任何改动。

    istio 适用于容器或虚拟机环境(特别是 k8s),兼容异构架构。

    istio 使用 sidecar(边车模式)代理服务的网络,不需要对业务代码本身做任何的改动。

    HTTP、gRPC、WebSocket 和 TCP 流量的自动负载均衡。

    istio 通过丰富的路由规则、重试、故障转移和故障注入,可以对流量行为进行细粒度控制;支持访问控制、速率限制和配额。

    istio 对出入集群入口和出口中所有流量的自动度量指标、日志记录和跟踪。

    对比国内阿里云和K8S官方维护的Nginx Ingress Controller及 Istio Gateway 比较

      Istio Gateway 阿里云Ingress Controller NGINX Ingress Controller
    根据HTTP Header选择路由规则 支持 支持 仅支持单个Header,不支持多个Header组合
    Header规则支持正则表达式 支持 支持 支持
    服务之间设置权重拆分流量 支持 支持 支持
    Header和权重规则组合使用 支持 支持 支持
    路由规则检查 支持 不支持 不支持
    路由规则粒度 service下的不同pod service service
    支持的协议 HTTP1.1/HTTP2/gRPC/TCP/Websockets/MongoDB HTTP1.1/HTTP2/gRPC/TCP/Websockets HTTP1.1/HTTP2/gRPC/TCP/Websockets

     部署istio

    1、下载istio官方的部署包网址:https://github.com/istio/istio/releases/tag/1.6.7
    wget https://github.com/istio/istio/releases/download/1.6.7/istio-1.6.7-linux-amd64.tar.gz
    2、解压安装包并加入环境变量中
    mkdir /application/
    tar xvf istio-1.6.7-linux-amd64.tar.gz -C /application /
    echo "export PATH=$PATH:/application/istio-1.6.7/bin" >>/etc/profile && source /etc/profile
    3、安装istio(ps:一定要保证k8s集群正常运行)
    [root@k8s-master ~]# kubectl get nodes
    NAME         STATUS   ROLES    AGE    VERSION
    k8s-master   Ready    master   7d2h   v1.18.0
    node-1       Ready    <none>   7d2h   v1.18.0
    node-2       Ready    <none>   7d2h   v1.18.0
    [root@k8s-master ~]# 
    4、安装
    [root@k8s-master bin]# istioctl manifest apply --set profile=demo
    Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
    ✔ Istio core installed
    ✔ Istiod installed
    ✔ Ingress gateways installed
    ✔ Egress gateways installed
    ✔ Addons installed
    ✔ Installation complete
    [root@k8s-master bin]#
    

    查询部署完成情况

    [root@k8s-master bin]# kubectl get svc -n istio-system
    NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                      AGE
    grafana                     ClusterIP      10.100.91.88     <none>        3000/TCP                                                                     2m5s
    istio-egressgateway         ClusterIP      10.106.229.1     <none>        80/TCP,443/TCP,15443/TCP                                                     2m6s
    istio-ingressgateway        LoadBalancer   10.111.48.40     <pending>     15021:30045/TCP,80:31929/TCP,443:31560/TCP,31400:31134/TCP,15443:31166/TCP   2m6s
    istiod                      ClusterIP      10.101.173.49    <none>        15010/TCP,15012/TCP,443/TCP,15014/TCP,853/TCP                                2m30s
    jaeger-agent                ClusterIP      None             <none>        5775/UDP,6831/UDP,6832/UDP                                                   2m5s
    jaeger-collector            ClusterIP      10.103.41.41     <none>        14267/TCP,14268/TCP,14250/TCP                                                2m5s
    jaeger-collector-headless   ClusterIP      None             <none>        14250/TCP                                                                    2m5s
    jaeger-query                ClusterIP      10.97.12.213     <none>        16686/TCP                                                                    2m5s
    kiali                       ClusterIP      10.105.102.92    <none>        20001/TCP                                                                    2m5s
    prometheus                  ClusterIP      10.98.88.198     <none>        9090/TCP                                                                     2m5s
    tracing                     ClusterIP      10.97.49.170     <none>        80/TCP                                                                       2m5s
    zipkin                      ClusterIP      10.111.114.233   <none>        9411/TCP                                                                     2m5s
    [root@k8s-master bin]# kubectl get pods -n istio-system
    NAME                                    READY   STATUS    RESTARTS   AGE
    grafana-b54bb57b9-4ncvl                 1/1     Running   0          2m28s
    istio-egressgateway-64bc874f5c-bxqb8    1/1     Running   0          2m29s
    istio-ingressgateway-6b947b8c5d-xdttt   1/1     Running   0          2m29s
    istio-tracing-9dd6c4f7c-vljvl           1/1     Running   0          2m28s
    istiod-654b4b468b-lfhgf                 1/1     Running   0          2m54s
    kiali-d45468dc4-q6wbn                   1/1     Running   0          2m28s
    prometheus-77566c9987-285jt             2/2     Running   0          2m28s
    [root@k8s-master bin]#

    设置可视化界面kiali为外部访问模式并查询nodeport号

    [root@k8s-master bin]# kubectl patch svc -n istio-system kiali -p '{"spec": {"type": "NodePort"}}'
    service/kiali patched
    [root@k8s-master bin]# kubectl describe svc -n istio-system kiali
    Name:                     kiali
    Namespace:                istio-system
    Labels:                   app=kiali
                              install.operator.istio.io/owning-resource=installed-state
                              install.operator.istio.io/owning-resource-namespace=istio-system
                              operator.istio.io/component=AddonComponents
                              operator.istio.io/managed=Reconcile
                              operator.istio.io/version=1.6.7
                              release=istio
    Annotations:              Selector:  app=kiali
    Type:                     NodePort
    IP:                       10.105.102.92
    Port:                     http-kiali  20001/TCP
    TargetPort:               20001/TCP
    NodePort:                 http-kiali  31822/TCP  #节点访问的端口
    Endpoints:                10.244.247.6:20001
    Session Affinity:         None
    External Traffic Policy:  Cluster
    Events:                   <none>
    [root@k8s-master bin]#
    

    访问node节点加上端口 192.168.10.112:31822 

     默认登陆账户和密码为admin/admin

    istio上部署测试应用bookinfo

    1、开启sidecar自动注入
    kubectl label namespace default istio-injection=enabled
    2、使用kubectl部署bookinfo并创建网关
    kubectl apply -f /application/istio-1.6.7/samples/bookinfo/platform/kube/bookinfo.yaml
    kubectl apply -f /application/istio-1.6.7/samples/bookinfo/networking/bookinfo-gateway.yaml 
    3、设置访问网关的 INGRESS_HOST 和 INGRESS_PORT 变量,查询是否有外部负载均衡器
    kubectl get svc istio-ingressgateway -n istio-system
    EXTERNAL-IP是none或是pending说明没有问题

    修改istio的网关为nodeport模式 

    kubectl patch service istio-ingressgateway -n istio-system -p '{"spec":{"type":"NodePort"}}'
    

    采用nodeport方式暴露istio-ingressgateway

    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}')
    #获取 ingress IP 地址:
    export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}')
    

    查询URL

    echo $INGRESS_HOST:$INGRESS_PORT
    192.168.10.112:30637
    

    使用浏览器访问bookinfo

    http://192.168.10.112:30637/productpage

     重复刷新可以发现星星发生变化说明部署成功

    参考地址:
    https://blog.csdn.net/weixin_44144334/article/details/107788292
    https://developer.aliyun.com/article/636511

    如有侵权请及时联系删除

  • 相关阅读:
    飞鱼星路由器配置端口映射
    Nginx 负载均衡配置和策略
    多个子路由器和主路由器怎么设置在同一个网段(变身无线交换机)
    iptables中DNAT、SNAT和MASQUERADE的理解
    图解正向代理、反向代理、透明代理
    CentOS 7 安装配置带用户认证的squid代理服务器
    MySQL 5.6下table_open_cache参数合理配置详解
    Linux SVN迁移备份的三种方法
    详解shell编程中2>&1用法
    安装配置OSA运维管理平台
  • 原文地址:https://www.cnblogs.com/huanglingfa/p/13895297.html
Copyright © 2011-2022 走看看