docker-compose转为k8s配置文件
Posted 悟初境
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker-compose转为k8s配置文件相关的知识,希望对你有一定的参考价值。
最近搞k8s,需要把docker-compose配置转为k8s的配置文件,涉及到的地方主要在下面。
挂载volume
docker-compose里的写法:
service:
relay:
image: getsentry/relay:22.6.0
volumes:
- "./geoip:/sentry"
- type: bind
read_only: true
source: ./relay
target: /work/.relay
- type: bind
read_only: true
source: ./geoip
target: /geoip
k8s通过volume名称对应
spec:
containers:
- name: sentry-relay
image: getsentry/relay:22.6.0
volumeMounts:
- mountPath: /work/.relay
name: v-relay-config
- mountPath: /geoip
name: v-relay-geoip
volumes:
- name: v-relay-config
hostPath:
path: ./relay
type: Directory
- name: v-relay-geoip
hostPath:
path: ./geoip
type: Directory
声明环境变量
docker-compose的写法
snuba:
image: "$SNUBA_IMAGE"
environment:
SNUBA_SETTINGS: distributed
CLICKHOUSE_HOST: 172.17.183.16
Pod
spec:
containers:
- name: sentry-snuba-api
image: getsentry/snuba:22.6.0
env:
- name: SNUBA_SETTINGS
value: "distributed"
- name: CLICKHOUSE_HOST
value: "172.17.183.16"
执行入口命令
更多请参考文档:https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/define-command-argument-container/
docker-compose的写法
snuba-consumer:
<<: *snuba_defaults
command: consumer --storage errors --auto-offset-reset=latest --max-batch-time-ms 750
k8s
spec:
containers:
- name: sentry-snuba-consumer
image: getsentry/snuba:22.6.0
command: ["consumer", "--storage", "errors", "--auto-offset-reset=latest", "--max-batch-time-ms", "750"]
depend on
docker-compose里经常会有一个服务依赖于另一个服务的情况:
nginx:
image: "nginx:1.21.6-alpine"
depends_on:
- web
- relay
然而在k8s里这种情况并不好处理,原则上这不关k8s的事,每个pod应该是互不干扰的无状态服务,所以应该交给服务自身去考虑。
更多补充…
以上是关于docker-compose转为k8s配置文件的主要内容,如果未能解决你的问题,请参考以下文章
YAML文件格式_k8s/docker-compose配置文件