Kubernetes:在多容器Pod / Job中停止CloudSQL-proxy sidecar容器 [英] Kubernetes: stop CloudSQL-proxy sidecar container in multi container Pod/Job
问题描述
我有一个在CloudSQL数据库上执行数据库迁移的Kubernetes JOB
。
从GKE访问CloudSQL数据库的一种方法是使用CloudSQL代理容器,然后通过 localhost
连接。伟大 - 这是迄今为止的工作。但是因为我正在K8s JOB
中做这个工作,因为代理继续运行,作业没有被标记为成功。
I have a Kubernetes JOB
that does database migrations on a CloudSQL database.
One way to access the CloudSQL database from GKE is to use the CloudSQL-proxy container and then connect via localhost
. Great - that's working so far. But because I'm doing this inside a K8s JOB
the job is not marked as successfully finished because the proxy keeps on running.
$ kubectrl get po
NAME READY STATUS RESTARTS AGE
db-migrations-c1a547 1/2 Completed 0 1m
即使输出说完成,最初两个容器之一仍在运行 - 代理。
Even though the output says 'completed' one of the initially two containers is still running - the proxy.
如何使代理退出完成容器1中的迁移?
How can I make the proxy exit on completing the migrations inside container 1?
推荐答案
一个可能的解决方案作为具有匹配服务的单独的cloudql-proxy部署。然后,您只需要将连接到您的代理服务的作业中的迁移容器。
One possible solution would be a separate cloudsql-proxy deployment with a matching service. You would then only need your migration container inside the job that connects to your proxy service.
这有一些缺点:
- 更高的网络延迟,没有pod本地mysql通信
- 如果您将sql端口提供给整个kubernetes集群,可能会出现安全问题
如果要打开cloudql-proxy到整个集群,您必须替换 tcp:3306
在cloudql-proxy上的 -instance
参数中使用 tcp:0.0.0.0:3306
If you want to open cloudsql-proxy to the whole cluster you have to replace tcp:3306
with tcp:0.0.0.0:3306
in the -instance
parameter on the cloudsql-proxy.
这篇关于Kubernetes:在多容器Pod / Job中停止CloudSQL-proxy sidecar容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!