{"id":22351411,"url":"https://github.com/metio/kdk","last_synced_at":"2026-06-19T18:32:27.188Z","repository":{"id":73641162,"uuid":"264543756","full_name":"metio/kdk","owner":"metio","description":"Infrastructure as code approach for Kubernetes","archived":false,"fork":false,"pushed_at":"2022-12-14T20:45:30.000Z","size":347,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-10T04:23:41.964Z","etag":null,"topics":["java","jshell","k8s","kubernetes","repl","yaml-generator"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metio.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,"governance":null,"roadmap":null,"authors":"AUTHORS/WAIVER","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-16T23:03:29.000Z","updated_at":"2020-05-24T19:08:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9b7ba1c-7f42-406d-9ecc-a1a1546c86d0","html_url":"https://github.com/metio/kdk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/metio/kdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metio%2Fkdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metio%2Fkdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metio%2Fkdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metio%2Fkdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metio","download_url":"https://codeload.github.com/metio/kdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metio%2Fkdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34544403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["java","jshell","k8s","kubernetes","repl","yaml-generator"],"created_at":"2024-12-04T12:13:54.221Z","updated_at":"2026-06-19T18:32:27.183Z","avatar_url":"https://github.com/metio.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k8s definition kit (kdk)\n\n`kdk` is an infrastructure as code approach for Kubernetes inspired by [aws-cdk](https://docs.aws.amazon.com/cdk/latest/guide/home.html) and [cdk-clj](https://github.com/StediInc/cdk-clj). Think of it like a programmable [helm](https://helm.sh/) chart.\n\n## Alternatives\n\n- https://cdk8s.io/\n- https://jkcfg.github.io/\n\n## Usage\n\n`kdk` requires at least Java 11 installed and supports 4 major use cases:\n\n1. **construct** Kubernetes resources\n2. **stack** Kubernetes resources\n3. **validate** Kubernetes resources\n4. **serialize** Kubernetes resources\n\n### Construct\n\nUse `kdk` to construct various k8s resources like this:\n\n```\nvar service = Service.builder()\n    .metadata(...)\n    .spec(...)\n    .build();\n```\n\nEach supported k8s resource has a corresponding Java class with the same name that expose one or more builder methods. Use those methods to construct your stack.\n\n### Stack\n\nThe `Stack` class does not exist in the k8s API and solely exists in `kdk` to wrap multiple resources together in one 'stack'.\n\n```\nvar stack = Stack.builder()\n    .addServices(service)\n    .build();\n```\n\nConsider publishing your application stack, so that others can easily integrate your work in their project.\n\n### Validate\n\nIn order to validate your construct, use the `Validate` class. It supports an easy to use API which can be customizationed in order to fit to your project. Several built-in validators are available, as well as presets which group these validators together.\n\n```\nvar errors = Validate.validate(stack);\n```\n\nThe above call will use the `recommended` preset. Use another one by specifying the validators as a second parameter:\n\n```\nvar errors = Validate.validate(stack, Validators.all());\n```\n\nBesides `recommended`, there are `all`, `deprecated`, and `none` presets. Use `Validators.builder()` to construct your custom set of validation rules. Each validator is a function that transforms `TYPE` to `Stream\u003cValidationError`. `TYPE` represents one of the available k8s API types. The builder for `Validators` will accept any function that matches that signature as a custom validator and execute it in case a matching resource is encountered during validation.\n\n```\nvar errors = Validate.validate(stack, Validators.builder()\n    .addDeploymentSpec(deploymentSpec -\u003e Stream.of(ValidationError.of(\"some-error-code\", deploymentSpec)))\n    .build());\n```\n\nIf you rather want to start from a predefined preset and extend it with additional validators, use this:\n\n```\nValidators.from(Validators.recommended())\n    .withDeploymentSpec(deploymentSpec -\u003e Stream.of(ValidationError.of(\"some-error-code\", deploymentSpec)));\n```\n\n#### Validation Errors \u0026 Presets\n\n| ID                                         | Resource   | Presets          | Description                              | Fix                                             |\n|--------------------------------------------|------------|------------------|------------------------------------------|-------------------------------------------------|\n| urn:kdk:error:secret:missing-metadata      | Secret     | all, recommended | Resource is missing the 'metadata' field | Add a 'metadata' field                          |\n| urn:kdk:error:ingress:missing-metadata     | Ingress    | all, recommended | Resource is missing the 'metadata' field | Add a 'metadata' field                          |\n| urn:kdk:error:service:missing-metadata     | Service    | all, recommended | Resource is missing the 'metadata' field | Add a 'metadata' field                          |\n| urn:kdk:error:deployment:missing-metadata  | Deployment | all, recommended | Resource is missing the 'metadata' field | Add a 'metadata' field                          |\n| urn:kdk:error:job:missing-metadata         | Job        | all, recommended | Resource is missing the 'metadata' field | Add a 'metadata' field                          |\n| urn:kdk:error:annotation:key-blank         | Annotation | all, recommended | The 'key' field is blank                 | Change the 'key' field to something non-blank   |\n| urn:kdk:error:annotation:value-blank       | Annotation | all, recommended | The 'value' field is blank               | Change the 'value' field to something non-blank |\n| urn:kdk:error:objectMeta:name-missing      | ObjectMeta | all, recommended | The 'name' field is not set              | Add a 'name' field                              |\n| urn:kdk:error:objectMeta:namespace-missing | ObjectMeta | all              | The 'namespace' field is not set         | Add a 'namespace' field                         |\n\n### Serialize\n\nIn order to serialize your construct to YAML, use the `Serialize` class.\n\n```\nvar yaml = Serialize.asYaml(stack);\n```\n\nUse the generated YAML string and write it into a file or just output it to the console.\n\n## Integration\n\nThere are several approaches to integrate `kdk` in your project.\n\n### Static-Void-Main-Approach\n\nJava applications can be started with `java \u003cyour.main.Class\u003e`. The specified class has to declare a static method that returns noting (`void`), is called `main`, and accepts an array of strings as its input. The following code shows an example:\n\n```java\npackage com.example;\n\nimport wtf.metio.kdk.construct.config.*;\nimport wtf.metio.kdk.construct.meta.*;\nimport wtf.metio.kdk.construct.service.*;\nimport wtf.metio.kdk.construct.workloads.*;\nimport wtf.metio.kdk.serialize.*;\nimport wtf.metio.kdk.stack.*;\nimport wtf.metio.kdk.validate.*;\n\npublic class ExampleApplication {\n\n    public static void main(String[] arguments) {\n        var name = \"test\";\n        var host = \"example.tld\";\n        var path = \"/service\";\n        var port = ServicePort.of(2002);\n        var label = Label.of(\"app\", name);\n\n        var metadata = ObjectMeta.builder()\n          .name(name)\n          .namespace(\"example\")\n          .addLabels(label)\n          .build();\n        var service = Service.of(\n          metadata,\n          ServiceSpec.of(port, Selector.of(label)));\n        var ingress = Ingress.of(\n          metadata,\n          IngressSpec.builder()\n              .addRules(IngressRule.of(host, HTTPIngressRuleValue.builder()\n                  .addPaths(HTTPIngressPath.of(IngressBackend.of(name, port), path))\n                  .build()))\n              .addTls(IngressTLS.of(\"tls-secret\", host))\n              .build());\n\n        var stack = Stack.builder()\n            .addService(service)\n            .addIngress(ingress)\n            .build();\n\n        var errors = Validate.validate(stack);\n\n        if (errors.isEmpty()) {\n            var yaml = Serialize.asYaml(stack);\n            System.out.print(yaml);\n        }\n    }\n\n}\n```\n\n### JShell-Approach\n\n[JShell](https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm) provides a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) for interactive Java development.\n\nYou will need both `kdk` and `snakeyml` (for serialization) on your classpath. You can use the [`jshell` artifact](https://codeberg.org/attachments/a8c30837-4afb-4cde-a5e0-c2bfca914782) which already includes all required files, and a bootstrap file to set up the classpath and load all `kdk` classes. Its [README](./kdk-construct/src/main/jshell/README.md) file explains how to start a new `jshell` session with `kdk`.\n\n## License\n\nTo the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.\nThis software is distributed without any warranty.\n\nYou should have received a copy of the CC0 Public Domain Dedication along with this software.\nIf not, see http://creativecommons.org/publicdomain/zero/1.0/.\n\n## Mirrors\n\n`kdk` is mirrored across several git repositories.\nUse any of the following to get a copy of the source.\n\n- https://codeberg.org/metio.wtf/kdk\n- https://github.com/metio/kdk (master only)\n- https://gitlab.com/metio.wtf/kdk (master only)\n- https://bitbucket.org/metio-wtf/kdk (master only)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetio%2Fkdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetio%2Fkdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetio%2Fkdk/lists"}