简体   繁体   English

如何将独立的mysql容器作为依赖项传递给kubernetes-helm中的服务?

[英]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.

相关问题 如何将抓取目标添加到安装了 Kubernetes-Helm 的 Prometheus 服务器? - How do you add scrape targets to a Prometheus server that was installed with Kubernetes-Helm? kubernetes-helm:使用xfs格式格式化do-block-storage - kubernetes-helm: formating do-block-storage with xfs format Kubernetes-Helm Charts 指向本地 docker 镜像 - Kubernetes-Helm Charts pointing to a local docker image 如何在Kubernetes上访问MySQL即服务? - How do I access MySQL as a Service on Kubernetes? 如何将 kubernetes 部署/副本集的名称传递给容器? - How do I pass the name of a kubernetes deployment/replica set to the container? kubernetes-如何将 mysql 服务暴露给另一个 pod? - kubernetes-How do I expose mysql service to another pod? 如何在 helm 图表中使用 kubernetes volumeMounts: mountPath 和 hostPath? - How do I use kubernetes volumeMounts: mountPath and hostPath in helm charts? 使用 Helm Chart 和 Kubernetes,在 postStart 期间将文件传递给容器 - Using Helm Chart and Kubernetes, pass a file to the container during postStart 由 Kubernetes-Helm 创建的自定义 JSON 文件在卷曲/浏览时被切断 - Custom JSON file created by Kubernetes-Helm gets cut off when curling/browsing to it 如果我想更改 kubernetes 中由 alertmanager 操作的服务使用的端口,我应该在哪里编辑 helm chart? - Where do I edit the helm chart if I want to change the port used by alertmanager-operated service in kubernetes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM