如何在Helmfile中为Contour部署添加HttpProxy自定义资源定义?
解决方案
针对你想在已有OSM+Contour的Helmfile配置中添加HttpProxy资源,且希望和OSM配置放在一起的需求,有两种简洁的实现方式:
方式一:直接在Helmfile的OSM Release中嵌入HttpProxy配置
修改你的Helmfile,在osm这个release下添加resources字段,直接写入HttpProxy的YAML内容,所有相关配置集中在同一个release块里:
repositories: - name: osm url: https://openservicemesh.github.io/osm releases: - name: osm namespace: my-namespace chart: osm/osm version: '1.2.4' values: - ./values/osm.yaml # 添加HttpProxy资源 resources: - | apiVersion: projectcontour.io/v1 kind: HTTPProxy metadata: name: my-proxy namespace: my-namespace spec: virtualhost: fqdn: localhost corsPolicy: allowCredentials: true allowOrigin: - "*" allowMethods: - GET - POST - OPTIONS allowHeaders: - "*" exposeHeaders: - "*" maxAge: "1s" routes: - conditions: - prefix: my-route services: - name: my-svc port: 8080 validation: caSecret: osm-system/osm-ca-bundle subjectName: default.my-namespace.cluster.local - ...
方式二:将HttpProxy配置单独存为文件,在Helmfile中引用
如果想保持Helmfile的简洁,可将HttpProxy配置单独保存为文件,再在OSM的release中通过resources加载:
- 创建
./values/contour-httpproxy.yaml:
apiVersion: projectcontour.io/v1 kind: HTTPProxy metadata: name: my-proxy namespace: my-namespace spec: virtualhost: fqdn: localhost corsPolicy: allowCredentials: true allowOrigin: - "*" allowMethods: - GET - POST - OPTIONS allowHeaders: - "*" exposeHeaders: - "*" maxAge: "1s" routes: - conditions: - prefix: my-route services: - name: my-svc port: 8080 validation: caSecret: osm-system/osm-ca-bundle subjectName: default.my-namespace.cluster.local
- 修改Helmfile:
repositories: - name: osm url: https://openservicemesh.github.io/osm releases: - name: osm namespace: my-namespace chart: osm/osm version: '1.2.4' values: - ./values/osm.yaml # 引用单独的HttpProxy配置文件 resources: - ./values/contour-httpproxy.yaml - ...
注意事项
- 由于你已经启用了OSM中的Contour组件,Contour会自动安装
projectcontour.io/v1对应的CRD,无需手动创建。 - 执行
helmfile apply时,Helmfile会先部署OSM/Contour,再创建HttpProxy资源,天然保证依赖顺序正确。
内容的提问来源于stack exchange,提问作者Tom
相关产品推荐
相关产品推荐

