Using the helm_release provider, I want to attach a sidecar container to a helm release. Specifically, I want to attach the sqlproxy container to the keto release. Below is my initial attempt but it does not pass values for sqlproxy config. How to add a container with values to a helm release?
使用HELM_RELEASE提供程序,我希望将SideCar容器附加到HELM发行版。具体地说,我希望将SQLProxy容器附加到keto发行版。下面是我的初始尝试,但它没有传递SQLProxy配置的值。如何将带有值的容器添加到Helm版本中?
locals {
db_username = "postgres"
sql_port = "5432"
}
resource "helm_release" "keto" {
name = "ory"
repository = "https://k8s.ory.sh/helm/charts"
chart = "keto"
values = [
<<EOT
serviceAccount:
create: false
name: ${module.service_account.value.id}
job:
serviceAccount:
create: false
name: ${module.service_account.value.id}
keto:
config:
dsn: postgres://${local.db_username}:${random_password.password.result}@pg-sqlproxy-gcloud-sqlproxy:${local.sql_port}/db
deploy:
extraContainers:
name: gcloud-sqlproxy
image: # what to place here? how to add extra values here?
EOT
]
}
The documentation for keto showed it offers a deployment:extraContainers
field where I can set the name and the image for a container; however, unsure how to pass the additional values needed for sqlproxy
keto的文档显示它提供了一个deployment:extraContainers字段,我可以在其中设置容器的名称和映像;但是,不确定如何传递sqlproxy所需的其他值
更多回答
优秀答案推荐
How any particular settings are used are fairly chart-specific, and there's not a generic recipe for things like adding sidecar containers.
如何使用任何特定的设置都是特定于图表的,并且没有添加侧车容器之类的通用方法。
In this particular chart, the extraContainers
setting is used as
在这个特定的图表中,ExtraContainers设置用作
containers:
- name: {{ .Chart.Name }}
# ... about another 100 lines of settings ...
{{- if $extraContainers }}
{{- tpl $extraContainers . | nindent 8 }}
{{- end }}
That is, if extraContainers
is set, it must be a string; it is run through the Helm tpl
extension function to render Go text/template markup using the top-level Helm object; and the result is indented to the correct level in the Deployment spec.
也就是说,如果设置了ExtraContainers,则它必须是一个字符串;它通过Helm TPL扩展函数运行,以使用顶级Helm对象呈现GO文本/模板标记;并且结果缩进到部署规范中的正确级别。
In the YAML you show, you need to end the extraContainers:
line with a |
, creating a YAML block scalar (a multi-line string). Under that you need to put a complete YAML list of container specs. You can include template blocks there if you want to.
在你展示的YAML中,你需要用一个|,创建YAML块标量(多行字符串)。在它下面,你需要放置一个完整的容器规范的YAML列表。如果需要,可以在其中包含模板块。
deploy:
extraContainers: |
- name: gcloud-sqlproxy
image: gcr.io/cloudsql-docker/gce-proxy
env:
- name: KETO_CONFIG_DSN
value: {{ .Values.keto.config.dsn }}
Note that you've provided a couple of links to a separate Helm chart for the proxy. That intrinsically will create a separate Helm release and objects like Kubernetes Deployments for it; it cannot attach it as a sidecar to other Deployments, and you can't use any of that chart's settings in a sidecar-container configuration.
请注意,您已经为代理提供了两个指向单独Helm图表的链接。这本质上将为它创建一个单独的Helm发行版和诸如Kubernetes部署的对象;它不能将它作为侧车附加到其他部署,并且您不能在侧车-容器配置中使用该图表的任何设置。
更多回答
我是一名优秀的程序员,十分优秀!