[英]How do i pass a standalone mysql container as a dependency to a service in kubernetes-helm?
I have a service for which a helm chart has been generated. 我有为其生成舵图的服务。 This helm chart spins off zookeeper and mysql containers with which the service communicates.
该舵图分解了与服务进行通信的zookeeper和mysql容器。 I now want to create a helm chart that spins off a platform of services of which the above service is one.
我现在想创建一个舵图,该舵图衍生出一个服务平台,上述服务就是其中之一。 When i attempt to do this, I use tags to disable the above service's dependencies that are listed in the helm chart, like so:
当我尝试执行此操作时,我使用标记禁用了舵表中列出的上述服务的依赖关系,如下所示:
tags:
service-zookeeper: false
service-mysql: false
Now, i have a few init containers(liquibase) that populate the mysql instances created via dependencies whenever the service is deployed. 现在,我有一些初始化容器(liquibase),每当部署服务时,该容器就会填充通过依赖关系创建的mysql实例。 I need to pass a separate, stand alone mysql container as the instance of mysql that this init container needs to populate.
我需要传递一个单独的独立mysql容器作为此init容器需要填充的mysql实例。 A similar chroots job for zookeeper exists.
动物园管理员也有类似的chroots工作。 The problem I need help tackling is that I can't seem to find a way to pass the separate mysql container as the container that needs to be populated by the first service's liquibase init-container.
我需要帮助解决的问题是,我似乎无法找到一种方法来传递单独的mysql容器,因为该容器需要由第一个服务的liquibase init-container填充。 Is there any way to do so?
有什么办法吗? Any help/insights are appreciated.
任何帮助/见解表示赞赏。
You just need the MySQL Service's hostname and credentials for this. 您只需要为此使用MySQL服务的主机名和凭据。
Remember that the Helm YAML templates can use everything in the Go text/template language . 请记住,Helm YAML模板可以使用Go文本/模板语言中的所有内容 。 That includes conditionals
{{ if ... }}...{{ else }}...{{ end }}
, among other control structures, plus most of the support functions in the Sprig library. 其中包括条件
{{ if ... }}...{{ else }}...{{ end }}
,以及其他控制结构,以及Sprig库中的大多数支持功能。 This can become verbose, but neatly solves this class of problem. 这可能会变得很冗长,但可以很好地解决此类问题。
For the host name, one approach is to assert a single service name, whether installed by your chart itself or the wrapper chart. 对于主机名,一种方法是声明一个服务名,无论是由图表本身还是由包装器图表安装。 (If the top-level chart installs MySQL, and also installs your service, they will have the same Helm release name and the same generated hostname, independently of whether MySQL is a direct dependency of your chart.)
(如果顶级图表安装了MySQL,并且还安装了您的服务,则它们将具有相同的Helm版本名称和相同的生成的主机名,而与MySQL是否直接依赖于图表无关。)
- name: MYSQL_HOST
value: {{ printf "%s-mysql.%s.svc.cluster.local" .Release.Name .Release.Namespace | quote }}
Another is to pass it in the values.yaml
configuration, optionally. 另一个选择是在
values.yaml
配置中传递它。 The Sprig default
function is useful here. Sprig
default
功能在这里很有用。
- name: MYSQL_HOST
value: {{ .Values.mysqlHostname | default (printf "%s-mysql.%s.svc.cluster.local" .Release.Name .Release.Namespace) | quote }}
You can use a similar approach to either find the Secret the MySQL installation saves its passwords in or reconstruct it from configuration. 您可以使用类似的方法找到MySQL安装程序将密码保存在其中的秘密,或者从配置中重构它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.