KubraGen Builder: Traefik 2
Project description
KubraGen Builder: Traefik 2
kg_traefik2 is a builder for KubraGen that deploys a Traefik 2 server in Kubernetes.
KubraGen is a Kubernetes YAML generator library that makes it possible to generate configurations using the full power of the Python programming language.
- Website: https://github.com/RangelReale/kg_traefik2
- Repository: https://github.com/RangelReale/kg_traefik2.git
- Documentation: https://kg_traefik2.readthedocs.org/
- PyPI: https://pypi.python.org/pypi/kg_traefik2
Example
from kubragen import KubraGen
from kubragen.consts import PROVIDER_GOOGLE, PROVIDERSVC_GOOGLE_GKE
from kubragen.object import Object
from kubragen.option import OptionRoot
from kubragen.options import Options
from kubragen.output import OutputProject, OD_FileTemplate, OutputFile_ShellScript, OutputFile_Kubernetes, \
OutputDriver_Print
from kubragen.provider import Provider
from kg_traefik2 import Traefik2Builder, Traefik2Options
kg = KubraGen(provider=Provider(PROVIDER_GOOGLE, PROVIDERSVC_GOOGLE_GKE), options=Options({
'namespaces': {
'mon': 'app-monitoring',
},
}))
out = OutputProject(kg)
shell_script = OutputFile_ShellScript('create_gke.sh')
out.append(shell_script)
shell_script.append('set -e')
#
# OUTPUTFILE: app-namespace.yaml
#
file = OutputFile_Kubernetes('app-namespace.yaml')
file.append([
Object({
'apiVersion': 'v1',
'kind': 'Namespace',
'metadata': {
'name': 'app-monitoring',
},
}, name='ns-monitoring', source='app', instance='app')
])
out.append(file)
shell_script.append(OD_FileTemplate(f'kubectl apply -f ${{FILE_{file.fileid}}}'))
shell_script.append(f'kubectl config set-context --current --namespace=app-monitoring')
#
# SETUP: traefik2
#
traefik2_config = Traefik2Builder(kubragen=kg, options=Traefik2Options({
'namespace': OptionRoot('namespaces.mon'),
'basename': 'mytraefik2',
'kubernetes': {
'resources': {
'deployment': {
'requests': {
'cpu': '150m',
'memory': '300Mi'
},
'limits': {
'cpu': '300m',
'memory': '450Mi'
},
},
},
}
}))
traefik2_config.ensure_build_names(traefik2_config.BUILD_CRD, traefik2_config.BUILD_ACCESSCONTROL,
traefik2_config.BUILD_SERVICE)
#
# OUTPUTFILE: traefik2-crd.yaml
#
file = OutputFile_Kubernetes('traefik2-crd.yaml')
out.append(file)
file.append(traefik2_config.build(traefik2_config.BUILD_CRD))
shell_script.append(OD_FileTemplate(f'kubectl apply -f ${{FILE_{file.fileid}}}'))
#
# OUTPUTFILE: traefik2-config.yaml
#
file = OutputFile_Kubernetes('traefik2-config.yaml')
out.append(file)
file.append(traefik2_config.build(traefik2_config.BUILD_ACCESSCONTROL))
shell_script.append(OD_FileTemplate(f'kubectl apply -f ${{FILE_{file.fileid}}}'))
#
# OUTPUTFILE: traefik2.yaml
#
file = OutputFile_Kubernetes('traefik2.yaml')
out.append(file)
file.append(traefik2_config.build(traefik2_config.BUILD_SERVICE))
shell_script.append(OD_FileTemplate(f'kubectl apply -f ${{FILE_{file.fileid}}}'))
#
# Write files
#
out.output(OutputDriver_Print())
# out.output(OutputDriver_Directory('/tmp/build-gke'))
Output:
****** BEGIN FILE: 001-app-namespace.yaml ********
apiVersion: v1
kind: Namespace
metadata:
name: app-monitoring
****** END FILE: 001-app-namespace.yaml ********
****** BEGIN FILE: 002-traefik2-crd.yaml ********
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressroutes.traefik.containo.us
spec:
group: traefik.containo.us
<...more...>
****** END FILE: 002-traefik2-crd.yaml ********
****** BEGIN FILE: 003-traefik2-config.yaml ********
apiVersion: v1
kind: ServiceAccount
metadata:
name: mytraefik2
namespace: app-monitoring
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: mytraefik2
rules:
- apiGroups: ['']
<...more...>
****** END FILE: 003-traefik2-config.yaml ********
****** BEGIN FILE: 004-traefik2.yaml ********
kind: Deployment
apiVersion: apps/v1
metadata:
name: mytraefik2
namespace: app-monitoring
labels:
app: mytraefik2
spec:
selector:
matchLabels:
app: mytraefik2
<...more...>
****** END FILE: 004-traefik2.yaml ********
****** BEGIN FILE: create_gke.sh ********
#!/bin/bash
set -e
kubectl apply -f 001-app-namespace.yaml
kubectl config set-context --current --namespace=app-monitoring
kubectl apply -f 002-traefik2-crd.yaml
kubectl apply -f 003-traefik2-config.yaml
kubectl apply -f 004-traefik2.yaml
****** END FILE: create_gke.sh ********
Credits
based on
Author
Rangel Reale (rangelspam@gmail.com)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kg_traefik2-0.7.2.tar.gz
(8.9 kB
view details)
Built Distribution
File details
Details for the file kg_traefik2-0.7.2.tar.gz
.
File metadata
- Download URL: kg_traefik2-0.7.2.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8abc661b3e7ec60a09b47d106b6cb316076ae7ea99339d965f8b1c5e278d3520 |
|
MD5 | 2cd12cfed686ca8c8401d61119ccd0be |
|
BLAKE2b-256 | 1c693ad90815f878f230f7f966693b0d3efdbf323c09c9beade53bb1ab68a3e5 |
File details
Details for the file kg_traefik2-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: kg_traefik2-0.7.2-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3e7de208a0c7ab526c88dc35d3e5cbb4b94dfcae9956c5e2c17e5ea62365b3e |
|
MD5 | 1fb1b1ad01382f510bf5c1e3d0870979 |
|
BLAKE2b-256 | 7efffeff79c544425e18e783c9522ee5d435f7bb0b6ad837a5a31fd1a9ee7cff |