小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

istio:在vs中實(shí)現(xiàn)ab測(cè)試和路徑切割

 路人甲Java 2022-01-20

  • 此篇內(nèi)容

主要目的是總結(jié)vs中的match的有關(guān)規(guī)則和在istio中如何實(shí)現(xiàn)路徑切割(當(dāng)下版本1.8.2)

實(shí)驗(yàn)demo

main.go

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	//1.創(chuàng)建路由
	r := gin.Default()
	//2.綁定路由規(guī)則,執(zhí)行的函數(shù)
	r.GET("/zisefeizhu", func(context *gin.Context) {
		context.String(http.StatusOK, "Hello Zisefeizhu V1!")
// v1版本為context.String(http.StatusOK, "Hello Zisefeizhu V1!")
// v2版本為context.String(http.StatusOK, "Hello Zisefeizhu V2!")
	})
	//3.監(jiān)聽端口,默認(rèn)8080
	r.Run(":8080")
}

Dockerfile

FROM registry.cn-shenzhen.aliyuncs.com/realibox-baseimage/golang:1.15.2-alpine as builder

WORKDIR /app

RUN go env -w GO111MODULE=on     && go env -w GOPROXY=https://,direct

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build -ldflags "-s -w"  -o server main.go


FROM alpine:latest

WORKDIR /app
COPY --from=builder /app/server /app
CMD ["./server"]

deployment.yaml

  • v1 v2版本的不同之處在于version
apiVersion: apps/v1
kind: Deployment
metadata:
  name: goproject
  namespace: zisefeizhu
  labels:
    app: goproject
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: goproject
      version: v1
  template:
    metadata:
      labels:
        app: goproject
        version: v1
    spec:
      containers:
      - image: registry.cn-shenzhen.aliyuncs.com/zisefeizhu/goproject:goproject-zisefeizhu-5425
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 30
          successThreshold: 1
          tcpSocket:
            port: 8080
          timeoutSeconds: 2
        name: goproject
        ports:
        - containerPort: 8080
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          initialDelaySeconds: 10
          periodSeconds: 30
          successThreshold: 1
          tcpSocket:
            port: 8080
      imagePullSecrets:
      - name: business-secret

svc.yaml

  • svc中沒有version標(biāo)簽
apiVersion: v1
kind: Service
metadata:
  labels:
    app: goproject
  name: goproject
  namespace: zisefeizhu
spec:
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: goproject
  type: ClusterIP

istio配置清單

gateway.yaml

  • istio-system 名稱空間下
  • 使用cert-manager 自動(dòng)生成、續(xù)簽證書
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: www-zisefeizhu-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - hosts:
    - www.zisefeizhu.com
    port:
      name: http
      number: 80
      protocol: HTTP
    tls:
      httpsRedirect: true  # 301跳轉(zhuǎn)https
  - hosts:
    - www.zisefeizhu.com
    port:
      name: https
      number: 443
      protocol: HTTPS
    tls:
      credentialName: www-zisefeizhu-com  # cert-manager生成的證書的certificate namespace
      mode: SIMPLE

dr.yaml

  • 定義子集
kind: DestinationRule
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: goproject
  namespace: zisefeizhu
spec:
  host: goproject
  subsets:
    - labels:
        version: v12.3
      name: v1
    - labels:
        version: v12.4
      name: v2

vr.yaml

  • 重點(diǎn)來了
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: goproject
  namespace: zisefeizhu
spec:
  hosts:
    - www.zisefeizhu.com
  gateways:
    - istio-system/www-zisefeizhu-gateway #跨namespace 
  http:
    - match:                          #ab test 條件匹配塊  這里設(shè)置的測(cè)試條件為user-agent字段,設(shè)置了兩個(gè)客戶地址
        - headers:                    #目前istio對(duì)于多條件的匹配需要寫多個(gè)headers
            user-agent:
              exact: Mozilla/5.0   
          uri:
            prefix: /api/            #訪問www.zisefeizhu.com/api/zisefeizhu 跳轉(zhuǎn)到www.zisefeizhu.com/zisefeizhu 
        - headers:                   #istio 沒有類似kong的 ``konghq.com/strip-path`` 注解
            user-agent:
              exact: Mozilla/6.0
          uri:
            prefix: /api/
      rewrite:                       #此處需要注意:https://github.com/istio/istio/issues/8076
        uri: /
      route:
        - destination:
            host: goproject
            subset: v2              #匹配到進(jìn)入v2版本
    - match:                        #此匹配塊為``切割``路由路徑匹配塊掩飾
        - uri:
            prefix: /api/
      rewrite:
        uri: /
      route:
        - destination:
            host: goproject
            subset: v1
    - route:                        #默認(rèn)路由
        - destination:
            host: goproject
            subset: v1

驗(yàn)證

  • 工具為:postman
  • 訪問地址http:www.zisefeizhu.com/api/zisefeizhu
    user-agent: Mozilla/5.0

user-agent: Mozilla/6.0

user-agent: Mozilla/7.0

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多