Package: kuku
kukukuku renders kubernetes yaml manifests using python templates. It is similar tohelmin usage (templates dir, value files, etc..).Installation:pip3installkukuor using the docker image:dockerpullxarg/kuku# Example usage (see more below):dockerrun-v$(pwd)/:/tmp/--rmxarg/kukurender-f/tmp/your-values.yaml/tmp/your-templates/|kubectlapply-UsageSuppose you want to create a k8s service using a template where you define the servicename,internalPortandexternalPort.Given the followingservice.pytemplate:fromkubernetesimportclientdeftemplate(context):returnclient.V1Service(api_version="v1",kind="Service",metadata=client.V1ObjectMeta(name=context["name"]),spec=client.V1ServiceSpec(type="NodePort",ports=[{"port":context["externalPort"],"targetPort":context["internalPort"]}],selector={"app":context["name"]},),)You can now generate a yaml output from the above template usingkukuby running:$ls.
service.py$kukurender-sname=kuku-web,internalPort=80,externalPort=80.the above produces:# Source: service.pyapiVersion:v1kind:Servicemetadata:name:kuku-webspec:ports:-port:80targetPort:80selector:app:kuku-webtype:NodePortYou can also combine the above withkubectl apply -f -to actually create your service on k8s:kukurender-sname=kuku-web,internalPort=80,externalPort=80.|kubectlapply-f-Same as above, but let's make it shorter:kukuapply-sname=kuku-web,internalPort=80,externalPort=80.Finally to delete it:kukudelete-sname=kuku-web,internalPort=80,externalPort=80.# same as abovekukurender-sname=kuku-web,internalPort=80,externalPort=80.|kubectldelete-f-TemplatesTemplates are python files that are defining a function calledtemplatethat accepts a dict argumentcontextand
returns a k8s object or a list of k8s objects:deftemplate(context):returnV1Namespace(name=context['namespace'])# example k8s objectYou can create multiple template files each defining their owntemplatefunction.kukuuses the k8s objects (aka models) fromofficial kubernetes python client package.
You can find them allhereCLISimilar tohelmkukuaccepts defining it's context variables from the CLI:kuku-snamespace=kuku.-s namespace=kukuwill be passed to thecontextargument in yourtemplatefunction. Runkuku -hto find out more.GoalsWrite python code to generate k8s manifests.Python is a very popular language with a huge ecosystem of devops packages. Most importantly it's easier to debug than
some templating languages used today to generate k8s manifests.No k8s server side dependencies (i.e. tiller).k8s already has a database for it's current state (using etcd). We can connect directly to it from the client to
do our operations instead of relying on an extra server side dependency.Local validation of manifests before runningkubectl apply.Where possible do the validation locally using theofficial k8s python client.Use standard toolsWhere possible usekubectlto apply changes to the k8s cluster instead of implementing a specific protocol.
Again, this will make debugging easier for the end user.Why not helm?AtGorgiaswe usehelmto manage our infrastructure, but there are a few
things that we found problematic with it:Poor templating language: requires constant referral to the docs, whitespace issues, yaml formatting is hard.Server side dependency: if you upgrade the server -> every user needs to update their client - waste of valuable time.Lack of local validation:helm lintdoes not really ensure the validity (i.e. required keys for a k8s object) of the manifest.Chart names, releases and other helm specific features do not really fit with our current workflow.ContributingContributions (code, issues, docs, etc..) are welcome!Once you have your python environment setup:pipinstall-e.[dev]# will install dev dependenciespre-commitinstall# will install pre-commit hooks for code quality checkingPublish a new version to pypi:pythonsetup.pyupload