{"id":664,"date":"2021-02-22T10:22:09","date_gmt":"2021-02-22T02:22:09","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=664"},"modified":"2022-05-17T09:29:50","modified_gmt":"2022-05-17T01:29:50","slug":"istio","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=664","title":{"rendered":"\u57fa\u4e8eistio\u7684\u7070\u5ea6\u53d1\u5e03\u5b9e\u9a8c"},"content":{"rendered":"<h1 id=\"id-\u7070\u5ea6\u53d1\u5e03\u5165\u95e8\u57f9\u8bad\u4e0edemo\u6f14\u793a-\u80cc\u666f\">\u80cc\u666f<\/h1>\n<p>\u7070\u5ea6\u53d1\u5e03\u53c8\u53ebA\/B\u6d4b\u8bd5\uff0c\u5373\u8ba9\u4e00\u90e8\u5206\u7528\u6237\u7ee7\u7eed\u7528\u4ea7\u54c1\u7279\u6027A\uff0c\u4e00\u90e8\u5206\u7528\u6237\u5f00\u59cb\u7528\u4ea7\u54c1\u7279\u6027B\uff0c\u5982\u679c\u7528\u6237\u5bf9B\u6ca1\u6709\u4ec0\u4e48\u53cd\u5bf9\u610f\u89c1\uff0c\u90a3\u4e48\u9010\u6b65\u6269\u5927\u8303\u56f4\uff0c\u628a\u6240\u6709\u7528\u6237\u90fd\u8fc1\u79fb\u5230B\u4e0a\u9762\u6765\u3002<br \/>\u56e0\u4e3a\u6700\u8fd1\u521a\u597d\u6709\u7070\u5ea6\u53d1\u5e03\u7684\u9700\u6c42\uff0c\u6211\u53c8\u5b66\u4e86\u4e00\u904distio\uff0c\u8bb0\u5f55\u4e86\u672c\u6b21\u7070\u5ea6\u53d1\u5e03\u7684\u5b9e\u65bd\u8fc7\u7a0b\uff08\u53ea\u5305\u62ec\u5e94\u7528\uff0c\u4e0d\u5305\u62ec\u6570\u636e\u5e93\u5347\u7ea7\uff09<\/p>\n<hr \/>\n<h1>\u5b9e\u9a8c\u8fc7\u7a0b<\/h1>\n<ol>\n<li>\u5148\u786e\u5b9a\u76ee\u524d\u7684\u5e94\u7528\u7248\u672c\u4e3aV1<\/li>\n<li>\u901a\u8fc7helm\u5305\u90e8\u7f72\u5e94\u7528\u7248\u672c\u4e3aV2\u7684pod\u5230K8S\u96c6\u7fa4\u4e2d<\/li>\n<li>\u786e\u5b9aV2\u7248\u672c\u7070\u5ea6\u7684\u7528\u6237\uff0c\u65b9\u6cd5\u5305\u62ecIP,\u6216\u8005\u7279\u5b9a\u7528\u6237<\/li>\n<li>\u901a\u8fc7istio\u7684virtualservice\u529f\u80fd\u628a\u7279\u5b9a\u7528\u6237\u7684\u6d41\u91cf\u6307\u5411V2\u7248\u672c<\/li>\n<li>\u68c0\u67e5\u7279\u5b9a\u7528\u6237\u4f7f\u7528\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u662f\u5426\u51fa\u73b0\u95ee\u9898<\/li>\n<li>\u82e5\u65e0\u95ee\u9898\uff0c\u901a\u8fc7istio\u5c06\u6240\u6709\u7528\u6237\u7684\u6d41\u91cf\u90fd\u6307\u5411V2\u7248\u672c<\/li>\n<li>\u82e5\u6240\u6709\u7528\u6237\u90fd\u4f7f\u7528V2\u65e0\u95ee\u9898\uff0c\u5220\u9664\u6389V1\u7248\u672c\u7684pod<\/li>\n<\/ol>\n<h1 id=\"id-\u7070\u5ea6\u53d1\u5e03\u5165\u95e8\u57f9\u8bad\u4e0edemo\u6f14\u793a-\u793a\u4f8b\u4ecb\u7ecd\">\u793a\u4f8b\u4ecb\u7ecd<\/h1>\n<p>\u524d\u7aef\u5e94\u7528frontend\uff0c\u540e\u7aef\u5e94\u7528mqtt-server\uff0c\u540e\u7aef\u5e94\u7528mqtt-server \u901a\u8fc7mqtt\u534f\u8bae\u4e0e\u8bbe\u5907\u76f8\u8fde\u63a5\u3002<br \/>\u524d\u7aef\u90e8\u7f723\u4e2a\u7248\u672c\uff0c\u5206\u522b\u662fV1\uff0cV2\uff0cV3\uff0c\u540e\u7aef\u540c\u6837\u90e8\u7f723\u4e2a\u7248\u672c\uff0c\u4e5f\u662fV1\uff0cV2\uff0cV3\u30023\u4e2a\u524d\u7aef\u7248\u672c\uff0c\u6309\u94ae\u6587\u5b57\u4e0d\u4e00\u6837\u30023\u4e2a\u540e\u7aef\u7248\u672c\uff0c\u8fde\u63a5\u7684mqtt\u8bbe\u5907\u4e0d\u4e00\u6837<\/p>\n<table class=\"relative-table confluenceTable\" style=\"width: 679px; height: 358px;\"><colgroup> <col style=\"width: 5.22979%;\" \/> <col style=\"width: 13.7876%;\" \/> <col style=\"width: 80.9826%;\" \/><\/colgroup>\n<tbody>\n<tr>\n<th class=\"confluenceTh\" colspan=\"1\">\u7248\u672c<\/th>\n<th class=\"confluenceTh\">\u524d\u7aef\u9875\u9762<\/th>\n<th class=\"confluenceTh\">\u540e\u7aef\u8fd4\u56de\u53c2\u6570<\/th>\n<\/tr>\n<tr>\n<td class=\"confluenceTd\" colspan=\"1\">V1<\/td>\n<td class=\"confluenceTd\">\u663e\u793aV11\u6309\u94ae<\/td>\n<td class=\"confluenceTd\">\n<pre>{\"message\":[\"wsytest010\",\"wsytest002\",\n\"wsytest003\",\"wsytest007\",\"wsytest006\",\n\"wsytest001\",\"wsytest005\",\"wsytest009\",\n\"wsytest008\",\"wsytest004\"]}<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"confluenceTd\" colspan=\"1\">V2<\/td>\n<td class=\"confluenceTd\">\u663e\u793aV22\u6309\u94ae<\/td>\n<td class=\"confluenceTd\">\n<pre>{\"message\":[\"wsytest019\",\"wsytest020\",\n\"wsytest017\",\"wsytest012\",\"wsytest011\",\n\"wsytest014\",\"wsytest018\",\"wsytest015\",\n\"wsytest013\",\"wsytest016\"]}<\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"confluenceTd\" colspan=\"1\">V3<\/td>\n<td class=\"confluenceTd\">\u663e\u793aV33\u6309\u94ae<\/td>\n<td class=\"confluenceTd\">\n<pre>{\"message\":[\"wsytest024\",\"wsytest028\",\n\"wsytest022\",\"wsytest026\",\"wsytest027\",\n\"wsytest021\",\"wsytest025\",\"wsytest030\",\n\"wsytest023\",\"wsytest029\"]}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-667 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/v1-Image-12.png\" alt=\"\" width=\"723\" height=\"459\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-669 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-13-4.png\" alt=\"\" width=\"672\" height=\"388\" \/><br \/>\u6839\u636e\u9700\u6c42\uff0c\u7248\u672c\u4e0d\u80fd\u4e32\uff0c\u6bd4\u5982\u524d\u7aefV1-&gt;\u540e\u7aefV1\uff0c\u4e0d\u5141\u8bb8\u51fa\u73b0\u524d\u7aefV1\u2192\u540e\u7aefV2\u8fd9\u6837\u7684\u60c5\u51b5\u53d1\u751f<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-670 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-3-3.png\" alt=\"\" width=\"914\" height=\"653\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-671 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-5-1.png\" alt=\"\" width=\"853\" height=\"655\" \/><br \/>\u8fd9\u91cc\u6211\u4eec\u5728\u9009\u62e9\u5206\u914d\u6d41\u91cf\u65b9\u5f0f\u65f6\uff0c\u4e0d\u80fd\u4f7f\u7528\u6743\u91cd\u7684\u65b9\u5f0f\u8fdb\u884c\u5206\u914d\uff0c\u53ea\u80fd\u9009\u62e9\u6307\u5b9a\u7528\u6237\u6216\u8005\u6307\u5b9aIP\uff0c\u5982\u679c\u9009\u62e9\u6743\u91cd\u7684\u65b9\u5f0f\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u5982\u4e0b\u7684\u95ee\u9898\uff1a<br \/><span style=\"color: #ff0000;\"><strong>\u524d\u7aef\u4f1a\u8bbf\u95ee\u591a\u4e2ajs,css\u7b49\u6587\u4ef6\uff0c\u5982\u679c\u4f7f\u7528\u6743\u91cd\u7684\u65b9\u5f0f\uff0c\u4f1a\u51fa\u73b0\u4e00\u90e8\u5206js\u6765\u6e90\u4e8ev1\u7248\u672c\uff0c\u4e00\u90e8\u5206css\u6765\u6e90\u4e8ev2\u7248\u672c\u3002<\/strong><\/span><br \/><span style=\"color: #ff0000;\"><strong>\u540e\u7aef\u4e5f\u540c\u7406\uff0c\u5982\u679c\u4e00\u4e2a\u9875\u9762\u6253\u5f00\u65f6\uff0c\u89e6\u53d1\u591a\u4e2a\u540e\u7aef\u8bf7\u6c42\uff0c\u90e8\u5206\u6765\u6e90\u4e8eV2,\u90e8\u5206\u6765\u6e90\u4e8eV1,\u80af\u5b9a\u4f1a\u5bfc\u81f4\u524d\u7aef\u663e\u793a\u51fa\u73b0\u95ee\u9898\u3002<\/strong><\/span><br \/><span style=\"color: #ff0000;\"><strong>\u6240\u4ee5\u53ea\u6709\u628a\u524d\u540e\u7aef\u901a\u8fc7\u67d0\u79cd\u65b9\u5f0f\u4e00\u4e00\u5bf9\u5e94\uff0c\u624d\u80fd\u6b63\u5e38\u4f7f\u7528<\/strong><\/span><br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-672 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-6-1-1024x532.png\" alt=\"\" width=\"900\" height=\"468\" \/><\/p>\n<hr \/>\n<h1 id=\"id-\u7070\u5ea6\u53d1\u5e03\u5165\u95e8\u57f9\u8bad\u4e0edemo\u6f14\u793a-\u5b9e\u65bd\u8fc7\u7a0b\">\u4ee3\u7801\u5b9e\u73b0\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h1>\n<p>1.\u90e8\u7f72\u524d\u7aef\u76843\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u6240\u6709\u7684pod\u90fd\u52a0\u4e0a<code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\"> labels:[app:frontend,version:#{\u5bf9\u5e94\u7248\u672c}]<\/code><\/p>\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: frontend\n  labels:\n    app: frontend\n    version: v1\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: frontend\n      version: v1\n  template:\n    metadata:\n      labels:\n        app: frontend\n        version: v1\n    spec:\n      containers:\n      - name: frontend\n        image: \u524d\u7aef\u955c\u50cf:v1\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]    # \u6309\u7167istio\u7684\u8bf4\u660e\uff0c\u6700\u597d\u628a\u8fd9\u4e2apod\u5b89\u5168\u7b56\u7565\u52a0\u4e0a\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 80\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: frontend-v2\n  labels:\n    app: frontend\n    version: v2\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: frontend\n      version: v2\n  template:\n    metadata:\n      labels:\n        app: frontend\n        version: v2\n    spec:\n      containers:\n      - name: frontend\n        image: \u524d\u7aef\u955c\u50cf:v2\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 80\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: frontend-v3\n  labels:\n    app: frontend\n    version: v3\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: frontend\n      version: v3\n  template:\n    metadata:\n      labels:\n        app: frontend\n        version: v3\n    spec:\n      containers:\n      - name: frontend\n        image: \u524d\u7aef\u955c\u50cf:v3\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 80\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: frontend\nspec:\n  selector:\n    app: frontend\n  type: ClusterIP   #\u8fd9\u4e2a\u4e0d\u7528NodePort\uff0c\u56e0\u4e3a\u6d41\u91cf\u5982\u679c\u662f\u4eceNodePort\u8fdb\u6765\u7684\uff0c\u5c31\u63a7\u4e0d\u4f4f\u7684\n  ports:\n    - port: 80\n      targetPort: 80\n      name: http-web<\/code><\/pre>\n<p>2.\u90e8\u7f72\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f,\u4e0e\u524d\u7aef\u5e94\u7528\u7c7b\u4f3c<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeHeader panelHeader pdl hide-border-bottom\">\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: mqtt-server-v1\n  labels:\n    app: mqtt-server\n    version: v1\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mqtt-server\n      version: v1\n  template:\n    metadata:\n      labels:\n        app: mqtt-server\n        version: v1\n    spec:\n      serviceAccountName: mqtt-server\n      containers:\n      - name: mqtt-server\n        image: \u540e\u7aef\u955c\u50cf:latest\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]    # \u6309\u7167istio\u7684\u8bf4\u660e\uff0c\u6700\u597d\u628a\u8fd9\u4e2apod\u5b89\u5168\u7b56\u7565\u52a0\u4e0a\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 8000\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: mqtt-server-v2\n  labels:\n    app: mqtt-server\n    version: v2\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mqtt-server\n      version: v2\n  template:\n    metadata:\n      labels:\n        app: mqtt-server\n        version: v2\n    spec:\n      serviceAccountName: mqtt-server\n      containers:\n      - name: mqtt-server\n        image: \u540e\u7aef\u955c\u50cf:latest\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 8000\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: mqtt-server-v3\n  labels:\n    app: mqtt-server\n    version: v3\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mqtt-server\n      version: v3\n  template:\n    metadata:\n      labels:\n        app: mqtt-server\n        version: v3\n    spec:\n      serviceAccountName: mqtt-server\n      containers:\n      - name: mqtt-server\n        image: \u540e\u7aef\u955c\u50cf:latest\n        securityContext:\n          capabilities:\n            add: [\"NET_ADMIN\", \"NET_RAW\"]\n        imagePullPolicy: Always\n        ports:\n        - containerPort: 8000\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: mqtt-server\nspec:\n  selector:\n    app: mqtt-server\n  type: NodePort   #\u8fd9\u4e2a\u4e0d\u7528NodePort\uff0c\u56e0\u4e3a\u6d41\u91cf\u5982\u679c\u662f\u4eceNodePort\u8fdb\u6765\u7684\uff0c\u5c31\u63a7\u4e0d\u4f4f\u7684\n  ports:\n    - port: 8000\n      targetPort: 8000\n      name: http-web<\/code><\/pre>\n<p>3.\u533a\u5206\u5916\u90e8\u6d41\u91cf\u548c\u5185\u90e8\u6d41\u91cf\u3002\u6211\u4eec\u5c06\u6d4f\u89c8\u5668\u5230\u524d\u7aef\u7684\u79f0\u4e3a\u5916\u90e8\u6d41\u91cf\uff0cK8S\u91cc\u7684\u4f8b\u5982\u524d\u7aef\u5230\u540e\u7aef\u7684\u79f0\u4e3a\u5185\u90e8\u6d41\u91cf<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-673 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-24.png\" alt=\"\" width=\"640\" height=\"241\" \/><br \/>4.\u5916\u90e8\u6d41\u91cf\u51fa\u53bb\uff0c\u9700\u8981\u88abistio\u7684ingress gateway\u7ba1\u63a7\u8d77\u6765\uff0c\u6240\u4ee5\u9700\u8981\u914d\u7f6e\u4e00\u4e2agateway<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeHeader panelHeader pdl hide-border-bottom\">\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">apiVersion: networking.istio.io\/v1alpha3\nkind: Gateway\nmetadata:\n  name: bookinfo\nspec:\n  selector:\n    istio: ingressgateway # use istio default controller\n  servers:\n  - port:\n      number: 80\n      name: http\n      protocol: HTTP\n    hosts:\n    - \"*\"<\/code><\/pre>\n<p>5.\u914d\u7f6e\u540e\u7aef\u7684virtualservice\u548cdestination\uff0c\u786e\u4fdd\u540e\u7aef\u7a0b\u5e8f\u80fd\u4e0e\u524d\u7aef\u7a0b\u5e8f\u4ea7\u751f\u4e00\u5bf9\u4e00\u7684\u5173\u7cfb\uff0c\u5728\u65e0\u5bf9\u5e94\u5173\u7cfb\u65f6\uff0c\u9ed8\u8ba4\u4f7f\u7528V1\u7248\u672c<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeHeader panelHeader pdl hide-border-bottom\">\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">---\napiVersion: networking.istio.io\/v1alpha3\nkind: VirtualService\nmetadata:\n  name: mqtt-server-internal\nspec:\n  hosts:\n  - \"mqtt-server\"     #\u6b64\u5904\u662f\u5173\u952e\uff0c\u628a\u5339\u914d\u5230\u8be5url\u7684\u6d41\u91cf\uff0c\u5168\u90e8\u8d70\u5230\u8fd9\u4e2a\u7279\u5b9a\u7684virtualservice\u91cc\n  http:\n  - match:\n    - sourceLabels:\n        version: v1\n    route:\n    - destination:\n        host: mqtt-server\n        subset: v1             # \u5c06\u5339\u914d\u5230\u7684\u6d41\u91cf\uff0c\u8f6c\u5411subset\u7684v1\u7248\u672c\uff0c\u8fd9\u4e2asubset: v1\u5728destination.yaml\u91cc\u5b9a\u4e49\n      headers:\n        response:\n          add:\n            user: v1\n  - match:\n    - sourceLabels:\n        version: v2\n    route:\n    - destination:\n        host: mqtt-server\n        subset: v2\n      headers:\n        response:\n          add:\n            user: v2\n  - match:\n    - sourceLabels:\n        version: v3\n    route:\n    - destination:\n        host: mqtt-server\n        subset: v3\n      headers:\n        response:\n          add:\n            user: v3\n  - route:\n    - destination:\n        host: mqtt-server\n        subset: v1\n      headers:\n        response:\n          add:\n            user: v1\n---\napiVersion: networking.istio.io\/v1alpha3\nkind: DestinationRule\nmetadata:\n  name: mqtt-server\nspec:\n  host: mqtt-server.default.svc.cluster.local\n  subsets:\n  - name: v1\n    labels:\n      version: v1    # \u6839\u636epod\u7684 version: v1 \u7684label\u6765\u8fdb\u884c\u5339\u914d\n  - name: v2\n    labels:\n      version: v2\n  - name: v3\n    labels:\n      version: v3<\/code><\/pre>\n<p>6.\u914d\u7f6e\u524d\u7aef\u7684virtualservice\u548cdestination\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbe\u7f6e\u6765\u6e90\u4e8e192.168.0.58\u8fd9\u4e2aIP\u7684\u8d70V2\u7248\u672c\uff0c\u5176\u4f59IP\u8d70V1\u7248\u672c<\/p>\n<div class=\"code panel pdl conf-macro output-block\" data-hasbody=\"true\" data-macro-name=\"code\">\n<div class=\"codeHeader panelHeader pdl hide-border-bottom\">\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">apiVersion: networking.istio.io\/v1alpha3\nkind: VirtualService\nmetadata:\n  name: frontend-server\nspec:\n  hosts:\n  - \"\u5916\u7f51\u57df\u540d\"     #\u6b64\u5904\u662f\u5173\u952e\uff0c\u628a\u5339\u914d\u5230\u8be5url\u7684\u6d41\u91cf\uff0c\u5168\u90e8\u8d70\u5230\u8fd9\u4e2a\u7279\u5b9a\u7684virtualservice\u91cc\n  gateways:\n  - bookinfo-gateway              #\u6b64\u5904\u5fc5\u987b\u5bf9\u5e94\u4e0agateway\u7684\u540d\u5b57\n  http:\n  - match:\n    - headers:\n      X-Forwarded-For:\n          exact: \"192.168.0.58\"            #\u6b64\u5904\u8868\u793a\u5339\u914dheader\u91cc\u6709{\"user\":\"v1\"}\n    route:\n    - destination:\n        host: mqtt-server\n        subset: v2             # \u5c06\u5339\u914d\u5230\u7684\u6d41\u91cf\uff0c\u8f6c\u5411subset\u7684v1\u7248\u672c\uff0c\u8fd9\u4e2asubset: v1\u5728destination.yaml\u91cc\u5b9a\u4e49\n      headers:\n        response:\n          add:\n            user: v2\n  - route:\n    - destination:\n        host: frontend\n        subset: v1             # \u5c06\u5339\u914d\u5230\u7684\u6d41\u91cf\uff0c\u8f6c\u5411subset\u7684v1\u7248\u672c\uff0c\u8fd9\u4e2asubset: v1\u5728destination.yaml\u91cc\u5b9a\u4e49\n      headers:\n        response:\n          add:\n            user: v1\n---\napiVersion: networking.istio.io\/v1alpha3\nkind: DestinationRule\nmetadata:\n  name: frontend\nspec:\n  host: frontend\n  subsets:\n  - name: v1\n    labels:\n      version: v1    # \u6839\u636epod\u7684 version: v1 \u7684label\u6765\u8fdb\u884c\u5339\u914d\n  - name: v2\n    labels:\n      version: v2\n  - name: v3\n    labels:\n      version: v3<\/code><\/pre>\n<p>7.\u56e0\u4e3a\u6211\u4eec\u7684\u6d4f\u89c8\u5668\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u4f1a\u7ecf\u8fc7istio,\u6240\u4ee5\u524d\u7aef\u6536\u5230\u7684IP\u5e76\u4e0d\u662f\u771f\u662f\u7684IP\uff0c\u6211\u4eec\u9700\u8981\u4fee\u6539istio\u7684ingress\u6587\u4ef6\uff0c\u628aspec.externalTrafficPolicy\u8bbe\u7f6e\u6210Local,\u5982\u4e0b\u56fe\u6240\u793a<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-674 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-25.png\" alt=\"\" width=\"857\" height=\"623\" \/><br \/>8.\u6700\u7ec8\u60c5\u51b5<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-675 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-26-1024x231.png\" alt=\"\" width=\"900\" height=\"203\" \/><\/p>\n<hr \/>\n<h1 id=\"id-\u7070\u5ea6\u53d1\u5e03\u5165\u95e8\u57f9\u8bad\u4e0edemo\u6f14\u793a-\u5b9e\u9a8c\u6548\u679c\u56fe\">\u5b9e\u9a8c\u6548\u679c\u56fe<\/h1>\n<p>1.\u5f53\u672c\u673aIP\u5730\u5740\u4e0d\u7b26\u5408\u6761\u4ef6\u65f6\uff0c\u524d\u7aef\u548c\u540e\u7aef\u90fd\u662fV1\u7248\u672c\u7684\u7ed3\u679c,\u7b2c\u4e00\u5f20\u56fe\u662f\u5b9e\u9645\u6548\u679c\uff0c\u7b2c\u4e8c\u5f20\u56fe\u662fkiali\u663e\u793a\u7684\u6d41\u91cf\u56fe<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-676 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-15-2.png\" alt=\"\" width=\"673\" height=\"401\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-677 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-18-2-1024x529.png\" alt=\"\" width=\"900\" height=\"465\" \/><br \/>2.\u5f53\u672c\u673aIP\u7b26\u5408\u6761\u4ef6\u65f6\uff0c\u524d\u7aef\u548c\u540e\u7aef\u90fd\u662fV2\u7248\u672c\u7684\u7ed3\u679c,\u5de6\u56fe\u662f\u5b9e\u9645\u6548\u679c\uff0c\u53f3\u56fe\u662fkiali\u663e\u793a\u7684\u6d41\u91cf\u56fe<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-678 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-20-1.png\" alt=\"\" width=\"718\" height=\"431\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-679 size-full\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-19-1.png\" alt=\"\" width=\"914\" height=\"639\" \/><br \/>3.\u5f53\u540c\u65f6\u6709\u6ee1\u8db3IP\u548c\u4e0d\u6ee1\u8db3IP\u6761\u4ef6\u7684\u673a\u5668\u8bbf\u95ee\u65f6\uff0c\u6d41\u91cf\u56fe\u6548\u679c\u5982\u4e0b<br \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-680 size-large\" src=\"https:\/\/yinyubo-1257235934.cos.ap-nanjing.myqcloud.com\/content\/Image-21-1-1024x695.png\" alt=\"\" width=\"900\" height=\"611\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u7070\u5ea6\u53d1\u5e03\u53c8\u53ebA\/B\u6d4b\u8bd5\uff0c\u5373\u8ba9\u4e00\u90e8\u5206\u7528\u6237\u7ee7\u7eed\u7528\u4ea7\u54c1\u7279\u6027A\uff0c\u4e00\u90e8\u5206\u7528\u6237\u5f00\u59cb\u7528\u4ea7\u54c1\u7279\u6027B\uff0c\u5982\u679c\u7528\u6237\u5bf9B\u6ca1\u6709\u4ec0\u4e48 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7],"tags":[11],"class_list":["post-664","post","type-post","status-publish","format-standard","hentry","category-k8s","category-7","tag-istio"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=664"}],"version-history":[{"count":4,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions"}],"predecessor-version":[{"id":858,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/664\/revisions\/858"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}