在 Kubernetes 和 Istio 中使用反向代理和 URL 重写背后的 Pact-Broker



我在本地Kubernetes集群中部署了pact-broker docker镜像(最新版本(,并进行了以下部署。

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"

协定经纪人api运行良好。我成功地将协议发布到https://my-domain.com/pactbroker/pacts/provider/test-provider/consumer/test-consumer/version/1.0.0

问题出在合约经纪人UI上。请求时https://my-domain.com/pactbroker响应不完整。资源指向根。

...
<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浏览器也有类似的问题:

URI模板中的引用没有显示URI前缀";pactbroker;

  • https://my-domain.org/pacts/provider//consumer//version/

我必须做些什么才能使它正确工作

我在协定代理项目的变更日志中发现了丢失的信息。

添加环境变量PACT_BROKER_BASE_URL修复了问题

- name: "PACT_BROKER_BASE_URL"
value: "https://my-domain.com/pactbroker"

相关内容

  • 没有找到相关文章

最新更新