12 Commits

Author SHA1 Message Date
35ecb0d4d9 Add temporary logo 2022-02-17 12:22:52 +01:00
89adc17857 Add doc for "same-pod" example 2022-02-17 11:54:09 +01:00
16fddbc6aa Fixed ignore list 2022-02-17 11:53:15 +01:00
8543bc5232 Added some generated examples 2022-02-17 11:48:33 +01:00
3d45401649 Fixup doc 2022-02-17 11:38:48 +01:00
95c24be14a Make it possible to mount one file from configMap 2022-02-17 11:38:23 +01:00
bf44d442e5 Fix "/" in configMap names
Fix #2
2022-02-17 11:04:04 +01:00
5d574015ce Fix the missed volume mount for empty dirs
Fix #1
2022-02-17 10:43:07 +01:00
3619cc4b20 Update README.md
Add Releases information to install katenary
2022-02-17 10:06:50 +01:00
5a49c4f869 Forgotten logo file... 2022-02-17 09:58:44 +01:00
88fb12a3bf Add Smile :) 2022-02-17 09:58:09 +01:00
d387d9aec0 Add MIT License 2022-02-17 09:42:32 +01:00
29 changed files with 541 additions and 5 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ docker-compose.yaml
katenary
*.env
docker-compose*
!examples/**/docker-compose*

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Patrice Ferlet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,10 +1,18 @@
![Logo](misc/logo.png)
Katenary is a tool to help transforming `docker-compose` files to a working Helm Chart for Kubernetes.
> **Important Note** Katenary is a tool to help building Helm Chart from a docker-compose file, but docker-compose doesn't propose as many features as what can do Kubernetes. So, we strongly recommend to use Katenary as a "bootstrap" tool and then to manually enhance the generated helm chart.
This project is partially made at [Smile](https://smile.eu)
![smile logo](misc/Logo_Smile.png)
# Install
You can download the binaries from the [Release](https://github.com/metal3d/katenary/releases) section. Copy the binary and rename it to `katenary`. Place the binary inside your `PATH`. You should now be able to call the `katenary` command.
If you've got `podman` or `docker`, you can build `katenary` by using:
```bash
@@ -93,7 +101,7 @@ What can be interpreted by Katenary:
- `env_file` list will create a configMap object per environemnt file (⚠ todo: the "to-service" label doesn't work with configMap for now)
- some labels can help to bind values, for example:
- `katenary.io/ingress: 80` will expose the port 80 in a ingress
- `katenary.io/to-service: VARNAME` will convert the value to a variable `{{ .Release.Name }}-VARNAME` - it's usefull when you want to pass the name of a service as a variable (think about the service name for mysql to pass to a container that wants to connect to this)
- `katenary.io/env-to-service: VARNAME` will convert the value to a variable `{{ .Release.Name }}-VARNAME` - it's usefull when you want to pass the name of a service as a variable (think about the service name for mysql to pass to a container that wants to connect to this)
Exemple of a possible `docker-compose.yaml` file:

10
examples/basic/README.md Normal file
View File

@@ -0,0 +1,10 @@
# Basic example
This is a basic example of what can do Katenary with standard docker-compose file.
In this example:
- `depends_on` yield a `initContainer` in the webapp ddeployment to wait for database
- so we need to declare the listened port inside `database` container as we don't use it with docker-compose- also, we needed to declare that `DB_HOST` is actually a service name
Take a look on [chart/basic](chart/basic) directory to see what `katenary convert` command has generated.

View File

@@ -0,0 +1,8 @@
# Create on 2022-02-17T10:27:30+01:00
# Katenary command line: katenary convert
apiVersion: v2
appVersion: 0.0.1
description: A helm chart for basic
name: basic
type: application
version: 0.1.0

View File

@@ -0,0 +1,8 @@
Congratulations,
Your application is now deployed. This may take a while to be up and responding.
{{ if .Values.webapp.ingress.enabled -}}
- webapp is accessible on : http://{{ .Values.webapp.ingress.host }}
{{- end }}

View File

@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: '{{ .Release.Name }}-database'
labels:
katenary.io/component: database
katenary.io/project: basic
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
katenary.io/version: master-3619cc4
spec:
replicas: 1
selector:
matchLabels:
katenary.io/component: database
katenary.io/release: '{{ .Release.Name }}'
template:
metadata:
labels:
katenary.io/component: database
katenary.io/release: '{{ .Release.Name }}'
spec:
containers:
- name: database
image: '{{ .Values.database.image }}'
ports:
- name: database
containerPort: 3306
env:
- name: MARIADB_PASSWORD
value: foo
- name: MARIADB_DATABASE
value: myapp
- name: MARIADB_ROOT_PASSWORD
value: foobar
- name: MARIADB_USER
value: foo

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: '{{ .Release.Name }}-database'
labels:
katenary.io/component: database
katenary.io/project: basic
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
katenary.io/version: master-3619cc4
spec:
selector:
katenary.io/component: database
katenary.io/release: '{{ .Release.Name }}'
ports:
- protocol: TCP
port: 3306
targetPort: 3306

View File

@@ -0,0 +1,48 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: '{{ .Release.Name }}-webapp'
labels:
katenary.io/component: webapp
katenary.io/project: basic
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
katenary.io/version: master-3619cc4
spec:
replicas: 1
selector:
matchLabels:
katenary.io/component: webapp
katenary.io/release: '{{ .Release.Name }}'
template:
metadata:
labels:
katenary.io/component: webapp
katenary.io/release: '{{ .Release.Name }}'
spec:
initContainers:
- name: check-database
image: busybox
command:
- sh
- -c
- |-
OK=0
echo "Checking database port"
while [ $OK != 1 ]; do
echo -n "."
nc -z {{ .Release.Name }}-database 3306 2>&1 >/dev/null && OK=1 || sleep 1
done
echo
echo "Done"
containers:
- name: webapp
image: '{{ .Values.webapp.image }}'
ports:
- name: webapp
containerPort: 80
env:
- name: DB_HOST
value: '{{ .Release.Name }}-database'

View File

@@ -0,0 +1,34 @@
{{- if .Values.webapp.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: '{{ .Release.Name }}-webapp'
labels:
katenary.io/component: webapp
katenary.io/project: basic
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
katenary.io/version: master-3619cc4
spec:
{{- if and .Values.webapp.ingress.class (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: '{{ .Values.webapp.ingress.class }}'
{{- end }}
rules:
- host: '{{ .Values.webapp.ingress.host }}'
http:
paths:
- path: /
pathType: Prefix
backend:
{{- if semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion }}
service:
name: '{{ .Release.Name }}-webapp'
port:
number: 80
{{- else }}
serviceName: '{{ .Release.Name }}-webapp'
servicePort: 80
{{- end }}
{{- end -}}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: '{{ .Release.Name }}-webapp'
labels:
katenary.io/component: webapp
katenary.io/project: basic
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: b9f12bb7d1e97901c1d7680394209525763f6640
katenary.io/version: master-3619cc4
spec:
selector:
katenary.io/component: webapp
katenary.io/release: '{{ .Release.Name }}'
ports:
- protocol: TCP
port: 80
targetPort: 80

View File

@@ -0,0 +1,8 @@
database:
image: mariadb:10
webapp:
image: php:7-apache
ingress:
class: nginx
enabled: false
host: webapp.basic.tld

View File

@@ -0,0 +1,30 @@
version: "3"
services:
webapp:
image: php:7-apache
environment:
DB_HOST: database
ports:
- "8080:80"
labels:
# expose an ingress
katenary.io/ingress: 80
# DB_HOST is actually a service name
katenary.io/env-to-service: DB_HOST
depends_on:
- database
database:
image: mariadb:10
environment:
MARIADB_ROOT_PASSWORD: foobar
MARIADB_USER: foo
MARIADB_PASSWORD: foo
MARIADB_DATABASE: myapp
labels:
# because we don't provide "ports" or "expose", alert katenary
# to use the mysql port for service declaration
katenary.io/ports: 3306

View File

@@ -0,0 +1,13 @@
# Make it possible to bind several containers in one pod
In this example, we need to make nginx and php-fpm to run inside the same "pod". The reason is that we configured FPM to listen an unix socket instead of the 9000 port.
Because NGinx will need to connect to the unix socket wich is a file, both containers should share the same node and work together.
So, in the docker-compose file, we need to declare:
- `katenary.io/empty-dirs: socket` where `socket` is the "volume name", this will avoid the creation of a PVC
- `katenary.io/same-pod: http` in `php` container to declare that this will be added in the `containers` section of the `http` deployment
You can note that we also use `configmap-volumes` to declare our configuration as `configMap`.
Take a look on [chart/same-pod](chart/same-pod) directory to see the result of the `katenary convert` command.

View File

@@ -0,0 +1,8 @@
# Create on 2022-02-17T11:36:02+01:00
# Katenary command line: katenary convert --force
apiVersion: v2
appVersion: 0.0.1
description: A helm chart for same-pod
name: same-pod
type: application
version: 0.1.0

View File

@@ -0,0 +1,8 @@
Congratulations,
Your application is now deployed. This may take a while to be up and responding.
{{ if .Values.http.ingress.enabled -}}
- http is accessible on : http://{{ .Values.http.ingress.host }}
{{- end }}

View File

@@ -0,0 +1,23 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Release.Name }}-config-nginx-http'
labels:
katenary.io/component: ""
katenary.io/project: same-pod
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: 74e67695bfdbb829f15531321e158808018280e0
katenary.io/version: master-bf44d44
data:
default.conf: |
upstream _php {
server unix:/sock/fpm.sock;
}
server {
listen 80;
location ~ ^/index\.php(/|$) {
fastcgi_pass _php;
include fastcgi_params;
}
}

View File

@@ -0,0 +1,30 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Release.Name }}-config-php-php'
labels:
katenary.io/component: ""
katenary.io/project: same-pod
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: 74e67695bfdbb829f15531321e158808018280e0
katenary.io/version: master-bf44d44
data:
www.conf: |
[www]
user = www-data
group = www-data
listen = /sock/fpm.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
access.log = /proc/self/fd/2
log_limit = 8192
clear_env = no
catch_workers_output = yes
decorate_workers_output = no

View File

@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: '{{ .Release.Name }}-http'
labels:
katenary.io/component: http
katenary.io/project: same-pod
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: 74e67695bfdbb829f15531321e158808018280e0
katenary.io/version: master-bf44d44
spec:
replicas: 1
selector:
matchLabels:
katenary.io/component: http
katenary.io/release: '{{ .Release.Name }}'
template:
metadata:
labels:
katenary.io/component: http
katenary.io/release: '{{ .Release.Name }}'
spec:
containers:
- name: http
image: '{{ .Values.http.image }}'
ports:
- name: http
containerPort: 80
volumeMounts:
- mountPath: /sock
name: sock
- mountPath: /etc/nginx/conf.d
name: config-nginx
- name: php
image: '{{ .Values.php.image }}'
volumeMounts:
- mountPath: /sock
name: sock
- mountPath: /usr/local/etc/php-fpm.d/www.conf
name: config-php
subPath: www.conf
volumes:
- emptyDir: {}
name: sock
- configMap:
name: '{{ .Release.Name }}-config-nginx-http'
name: config-nginx
- configMap:
name: '{{ .Release.Name }}-config-php-php'
name: config-php

View File

@@ -0,0 +1,34 @@
{{- if .Values.http.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: '{{ .Release.Name }}-http'
labels:
katenary.io/component: http
katenary.io/project: same-pod
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: 74e67695bfdbb829f15531321e158808018280e0
katenary.io/version: master-bf44d44
spec:
{{- if and .Values.http.ingress.class (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: '{{ .Values.http.ingress.class }}'
{{- end }}
rules:
- host: '{{ .Values.http.ingress.host }}'
http:
paths:
- path: /
pathType: Prefix
backend:
{{- if semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion }}
service:
name: '{{ .Release.Name }}-http'
port:
number: 80
{{- else }}
serviceName: '{{ .Release.Name }}-http'
servicePort: 80
{{- end }}
{{- end -}}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: '{{ .Release.Name }}-http'
labels:
katenary.io/component: http
katenary.io/project: same-pod
katenary.io/release: '{{ .Release.Name }}'
annotations:
katenary.io/docker-compose-sha1: 74e67695bfdbb829f15531321e158808018280e0
katenary.io/version: master-bf44d44
spec:
selector:
katenary.io/component: http
katenary.io/release: '{{ .Release.Name }}'
ports:
- protocol: TCP
port: 80
targetPort: 80

View File

@@ -0,0 +1,8 @@
http:
image: nginx:alpine
ingress:
class: nginx
enabled: false
host: http.same-pod.tld
php:
image: php:fpm

View File

@@ -0,0 +1,10 @@
upstream _php {
server unix:/sock/fpm.sock;
}
server {
listen 80;
location ~ ^/index\.php(/|$) {
fastcgi_pass _php;
include fastcgi_params;
}
}

View File

@@ -0,0 +1,17 @@
[www]
user = www-data
group = www-data
listen = /sock/fpm.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
access.log = /proc/self/fd/2
log_limit = 8192
clear_env = no
catch_workers_output = yes
decorate_workers_output = no

View File

@@ -0,0 +1,38 @@
version: "3"
services:
http:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- "sock:/sock"
- "./config/nginx:/etc/nginx/conf.d:z"
labels:
# the "sock" volume will need to be shared to the same pod, so let's
# declare that this is not a PVC
katenary.io/empty-dirs: sock
# use ./config/nginx as a configMap
katenary.io/configmap-volumes: ./config/nginx
# declare an ingress
katenary.io/ingress: 80
php:
image: php:fpm
volumes:
- "sock:/sock"
- "./config/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:z"
labels:
# fpm will need to use a unix socket shared
# with nginx (http service above), so we want here
# make a single pod containing nginx and php
katenary.io/same-pod: http
# use the ./config/php files as a configMap
katenary.io/configmap-volumes: ./config/php/www.conf
volumes:
sock:

View File

@@ -403,11 +403,21 @@ func prepareVolumes(deployment, name string, s *compose.Service, container *helm
continue
}
if isCM {
// check if the volname path points on a file, if so, we need to add subvolume to the interface
stat, _ := os.Stat(volname)
pointToFile := ""
if !stat.IsDir() {
pointToFile = filepath.Base(volname)
volname = filepath.Dir(volname)
}
// the volume is a path and it's explicitally asked to be a configmap in labels
cm := buildCMFromPath(volname)
volname = strings.Replace(volname, "./", "", 1)
volname = strings.ReplaceAll(volname, "/", "-")
volname = strings.ReplaceAll(volname, ".", "-")
cm.K8sBase.Metadata.Name = RELEASE_NAME + "-" + volname + "-" + name
// build a configmap from the volume path
volumes = append(volumes, map[string]interface{}{
"name": volname,
@@ -415,10 +425,18 @@ func prepareVolumes(deployment, name string, s *compose.Service, container *helm
"name": cm.K8sBase.Metadata.Name,
},
})
if len(pointToFile) > 0 {
mountPoints = append(mountPoints, map[string]interface{}{
"name": volname,
"mountPath": volepath,
"subPath": pointToFile,
})
} else {
mountPoints = append(mountPoints, map[string]interface{}{
"name": volname,
"mountPath": volepath,
})
}
ret <- cm
} else {
// rmove minus sign from volume name
@@ -432,6 +450,11 @@ func prepareVolumes(deployment, name string, s *compose.Service, container *helm
"name": volname,
"emptyDir": map[string]string{},
})
mountPoints = append(mountPoints, map[string]interface{}{
"name": volname,
"mountPath": volepath,
})
container.VolumeMounts = mountPoints
isEmptyDir = true
break
}

BIN
misc/LogoMakr-1TEtSp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
misc/Logo_Smile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
misc/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB