首页 > 其他分享 >Istio 基于头部分流

Istio 基于头部分流

时间:2024-08-30 16:29:58浏览次数:2  
标签:gray name nginx app Istio istio 分流 头部 home

分离部署istio下面的示例把数据平面和控制平面分开部署。

自动生成配置文件可以istioctl profile dump empty加上配置文档然后进行修改。

生产集群注意配置资源限制。

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: control-plane
spec:
  profile: default
  components:
    ingressGateways:
    - name: istio-ingressgateway
      enabled: false
    egressGateways:
    - name: istio-egressgateway
      enabled: false
  hub: harbor.kailinesb.com/ops

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: ingress-gateway
spec:
  profile: empty
  components:
    ingressGateways:
    - name: ingressgateway
      namespace: istio-system
      enabled: true
      label:
        istio: ingressgateway
      k8s:
        resources:
          requests:
            cpu: 100m
            memory: 160Mi
  hub: harbor.kailinesb.com/ops

加了这两个配置

root@dev-km-01-175:~/istio# kubectl  -n istio-system get cm istio -o yaml
apiVersion: v1
data:
  mesh: |-
    accessLogFile: /dev/stdout
    defaultConfig:
      discoveryAddress: istiod.istio-system.svc:15012
      tracing:    # <<< 这里
        sampling: 40
        zipkin:
          address: zipkin.istio-system:9411
    accessLogEncoding: "JSON"    # <<< 这里
......

创建两个版本的应用。一个是正常版本,另外一个是灰度版本。

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-home
    version: nginx-home-prod
  name: nginx-home
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-home
      version: nginx-home-prod
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-home
        version: nginx-home-prod
    spec:
      containers:
      - image: harbor.kailinesb.com/ops/nginx:1.22.1
        name: nginx
---
# 灰度版本app
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-home
    version: nginx-home-gray
  name: nginx-home-gray
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-home
      version: nginx-home-gray
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-home
        version: nginx-home-gray
    spec:
      containers:
      - image: harbor.kailinesb.com/ops/nginx:1.22.1
        name: nginx
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-home
  name: nginx-home
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-home
  type: ClusterIP


kubectl exec -it deploy/nginx-home-gray -- \
sed -i 's#nginx#nginx-gray#g' /usr/share/nginx/html/index.html

# 把部署的app打上如下的标签。
root@dev-km-01-175:~/istio# kubectl get deploy --show-labels
root@dev-km-01-175:~/istio# kubectl -n jian-butler-gray get deploy --show-labels
NAME              READY   UP-TO-DATE   AVAILABLE   AGE   LABELS
nginx-home        1/1     1            1           97s   app=nginx-home,version=nginx-home-prod
nginx-home-gray   1/1     1            1           33m   app=nginx-home,version=nginx-home-gray

# 现在访问svc会出现两种版本都出现的情况。

image

创建gw

cat 01-nginx-app-gw.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: nginx-app-gw
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "nginx-app.kailinesb.com"

创建vs

cat 02-nginx-app-vs.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-app-vs
spec:
  hosts:
  - "nginx-app.kailinesb.com"
  gateways:
  - nginx-app-gw
  http:
  - route:
    - destination:
        host: nginx-home    # nginx-home是svc

通过从ingressgateway网关访问nginx-app.kailinesb.com现在会随机返回两个版本的内容。

192.168.21.175 nginx-app.kailinesb.com

image

image

通过dr声明版本之间的关系,这样vs才能分清楚流量分发到哪个版本。

root@dev-km-01-175:~/istio# cat dr.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: nginx-app-dr
spec:
  host: nginx-home 
  subsets:
  - name: version-prod
    labels:
      version: nginx-home-prod
  - name: version-gray
    labels:
      version: nginx-home-gray

更新vs

cat 02-nginx-app-vs.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nginx-app-vs
spec:
  hosts:
  - "nginx-app.kailinesb.com"
  gateways:
  - nginx-app-gw
  http:
  - match:
    - headers:
        version:
          exact: "gray"
    route:
    - destination:
        host: nginx-home
        subset: version-gray
  - route:
    - destination:
        host: nginx-home
        subset: version-prod

访问测试。

[ops@deploy21-146 ~]$ curl -s http://192.168.21.175 -H 'version: gray'  -H 'Host: nginx-app.kailinesb.com' | grep Welco
<title>Welcome to nginx-gray!</title>
<h1>Welcome to nginx-gray!</h1>

[ops@deploy21-146 ~]$ curl -s http://192.168.21.175  -H 'Host: nginx-app.kailinesb.com' | grep Welco
<title>Welcome to nginx!</title>
<h1>Welcome to nginx!</h1>

Istio 监控部署

jaeger 流量追踪。

jaeger和zipkin会一起安装,jaeger兼容后者。

kiali 观察网格服务状态,这个调用zipkin把链路追踪的功能也集成了。

流量可观测jaeger和配置可观测kiali依赖grafana和prometheus。

标签:gray,name,nginx,app,Istio,istio,分流,头部,home
From: https://www.cnblogs.com/gshelldon/p/18388967

相关文章

  • HTTP协议头部与Keep-Alive
    一、HTTP头部字段 一)字段总结1Accept:告诉WEB服务器自己接受什么介质类型,/表示任何类型,type/*表示该类型下的所有子类型,type/sub-type。2Accept-Charset:浏览器申明自己接收的字符集Accept-Encoding:浏览器申明自己接收的编码方法,通常指定压缩方法,是否支持压缩,支持什......
  • abp vnext请求头增加,以及请求头增加公共头部回调
    context.Services.AddHttpContextAccessor();要访问请求头的话,要加上这个语句;追加请求头的方法:1、服务层服务的HttpApi.Client项目Module类的ConfigureServices方法开头位置添加如下代码:context.Services.AddTransient<AddHeaderHandler>();context.Services.AddHttpClient(Prod......
  • 【Head3D X 2024 三维RGB - 头部三维数据集-RGB-高精度-三维建模渲染-高清】
    Head3DX2024商用数据集一、数据标注信息(数据量20w+)1)高清原图(短边高于等于2000像素)2)三维头部mesh(obj文件)3)三维虚拟相机内参(npy文件)4)二维头部关键点信息(npy文件5)姿态角(pitch,roll,yaw)检测(基于相机坐标系)三维维建模渲染示例:(Head3D2024三维渲染......
  • 非扁平网络场景下,基于开源istio治理CCE多集群
    本文分享自华为云社区《基于开源istio治理CCE多集群--非扁平网络场景》,作者:可以交个朋友。一背景鉴于扁平网络模式下对网络存在严格的要求,需要所有集群处于同一个扁平网络,PodIP地址互通且不重叠,Service网段也不能冲突。这些网络需求在实际环境中可能难以满足,限制了该模式......
  • istio可用工具kiali
    1.安装kubectlcreate-fsamples/addons/   #安装这个目录下的所有插件//kubectlcreate-fsamples/addons/kiali.yaml//kubectlcreate-fsamples/addons/jaeger.yaml2.修改kialiservicetypekubectleditsvc kiali-n istio-system  把ClusterIp改为......
  • 助力人效提升!火山引擎数智平台助推头部新能源车企业务增长
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群。 近年来,国内新能源汽车产业保持高速增长,形成了规模化市场。根据中国汽车工业协会的公开数据,去年国内新能源汽车产量达958.7万辆,销量达949.5万辆,同比分别增长35.8%和37.9%。而今年,仅截至5......
  • 微信小程序 自定义 头部导航栏
    最近公司小程序有个需求简单来说就是除开首页和我的页面其他页面左上角都需要有一个返回按钮能返回首页最开始我说的是不用做那两个tabbar页面下面可以点啊结果客户那边非得要没办法客户就是上帝那么话不多说我们直接开干首先是新建一个custom-navbar组件目录结构如......
  • CSS综合案例(快报模块头部制作)
    (大家好,今天我们将继续来学习CSS的相关知识,大家可以在评论区进行互动答疑哦~加油!......
  • 缓存与http头部
    1https://juejin.cn/post/6844903764566999054实践这一次,彻底搞懂浏览器缓存机制2https://www.cyc2018.xyz/计算机基础/HTTP/HTTP.html#缓存cyc#缓存3浏览器http请求缓存,cache-control是服务器设置,还是浏览器设置本文链接:https://blog.csdn.net/qq_17335549/article/deta......
  • `useHeadSafe`:安全生成HTML头部元素
    title:useHeadSafe:安全生成HTML头部元素date:2024/7/17updated:2024/7/17author:cmdragonexcerpt:摘要:“useHeadSafe”是Vue.js组合函数,用于安全生成HTML头部元素,通过限制输入值格式避免XSS等安全风险,提供了安全值白名单确保只有安全属性被添加。categories:......