Use kompose to convert docker-compose files into k8s resources

Introduction

Have a nice try

Install

The installation is very simple, just download a binary directly

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

use

First prepare a docker-compose file

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
 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"

execute directly after

kompose convert

Enough

If your file is not docker-compose.yaml , you can use the -f parameter to get the specified file name

The resource file generated in this way will be brought with it by default.

 1
2
3
 annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.1 ( a9d05d509 )

these two annotations

You can do this if you don’t want to

./kompose-linux-amd64 convert -f docker-compose.yaml --with-kompose-annotation=false

The default converted from kompose is deployment. Of course, if you want to convert to daemonset, you can use the following parameters

--controller=daemonSet

If you don’t want to generate a file, you can use the following parameters to output directly to the screen

--stdout

say a word

The quality of the conversion is OK, it can help the yaml engineer to write a few parameters less

Welcome to my blog www.bboy.app

Have Fun

This article is reprinted from: 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/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment