在反向代理后面使用 Pact-Broker 并 URL 在 Kubernetes 和 Istio 中重写
Using Pact-Broker Behind Reverse Proxy And URL Rewrite in Kubernetes & Istio
我使用以下部署在本地 Kubernetes 集群中部署了 pact-broker docker image(最新版本)。
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-pact-broker
...
spec:
containers:
- name: my-pact-broker
image: pactfoundation/pact-broker
ports:
- containerPort: 9292
env:
- name: PACT_BROKER_ALLOW_PUBLIC_READ
value: "true"
- name: PACT_BROKER_BASIC_AUTH_USERNAME
value: "****"
- name: PACT_BROKER_BASIC_AUTH_PASSWORD
value: "****
- name: PACT_BROKER_PORT
value: "9292"
- name: PACT_BROKER_LOG_LEVEL
value: "DEBUG"
- name: PACT_BROKER_SQL_LOG_LEVEL
value: "DEBUG"
...
为 istio 入口控制器配置了一个虚拟服务
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-pact-broker
namespace: default
spec:
.....
http:
- match:
- uri:
prefix: /pactbroker/
- uri:
prefix: /pactbroker
rewrite:
uri: /
route:
- destination:
port:
number: 9292
host: my-pact-broker.default.svc.cluster.local
headers:
request:
add:
X-Forwarded-Scheme: "https"
X-Forwarded-Host: "my-domain.com"
X-Forwarded-Port: "80"
pact-broker api 工作正常。我已成功将协议发布到 https://my-domain.com/pactbroker/pacts/provider/test-provider/consumer/test-consumer/version/1.0.0
问题出在契约经纪人 UI 上。请求 https://my-domain.com/pactbroker 时,响应不完整。资源指向 root。
...
<body>
<link href='/stylesheets/index.css' rel='stylesheet'>
<link href='/stylesheets/material-menu.css' rel='stylesheet'>
<link href='/stylesheets/material-icon.css' rel='stylesheet'>
<link href='/stylesheets/jquery-confirm.min.css' rel='stylesheet'>
<script src='/javascripts/jquery.tablesorter.min.js' type='text/javascript'></script>
<script src='/javascripts/material-menu.js' type='text/javascript'></script>
<script src='/javascripts/index.js' type='text/javascript'></script>
<script src='/javascripts/clipboard.js' type='text/javascript'></script>
<script src='/javascripts/jquery-confirm.min.js' type='text/javascript'></script>
<div class='container'>
<nav class='navbase-default' id='navigation' role='navigation'>
<div class='container-fluid'>
<div class='navbar-header'></div>
<ul class='navbar-right' id='top-left-menu'>
<li>
<a href='?tags=true'>
Show latest tags
</a>
<a href='/hal-browser/browser.html'>
API Browser
</a>
</li>
</ul>
</div>
</nav>
....
HAL-Browser也有类似的问题:
URI 模板中的引用未显示 uri 前缀“pactbroker”
我需要做什么才能使其正常工作。
我在 pact-broker 项目的 Changelog 中找到了缺失的信息。
添加环境变量PACT_BROKER_BASE_URL解决了问题
- name: "PACT_BROKER_BASE_URL"
value: "https://my-domain.com/pactbroker"
我使用以下部署在本地 Kubernetes 集群中部署了 pact-broker docker image(最新版本)。
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-pact-broker
...
spec:
containers:
- name: my-pact-broker
image: pactfoundation/pact-broker
ports:
- containerPort: 9292
env:
- name: PACT_BROKER_ALLOW_PUBLIC_READ
value: "true"
- name: PACT_BROKER_BASIC_AUTH_USERNAME
value: "****"
- name: PACT_BROKER_BASIC_AUTH_PASSWORD
value: "****
- name: PACT_BROKER_PORT
value: "9292"
- name: PACT_BROKER_LOG_LEVEL
value: "DEBUG"
- name: PACT_BROKER_SQL_LOG_LEVEL
value: "DEBUG"
...
为 istio 入口控制器配置了一个虚拟服务
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-pact-broker
namespace: default
spec:
.....
http:
- match:
- uri:
prefix: /pactbroker/
- uri:
prefix: /pactbroker
rewrite:
uri: /
route:
- destination:
port:
number: 9292
host: my-pact-broker.default.svc.cluster.local
headers:
request:
add:
X-Forwarded-Scheme: "https"
X-Forwarded-Host: "my-domain.com"
X-Forwarded-Port: "80"
pact-broker api 工作正常。我已成功将协议发布到 https://my-domain.com/pactbroker/pacts/provider/test-provider/consumer/test-consumer/version/1.0.0
问题出在契约经纪人 UI 上。请求 https://my-domain.com/pactbroker 时,响应不完整。资源指向 root。
...
<body>
<link href='/stylesheets/index.css' rel='stylesheet'>
<link href='/stylesheets/material-menu.css' rel='stylesheet'>
<link href='/stylesheets/material-icon.css' rel='stylesheet'>
<link href='/stylesheets/jquery-confirm.min.css' rel='stylesheet'>
<script src='/javascripts/jquery.tablesorter.min.js' type='text/javascript'></script>
<script src='/javascripts/material-menu.js' type='text/javascript'></script>
<script src='/javascripts/index.js' type='text/javascript'></script>
<script src='/javascripts/clipboard.js' type='text/javascript'></script>
<script src='/javascripts/jquery-confirm.min.js' type='text/javascript'></script>
<div class='container'>
<nav class='navbase-default' id='navigation' role='navigation'>
<div class='container-fluid'>
<div class='navbar-header'></div>
<ul class='navbar-right' id='top-left-menu'>
<li>
<a href='?tags=true'>
Show latest tags
</a>
<a href='/hal-browser/browser.html'>
API Browser
</a>
</li>
</ul>
</div>
</nav>
....
HAL-Browser也有类似的问题:
URI 模板中的引用未显示 uri 前缀“pactbroker”
我需要做什么才能使其正常工作。
我在 pact-broker 项目的 Changelog 中找到了缺失的信息。
添加环境变量PACT_BROKER_BASE_URL解决了问题
- name: "PACT_BROKER_BASE_URL"
value: "https://my-domain.com/pactbroker"