首页 > 其他分享 >9、istio配置redirect-and-rewrite

9、istio配置redirect-and-rewrite

时间:2023-07-13 23:32:11浏览次数:36  
标签:redirect name rewrite app istio demoapp backend spec metadata

1、demoappv10

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: demoappv10
    version: v1.0
  name: demoappv10
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  selector:
    matchLabels:
      app: demoapp
      version: v1.0
  template:
    metadata:
      labels:
        app: demoapp
        version: v1.0
    spec:
      containers:
      - image: ikubernetes/demoapp:v1.0
        imagePullPolicy: IfNotPresent
        name: demoapp
        env:
        - name: "PORT"
          value: "8080"
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP

2、demoappv11

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: demoappv11
    version: v1.1
  name: demoappv11
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  selector:
    matchLabels:
      app: demoapp
      version: v1.1
  template:
    metadata:
      labels:
        app: demoapp
        version: v1.1
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/lavamusic/public:demoapp-v1.1
        imagePullPolicy: IfNotPresent
        name: demoapp
        env:
        - name: "PORT"
          value: "8080"
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        resources:
          limits:
            cpu: 50m

3、配置service

---
apiVersion: v1
kind: Service
metadata:
  name: demoapp
spec:
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: demoapp
  type: ClusterIP

4、配置proxy

apiVersion: apps/v1
kind: Deployment
metadata:
  name: proxy
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: proxy
  template:
    metadata:
      labels:
        app: proxy
    spec:
      containers:
        - env:
          - name: PROXYURL
            value: http://demoapp:8080
          image: registry.cn-shenzhen.aliyuncs.com/lavamusic/public:proxy-v0.1.1
          imagePullPolicy: IfNotPresent
          name: proxy
          ports:
            - containerPort: 8080
              name: web
              protocol: TCP
          resources:
            limits:
              cpu: 50m
---
apiVersion: v1
kind: Service
metadata:
  name: proxy
spec:
  ports:
    - name: http-80
      port: 80
      protocol: TCP
      targetPort: 8080
  selector:
    app: proxy
---

5、配置dr

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: demoapp
spec:
  host: demoapp
  subsets:
  - name: v10
    labels:
      version: v1.0
  - name: v11
    labels:
      version: v1.1

6、配置backend

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: backend
    version: v3.6
  name: backendv36
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  selector:
    matchLabels:
      app: backend
      version: v3.6
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: backend
        version: v3.6
    spec:
      containers:
      - image: ikubernetes/gowebserver:v0.1.0
        imagePullPolicy: IfNotPresent
        name: gowebserver
        env:
        - name: "SERVICE_NAME"
          value: "backend"
        - name: "SERVICE_PORT"
          value: "8082"
        - name: "SERVICE_VERSION"
          value: "v3.6"
        ports:
        - containerPort: 8082
          name: web
          protocol: TCP
        resources:
          limits:
            cpu: 50m
---
apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  ports:
    - name: http-web
      port: 8082
      protocol: TCP
      targetPort: 8082
  selector:
    app: backend
    version: v3.6
---

7、配置vs-demoapp

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: demoapp
spec:
  hosts:
  - demoapp
  http:
  - name: rewrite
    match:
    - uri:
        prefix: /canary
    rewrite:
      uri: /
    route:
    - destination:
        host: demoapp
        subset: v11
  #- name: redirect
  #  match:
  #  - uri:
  #      prefix: "/backend"
  #  redirect:
  #    uri: /
  #    authority: backend
  #    port: 8082
  - name: default
    route:
    - destination:
        host: demoapp
        subset: v10

8、配置vs-proxy

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: proxy
spec:
  hosts:
  - proxy
  http:
  - name: redirect
    match:
    - uri:
        prefix: "/backend"
    redirect:
      uri: /
      authority: backend
      port: 8082
  - name: default
    route:
    - destination:
        host: proxy

9、测试

[root@k8s-uat-manager ~]# kubectl exec -it sleep-69cfb4968f-2k674 -- sh
/ $ curl -I http://proxy/backend
HTTP/1.1 301 Moved Permanently
location: http://backend:8082/
date: Thu, 13 Jul 2023 15:02:47 GMT
server: envoy
transfer-encoding: chunked

/ $ while true;do curl http://proxy/canary;sleep 0.001;done

9、istio配置redirect-and-rewrite_istio

10、测试


/ $ while true;do curl http://proxy;sleep 0.001;done

9、istio配置redirect-and-rewrite_istio_02

标签:redirect,name,rewrite,app,istio,demoapp,backend,spec,metadata
From: https://blog.51cto.com/yht1990/6717102

相关文章

  • Istio与Mcp Server服务器讲解与搭建演示
    01Istio与外部注册中心Istio为何需要对接外部注册中心Istio对Kubernetes具有较强的依赖性:1.服务发现就是基于Kubernetes实现的,如果要使用Istio,首先需要迁移到Kubernetes上,并使用Kubernetes的服务注册发现机制。2.对于大量现存的微服务项目来说,这个前提条件并不成立。对......
  • 常见的istio定位手段
    常见的网格定位手段本文大都参考官方文档和自己定位问题的经验查看istio-proxy日志kubectllogspodname-xxx-cistio-proxy查看istio指标#curl-sS'localhost:15000/stats/prometheus'|grep<指标名>curl-sS'localhost:15000/stats/prometheus'|grepistio_reque......
  • Immediate window & redirect
    RedirecttotextfileSettheoptionRedirectallOutputWindowtexttotheImmediateWindow.WefinditinTools→Options→Debugging→General(fifthtolastitem).OpentheImmediateWindow:Ctrl+Alt+IorDebug→Windows→ImmediateWindow......
  • redirect-django-url-with-javascript
    https://www.appsloveworld.com/django/100/279/redirect-django-url-with-javascriptscore:3AcceptedanswerYoucanusethis:window.location.href="{%url'app:result'%}" score:1djangotemplatetagsworkinsidethedjangotem......
  • Nginx Rewrite
    摘要:nginx是重要的服务,在nginx中rewrite是很重要的一个功能,在企业中应用广泛。 目录一、Rewirte跳转场景二、Rewrite跳转实现三、Rewrite实现场景四、Rewrite正则表达式五、Rewrite语法格式六、location分类七、location优先级八、Rewrite和location九、案例......
  • Nginx 服务 Rewrite
    目录一、跳转场景二、正则表达式三、命令语法1.格式2.标记说明四、location分类1.分类2.正则匹配的常用表达式五、location优先级1.标记优先级2.实例说明六、必选三个规则1.第一个必选规则2.第二个必选规则3.第三个必选规则七、rewrite和location比较1.相同点2.不......
  • Nginx 6个例子理解proxy_pass和rewrite的用法
    Nginx6个例子理解proxy_pass和rewrite的用法一、rewrite描述rewrite可以重写path,也可以重写整个url(如果存在协议,默认返回302临时跳转,即使加了last和break也无效)。rewrite共有4种flag:last、break、redirect(302)、permanent(301)。当location中存在flag时,不会再执行之后的......
  • [网络安全] DVWA之 Open HTTP Redirect 攻击姿势及解题详析合集
    Lowlevel主页面如下:点击Quote1,发现url传递参数源代码审计源码如下:<?phpif(array_key_exists("redirect",$_GET)&&$_GET['redirect']!=""){header("location:".$_GET['redirect']);exit;}http......
  • 在 Istio 服务网格内连接外部 MySQL 数据库
    为了方便理解,以Istio官方提供的Bookinfo应用示例为例,利用ratings服务外部MySQL数据库。Bookinfo应用的架构图如下:其中,包含四个单独的微服务:productpage:调用details和reviews两个服务,用来生成页面。details:包含了书籍的信息。reviews:包含了书籍相关的评论。它还......
  • 深入理解 Istio 流量管理的超时时间设置
    环境准备部署httpbin服务:kubectlapply-fsamples/httpbin/httpbin.yaml部署sleep服务:kubectlapply-fsamples/sleep/sleep.yamlhttpbin服务作为接收请求的服务端,sleep服务作为发送请求的客户端。设置超时时间在sleep服务中向httpbin服务发出请求:export......