我想运行一个使用DB的微服务。DB也需要使用PVC/PV部署在同一个kubernetes集群中。用于实现这种逻辑的kubernetes服务名称/命令是什么:
我主要关注的是1-2:如果没有DB,服务就不能工作,但同时需要处于不同的吊舱中(或者我错了,最好把两个容器: DB和服务放在同一个吊舱中?)
发布于 2021-04-28 07:42:17
我会说,您应该将initContainer添加到您的微服务中,这将搜索DB服务,每当它准备就绪时,就会启动微服务。
例如:
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]至于命令,只需将库贝特与您的yaml一起使用(在应用程序中配置了initContainer )。
如果您想以更自动化的方式这样做,可以考虑使用fluxCD/argoCD。
关于评论中的问题,containers that run before the main container runs and the main container must be in the same pod?
是的,他们必须在同一个舱里。因为init容器会起作用除非,f.e。数据库服务将是可维护的,然后主容器将启动。在上面的initContainer文档中有一个很好的例子。
https://stackoverflow.com/questions/67279097
复制相似问题