{"id":13646965,"url":"https://github.com/ksonnet/ksonnet-lib","last_synced_at":"2025-04-21T21:32:14.194Z","repository":{"id":57481009,"uuid":"82740765","full_name":"ksonnet/ksonnet-lib","owner":"ksonnet","description":"Codegen for Kubernetes-API-compatible Jsonnet libraries","archived":true,"fork":false,"pushed_at":"2020-02-12T20:45:50.000Z","size":2539,"stargazers_count":444,"open_issues_count":22,"forks_count":83,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-06-18T04:38:27.720Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://ksonnet.io","language":"Jsonnet","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/ksonnet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-22T00:12:14.000Z","updated_at":"2024-06-18T04:38:27.721Z","dependencies_parsed_at":"2022-09-26T17:41:25.322Z","dependency_job_id":null,"html_url":"https://github.com/ksonnet/ksonnet-lib","commit_stats":null,"previous_names":["heptio/kube.libsonnet"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksonnet%2Fksonnet-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksonnet%2Fksonnet-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksonnet%2Fksonnet-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksonnet%2Fksonnet-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksonnet","download_url":"https://codeload.github.com/ksonnet/ksonnet-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223880367,"owners_count":17219107,"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":[],"created_at":"2024-08-02T01:03:16.915Z","updated_at":"2024-11-09T20:30:52.174Z","avatar_url":"https://github.com/ksonnet.png","language":"Jsonnet","funding_links":[],"categories":["YAML/JSON Config","Configuration \u0026 Policy Automation","Jsonnet"],"sub_categories":["[Jenkins](#jenkins)"],"readme":"# ksonnet: Simplify working with Kubernetes\n\n**ksonnet** (currently in beta testing) provides a simpler alternative\nto writing complex YAML for your Kubernetes configurations. Instead,\nyou write template functions against the [Kubernetes application\nAPI][v1] using the data templating language [Jsonnet][jsonnet] .\nComponents called **mixins** also help simplify the work that's\nrequired to extend your configuration as your application scales up.\n\n![Jsonnet syntax highlighting][jsonnet-demo]\n\nOther projects help simplify the work of writing a Kubernetes\nconfiguration by creating a simpler API that wraps the Kubernetes\nAPI. These projects include [Kompose][Kompose],\n[OpenCompose][OpenCompose], and [compose2kube][compose2kube].\n\n**ksonnet** instead streamlines the process of writing\nconfigurations that create native Kubernetes objects.\n\n## Install\n\nFirst, install Jsonnet.\n\n### Mac OS X\n\nIf you do not have Homebrew installed, [install it now](https://brew.sh/).\n\nThen run:\n\n`brew install jsonnet`\n\n### Linux\n\nYou must build the binary. For details, [see the GitHub\nrepository](https://github.com/google/jsonnet).\n\n## Run\n\nFork or clone this repository, using a command such as:\n\n```shell\ngit clone git@github.com:ksonnet/ksonnet-lib.git\n```\n\nThen add the appropriate import\nstatements for the library to your Jsonnet code:\n\n```jsonnet\nlocal k = import \"ksonnet.beta.2/k.libsonnet\";\n```\n\nJsonnet `import` statements look along a \"search path\" specified using\n`jsonnet -J \u003cpath\u003e`.  To use **ksonnet**, the search path should\ninclude the root of the `ksonnet-lib` git repository.  You should add\nadditional `-J` paths as you build up your own local libraries.\n\nJsonnet does not yet support [ES2016-style](https://github.com/google/jsonnet/issues/307) imports, \nso it is common to \"unpack\" an import with a series of `local` definitions:\n\n```jsonnet\nlocal container = k.core.v1.container;\nlocal deployment = k.extensions.v1beta1.deployment;\n```\n\n### Tools\n\nDeveloped in tandem with `ksonnet-lib` is\n[`vscode-jsonnet`](https://github.com/heptio/vscode-jsonnet), a static\nanalysis toolset written as a [Visual Studio\nCode](https://code.visualstudio.com/) plugin, meant to provide\nfeatures such as autocomplete, syntax highlighting, and static\nanalysis.\n\n### Get started\n\nIf you're not familiar with **Jsonnet**, check out the\n[website](http://jsonnet.org/index.html) and [their\ntutorial](http://jsonnet.org/docs/tutorial.html). For usage, see the [command\nline tool](http://jsonnet.org/implementation/commandline.html).\n\nYou can also start writing `.libsonnet` or `.jsonnet` files based on\nthe examples in this readme. Then run the\nfollowing command:\n\n```bash\njsonnet -J /path/to/ksonnet-lib \u003cfilename.libsonnet\u003e\n```\n\nThis command produces a JSON file that you can then run the\nappropriate `kubectl`\ncommands against, with the following syntax:\n\n```bash\nkubectl \u003ccommand\u003e -\u003coptions\u003e \u003cfilename.json\u003e\n```\n\n## Write your config files with ksonnet\n\nThe YAML for the Kubernetes\n[nginx hello world tutorial][helloworld] looks\nlike this:\n\n```yaml\napiVersion: extensions/v1beta1\nkind: Deployment\nmetadata:\n  name: nginx-deployment\nspec:\n  replicas: 2\n  template:\n    metadata:\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: nginx:1.7.9\n        ports:\n        - containerPort: 80\n```\n\nInstead, you can write the following **ksonnet** code:\n\n```javascript\nlocal k = import \"ksonnet.beta.2/k.libsonnet\";\n\n// Specify the import objects that we need\nlocal container = k.extensions.v1beta1.deployment.mixin.spec.template.spec.containersType;\nlocal containerPort = container.portsType;\nlocal deployment = k.extensions.v1beta1.deployment;\n\nlocal targetPort = 80;\nlocal podLabels = {app: \"nginx\"};\n\nlocal nginxContainer =\n  container.new(\"nginx\", \"nginx:1.7.9\") +\n  container.ports(containerPort.containerPort(targetPort));\n\nlocal nginxDeployment =\n  deployment.new(\"nginx-deployment\", 2, nginxContainer, podLabels);\n\nk.core.v1.list.new(nginxDeployment)\n```\n\nSave the file as `helloworld.libsonnet`, then run:\n\n```bash\njsonnet -J \u003c/path/to/ksonnet-lib\u003e helloworld.libsonnet \u003e deployment.json\n```\n\nThis command creates the `deployment.json` file that the\n**ksonnet** snippet defines.\n\nYou can now apply this deployment to your Kubernetes cluster\nby running the following command:\n\n```bash\nkubectl apply -f deployment.json\n```\n\n## The **ksonnet** libraries\n\nThe **ksonnet** project organizes libraries by the level of\nabstraction they approach. For most users, the right entry point is:\n\n* `ksonnet.beta.2/k.libsonnet`: higher-level abstractions and methods\n  to help create complex Kubernetes objects out of smaller objects\n\n`k.libsonnet` is built on top of a utility library, `k8s.libsonnet`, \nthat is generated directly from the OpenAPI definition.\n\n## Mixins\n\nMixins are a core feature of **ksonnet**. Conceptually, they provide dynamic inheritance, at \nruntime instead of compile time, which lets you combine them freely to modify objects or \ncreate new ones.\n\n**ksonnet** ships with a large library of built-in mixins, or you can write your own custom mixins. \nThe [tutorial](/docs/TUTORIAL.md) shows you how to create a custom mixin that you can then \neasily add as a Sidecar container to your Kubernetes cluster.\n\n## Contributing\n\nThanks for taking the time to join our community and start\ncontributing!\n\n### Before you start\n\n* Please familiarize yourself with the [Code of\nConduct](https://github.com/ksonnet/ksonnet-lib/blob/master/CODE-OF-CONDUCT.md) before contributing.\n* See [CONTRIBUTING.md](https://github.com/ksonnet/ksonnet-lib/blob/master/CONTRIBUTING.md) for instructions on the\ndeveloper certificate of origin that we require.\n\n### Pull requests\n\n* We welcome pull requests. Feel free to dig through the\n[issues](https://github.com/ksonnet/ksonnet-lib/issues) and jump in.\n\n## Contact us\n\nHave any questions or long-form feedback? You can always find us here:\n\n* Our [Slack channel](https://ksonnet.slack.com) [working having an auto-invite system!)\n* Our [mailing list](https://groups.google.com/forum/#!forum/ksonnet).\n* We monitor the [ksonnet\ntag](https://stackoverflow.com/questions/tagged/ksonnet) on Stack\nOverflow.\n\n[jsonnet]: http://jsonnet.org/ \"Jsonnet\"\n[v1]: https://kubernetes.io/docs/api-reference/v1/definitions/ \"V1 API objects\"\n[v1Container]: https://kubernetes.io/docs/api-reference/v1/definitions/#_v1_container \"v1.Container\"\n[Kompose]: https://github.com/kubernetes-incubator/kompose \"Kompose\"\n[OpenCompose]: https://github.com/redhat-developer/opencompose \"OpenCompose\"\n[compose2kube]: https://github.com/kelseyhightower/compose2kube \"compose2kube\"\n\n[helloworld]: https://kubernetes.io/docs/tutorials/stateless-application/run-stateless-application-deployment/ \"Hello, Kubernetes!\"\n[v1hellojsonnet]: https://github.com/ksonnet/ksonnet-lib/blob/master/examples/hello-world/hello.v1.jsonnet \"Hello, Jsonnet (v1)!\"\n[v2hellojsonnet]: https://github.com/ksonnet/ksonnet-lib/blob/master/examples/hello-world/hello.v2.jsonnet \"Hello, Jsonnet (v2)!\"\n[deploymentspec]: https://kubernetes.io/docs/api-reference/extensions/v1beta1/definitions/#_v1beta1_deploymentspec \"v1.DeploymentSpec\"\n\n[jsonnet-demo]: docs/images/kube-demo.gif\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksonnet%2Fksonnet-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksonnet%2Fksonnet-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksonnet%2Fksonnet-lib/lists"}