{"id":15019950,"url":"https://github.com/xarg/kuku","last_synced_at":"2025-10-24T20:32:04.192Z","repository":{"id":62574799,"uuid":"149689716","full_name":"xarg/kuku","owner":"xarg","description":"Kubernetes templating tool","archived":false,"fork":false,"pushed_at":"2020-05-13T15:32:57.000Z","size":45,"stargazers_count":40,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-29T05:21:04.922Z","etag":null,"topics":["cli","helm","k8s","kubernetes","python","python3","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xarg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-21T00:59:14.000Z","updated_at":"2023-10-20T09:28:40.000Z","dependencies_parsed_at":"2022-11-03T20:09:16.041Z","dependency_job_id":null,"html_url":"https://github.com/xarg/kuku","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xarg%2Fkuku","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xarg%2Fkuku/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xarg%2Fkuku/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xarg%2Fkuku/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xarg","download_url":"https://codeload.github.com/xarg/kuku/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867829,"owners_count":16555886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","helm","k8s","kubernetes","python","python3","yaml"],"created_at":"2024-09-24T19:54:22.080Z","updated_at":"2025-10-24T20:32:00.496Z","avatar_url":"https://github.com/xarg.png","language":"Python","funding_links":[],"categories":["Configuration Management"],"sub_categories":[],"readme":"# kuku\n\n[![Build Status](https://travis-ci.org/xarg/kuku.svg?branch=master)](https://travis-ci.org/xarg/kuku)\n\nkuku renders kubernetes yaml manifests using python templates. It is similar to [helm](https://helm.sh/) in usage (templates dir, value files, etc..).\n\n\n## Installation:\n\n```bash\npip3 install kuku\n```\n\nor using the docker image:\n\n```bash\ndocker pull xarg/kuku\n\n# Example usage (see more below):\ndocker run -v $(pwd)/:/tmp/ --rm xarg/kuku render -f /tmp/your-values.yaml /tmp/your-templates/ | kubectl apply -\n```\n\n## Usage\n\nSuppose you want to create a k8s service using a template where you define the service `name`, `internalPort` and `externalPort`.\n\nGiven the following `service.py` template:\n```python\nfrom kubernetes import client\n\n\ndef template(context):\n    return client.V1Service(\n        api_version=\"v1\",\n        kind=\"Service\",\n        metadata=client.V1ObjectMeta(name=context[\"name\"]),\n        spec=client.V1ServiceSpec(\n            type=\"NodePort\",\n            ports=[\n                {\"port\": context[\"externalPort\"], \"targetPort\": context[\"internalPort\"]}\n            ],\n            selector={\"app\": context[\"name\"]},\n        ),\n    )\n```\n\nYou can now generate a yaml output from the above template using `kuku` by running: \n```bash\n$ ls .\nservice.py \n$ kuku render -s name=kuku-web,internalPort=80,externalPort=80 .\n```\nthe above produces:\n```yaml\n# Source: service.py\napiVersion: v1\nkind: Service\nmetadata:\n  name: kuku-web\nspec:\n  ports:\n  - port: 80\n    targetPort: 80\n  selector:\n    app: kuku-web\n  type: NodePort\n```\n\n      \nYou can also combine the above with `kubectl apply -f -` to actually create your service on k8s:\n```bash\nkuku render -s name=kuku-web,internalPort=80,externalPort=80 . | kubectl apply -f -\n```\n    \nSame as above, but let's make it shorter:\n```bash\nkuku apply -s name=kuku-web,internalPort=80,externalPort=80 .\n```\n \n   \nFinally to delete it: \n```bash\nkuku delete -s name=kuku-web,internalPort=80,externalPort=80 .\n# same as above\nkuku render -s name=kuku-web,internalPort=80,externalPort=80 . | kubectl delete -f - \n```\n\n## Templates      \n\nTemplates are python files that are defining a function called `template` that accepts a dict argument `context` and \nreturns a k8s object or a list of k8s objects:\n\n```python\ndef template(context):\n    return V1Namespace(name=context['namespace'])  # example k8s object \n```\n\nYou can create multiple template files each defining their own `template` function.\n`kuku` uses the k8s objects (aka models) from [official kubernetes python client package](https://github.com/kubernetes-client/python).\nYou can find them all [here](https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md#documentation-for-models)\n\n\n## CLI\n\nSimilar to [helm](https://helm.sh/) `kuku` accepts defining it's context variables from the CLI:\n\n```bash\nkuku -s namespace=kuku .\n```\n    \n`-s namespace=kuku` will be passed to the `context` argument in your `template` function. Run `kuku -h` to find out more.\n\n## Goals\n\n#### Write python code to generate k8s manifests.\nPython is a very popular language with a huge ecosystem of devops packages. Most importantly it's easier to debug than \nsome templating languages used today to generate k8s manifests.\n\n#### No k8s server side dependencies (i.e. tiller).\nk8s already has a database for it's current state (using etcd). We can connect directly to it from the client to \ndo our operations instead of relying on an extra server side dependency.\n\n#### Local validation of manifests before running `kubectl apply`. \nWhere possible do the validation locally using the [official k8s python client](https://github.com/kubernetes-client/python).\n\n#### Use standard tools\nWhere possible use `kubectl` to apply changes to the k8s cluster instead of implementing a specific protocol.\nAgain, this will make debugging easier for the end user.\n\n## Why not helm?\n\nAt [Gorgias](https://gorgias.io) we use [helm](https://helm.sh/) to manage our infrastructure, but there are a few \nthings that we found problematic with it:\n\n- Poor templating language: requires constant referral to the docs, whitespace issues, yaml formatting is hard.\n- Server side dependency: if you upgrade the server -\u003e every user needs to update their client - waste of valuable time.\n- Lack of local validation: `helm lint` does not really ensure the validity (i.e. required keys for a k8s object) of the manifest.\n\nChart names, releases and other helm specific features do not really fit with our current workflow.\n\n\n# Contributing\n\nContributions (code, issues, docs, etc..) are welcome!\n\nOnce you have your python environment setup:\n\n```bash\npip install -e .[dev] # will install dev dependencies\npre-commit install # will install pre-commit hooks for code quality checking \n```\n    \nPublish a new version to pypi:\n```bash\npython setup.py upload\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxarg%2Fkuku","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxarg%2Fkuku","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxarg%2Fkuku/lists"}