使用kompose把docker-compose文件转换成k8s资源
source link: https://www.bboy.app/2022/05/09/%E4%BD%BF%E7%94%A8kompose%E6%8A%8Adocker-compose%E6%96%87%E4%BB%B6%E8%BD%AC%E6%8D%A2%E6%88%90k8s%E8%B5%84%E6%BA%90/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用kompose把docker-compose文件转换成k8s资源
Have a nice try
安装很简单,直接一个二进制下载过来就好了
wget https://github.com/kubernetes/kompose/releases/download/v1.26.1/kompose-linux-amd64.tar.gz
tar -zxvf kompose-linux-amd64.tar.gz
mv kompose-linux-amd64 /bin/kompose
首先准备一个docker-compose文件
version: "3"
services:
prometheus:
image: "prom/prometheus:v2.35.0"
volumes:
- "./prometheus-conf/prometheus.yml:/etc/prometheus/prometheus.yml"
- "./data:/prometheus"
- "/etc/localtime:/etc/localtime"
- "./prometheus-conf/file_sd:/file_sd"
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--web.enable-lifecycle"
- "--web.enable-admin-api"
- "--web.enable-remote-write-receiver"
- "--storage.tsdb.retention.time=7d"
- "--storage.tsdb.max-block-duration=2h"
- "--storage.tsdb.min-block-duration=2h"
ports:
- "9000:9000"
- "9090:9090"
restart: "always"
container_name: "prometheus"
之后直接执行
kompose convert
如果你的文件不是docker-compose.yaml
这个名字的,你可以使用-f
参数取指定文件名字
这样生成出来的资源文件默认会带上
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.1 (a9d05d509)
这两个annotations
如果你不想要的话可以这么做
./kompose-linux-amd64 convert -f docker-compose.yaml --with-kompose-annotation=false
默认kompose转换出来的是deployment,当然你想转成daemonset,你可以使用下面参数
--controller=daemonSet
如果你不想生成文件,可以使用下面参数直接输出到屏幕中
--stdout
转换出来的质量还可以,可以帮助yaml工程师少写几个参数了
欢迎关注我的博客www.bboy.app
Have Fun
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK