{"id":19282361,"url":"https://github.com/vaslabs/sbt-kubeyml","last_synced_at":"2025-04-22T01:31:33.949Z","repository":{"id":35544900,"uuid":"215316605","full_name":"vaslabs/sbt-kubeyml","owner":"vaslabs","description":"Sbt plugin to help deploy Scala applications to Kubernetes","archived":false,"fork":false,"pushed_at":"2025-04-11T07:53:54.000Z","size":2451,"stargazers_count":38,"open_issues_count":12,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T09:55:05.205Z","etag":null,"topics":["akka-cluster","docker","gitlab-ci","ingress","kubernetes","kubernetes-deployment","kubernetes-ingress","kubernetes-manifests","kubernetes-service","sbt","sbt-kubeyml","sbt-plugin","scala","typesafety"],"latest_commit_sha":null,"homepage":"http://sbt-kubeyml.vaslabs.org","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vaslabs.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":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"ko_fi":"vaslabs"}},"created_at":"2019-10-15T14:15:22.000Z","updated_at":"2025-04-11T07:53:58.000Z","dependencies_parsed_at":"2023-12-13T17:58:34.088Z","dependency_job_id":"693880ab-ed94-483d-91f9-83c98ef616f1","html_url":"https://github.com/vaslabs/sbt-kubeyml","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaslabs%2Fsbt-kubeyml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaslabs%2Fsbt-kubeyml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaslabs%2Fsbt-kubeyml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaslabs%2Fsbt-kubeyml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaslabs","download_url":"https://codeload.github.com/vaslabs/sbt-kubeyml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250162034,"owners_count":21385030,"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":["akka-cluster","docker","gitlab-ci","ingress","kubernetes","kubernetes-deployment","kubernetes-ingress","kubernetes-manifests","kubernetes-service","sbt","sbt-kubeyml","sbt-plugin","scala","typesafety"],"created_at":"2024-11-09T21:26:33.329Z","updated_at":"2025-04-22T01:31:33.619Z","avatar_url":"https://github.com/vaslabs.png","language":"Scala","funding_links":["https://ko-fi.com/vaslabs"],"categories":[],"sub_categories":[],"readme":"\n# sbt-kubeyml \n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1a2b9682f101488cb8bf5589e5bd7310)](https://www.codacy.com/manual/vaslabs/sbt-kubeyml?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=vaslabs/sbt-kubeyml\u0026amp;utm_campaign=Badge_Grade) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.vaslabs.kube/sbt-kubeyml/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.vaslabs.kube/sbt-kubeyml) [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat\u0026logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)\n\n![Sbt kubeyml logo](https://raw.githubusercontent.com/vaslabs/sbt-kubeyml/master/site/src/main/resources/microsite/img/navbar_brand.png) \n\nAn sbt plugin to generate typesafe kubernetes deployment plans for scala projects\n\n## Deployment plugin\n\n### Add the plugin to your plugins.sbt\n```\naddSbtPlugin(\"org.vaslabs.kube\" % \"sbt-kubeyml\" % \"0.4.1\")\n```\n\nAdd the plugin in your project and enable it\n```\nenablePlugins(KubeDeploymentPlugin)\n```\nThe plugin depends on DockerPlugin from [sbt-native-packager](https://github.com/sbt/sbt-native-packager)\n\n```\nenablePlugins(DockerPlugin)\n```\n\nTry to run\n\n```\nkubeyml:gen\n```\n\n\n### Properties\n\n| **sbt key**       | **description**                                                                      | **default**                                                                              | \n|-------------------|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|\n| namespace         | The kubernetes namespace of the deployment                                           | Default value is project name                                                            | \n| application       | The name of the deployment                                                           | Default value is project name                                                            |\n| dockerImage       | The docker image to deploy in a single container                                     | Default is the picked from sbt-native-packager                                           |\n| ports             | List of container ports optionally tagged with name                                  | dockerExposedPorts from docker plugin                                                    |\n| livenessProbe     | Healthcheck probe                                                                    | `HttpProbe(HttpGet(\"/health\", 8080, List.empty), 0 seconds, 1 second, 10 seconds, 3, 1)` |\n| readinessProbe    | Probe to check when deployment is ready to receive traffic                           | livenessProbe                                                                            |\n| annotations       | `Map[String, String]` for spec template annotations (e.g. aws roles)                 | empty                                                                                    |\n| replicas          | the number of replicas to be deployed                                                | 2                                                                                        |\n| imagePullPolicy   | Image pull policy for kubernetes, set to IfNotPresent or Always                      | IfNotPresent                                                                             |\n| command           | Command for the container                                                            | empty                                                                                    |\n| args              | arguments for the command                                                            | empty Seq                                                                                |\n| envs              | Map of environment variables, raw, field path or secret are supported                | empty                                                                                    |\n| resourceRequests  | Resource requests (cpu in the form of m, memory in the form of MiB                   | `Resource(Cpu(100), Memory(256))`                                                        |\n| resourceLimits    | Resource limits (cpu in the form of m, memory in the form of MiB                     | `Resource(Cpu(1000), Memory(512))`                                                       |\n| target            | The directory to output the deployment.yml                                           | target in ThisProject / kubeyml                                                          |\n| deployment        | The key to access the whole Deployment definition, exposed for further customisation | Instance with above defaults                                                             |\n| persistentVolumes | Persistent volumes that should be used by deployment pods                            | empty Seq                                                                                |\n\n### Recipes\n\n#### Single namespace, two types of deployments with secret and dependency\n\n```scala\nimport kubeyml.deployment._\nimport kubeyml.deployment.api._\nimport kubeyml.deployment.plugin.Keys._\n\nlazy val deploymentName = sys.env.getOrElse(\"DEPLOYMENT_NAME\", \"myservice-test\")\nlazy val secretsName = sys.env.getOrElse(\"SECRETS_NAME\", \"myservice-test-secrets\")\nlazy val serviceDependencyConnection = sys.env.getOrElse(\"MY_DEPENDENCY\", \"https://localhost:8080\")\n\nlazy val deploymentSettings = Seq(\n  kube / namespace := \"my-namespace\", //default is ThisProject / name \n  kube / application := deploymentName, //default is ThisProject / name\n  kube / command := Some(\"webserver\"),\n  kube / args := Seq(\"-c\",\"/path/to/config\"),\n  kube / envs := Map(\n    EnvName(\"JAVA_OPTS\") -\u003e EnvRawValue(\"-Xms256M -Xmx2048M\"),\n    EnvName(\"MY_DEPENDENCY_SERVICE\") -\u003e EnvRawValue(serviceDependencyConnection),\n    EnvName(\"MY_SECRET_TOKEN\") -\u003e EnvSecretValue(name = secretsName, key = \"my-token\")\n  ),\n  kube / resourceLimits := Resource(Cpu.fromCores(2), Memory(2048+512)),\n  kube / resourceRequests := Resource(Cpu(500), Memory(512)),\n  //if you want you can use something like the below to modify any part of the deployment by hand\n  kube / deployment := (kube / deployment).value.pullDockerImage(IfNotPresent)\n)\n```\n\n#### Gitlab CI/CD usage (followup from previous)\n\n```yaml\nstages:\n  - publish-image\n  - deploy\n\n.publish-template:\n  stage: publish-image\n  script:\n      - sbt docker:publish\n      - sbt kubeyml:gen\n  artifacts:\n      untracked: false\n      paths:\n        - target/kubeyml/deployment.yml\n\n.deploy-template:\n  stage: deploy\n  image: docker-image-that-has-your-kubectl-config\n  script:\n     - kubectl apply -f target/kubeyml/deployment.yml\n\npublish-test:\n  before_script:\n      export MY_DEPENDENCY=${MY_TEST_DEPENDENCY}\n  extends: .publish-template\n\ndeploy-test:\n  extends: .deploy-template\n  dependencies:\n     - publish-test\n\npublish-prod:\n  before_script:\n    - export MY_DEPENDENCY=${MY_PROD_DEPENDENCY}\n    - export SECRETS_NAME=${MY_PROD_SECRET_NAME}\n    - export DEPLOYMENT_NAME=my-service-prod\n  extends: .publish-template\n\ndeploy-prod:\n  extends: .deploy-template\n  dependencies:\n   - publish-prod\n```\n\n## Service plugin\n\nThis plugin depends on the deployment plugin and every property is derived from that.\n\nThere's some room for customisation.\n\n```\nenablePlugins(KubeServicePlugin)\n```\n\nThen your gitlab publish template will look like (example extended from above)\n\n```yaml\n.publish-template:\n  stage: publish-image\n  script:\n      - sbt docker:publish\n      - sbt kubeyml:gen\n  artifacts:\n      untracked: false\n      paths:\n        - target/kubeyml/deployment.yml\n        - target/kubeyml/service.yml\n```\nAnd deploy with\n```yaml\n.deploy-template:\n  stage: deploy\n  image: docker-image-that-has-your-kubectl-config\n  script:\n     - kubectl apply -f target/kubeyml/deployment.yml     \n     - kubectl apply -f target/kubeyml/service.yml\n```\n\n### Properties\n\n| **sbt key**  | **description**  | **default**  |\n|---|---|---|\n| portMappings  | Port mappings against the deployment (service to pod)   |  Derived from deployment |\n| service  | Key configuration for modifying the service properties   |  Derived from deployment |\n\n\n## Ingress Plugin\n\nThis plugin depends on the service plugin. It provides some safety nets to make sure the service name and service ports\nare mapped properly to the ingress configuration.\n\nTo extend on the above, you can configure ingress generation with the following steps.\n\n1. Enable the plugin\n```sbt\nenablePlugins(KubeIngressPlugin)\n```\n\n2. Set an ingress name and a hostname\n\n```scala\nlazy val ingressEnvName = sys.env.getOrElse(\"HELLO_INGRESS_NAME\", \"helloworld-ingress-test\")\n\nlazy val hostName = sys.env.getOrElse(\"YOUR_HOST_NAME\", \"your-hostname.yourdomain.smth\")\n```\n\n3. Configure the plugin\n\n```scala\n  import kubeyml.protocol.{NonEmptyString, Host}\n  import kubeyml.deployment.plugin.Keys._\n  import kubeyml.ingress.api._\n\n  import kubeyml.ingress.plugin.Keys._\n  import kubeyml.service.plugin.Keys._\n  import kubeyml.ingress.{HttpRule, ServiceMapping, Path =\u003e IngressPath}\n  \n  val ingressSettings = Seq(\n      (kube / ingressName) := ingressEnvName,\n      (kube / ingressRules) := List(\n        HttpRule(Host(hostName), List(\n          IngressPath(ServiceMapping((kube / service).value.name, 8085), \"/hello-world\")\n        ))\n      ),\n      (kube / ingressAnnotations) := Map(\n        Annotate.nginxIngress(), // this adds kubernetes.io/ingress.class: nginx\n        Annotate.nginxRewriteTarget(\"/hello-world\"), //this adds nginx.ingress.kubernetes.io/rewrite-target: /hello-world\n        NonEmptyString(\"your-own-annotation-key\") -\u003e \"value\"\n      )\n    )\n``` \n\nThe command to generate the ingress is the same `kubeyml:gen` which will generate 3 yml files.\n\n#### Gitlab CI extension \n\nPotentially the CI configuration evolves to\n\n```yaml\n.publish-template:\n  stage: publish-image\n  script:\n      - sbt docker:publish\n      - sbt kubeyml:gen\n  artifacts:\n      untracked: false\n      paths:\n        - target/kubeyml/deployment.yml\n        - target/kubeyml/service.yml\n        - target/kubeyml/ingress.yml\n.deploy-template:\n  stage: deploy\n  image: docker-image-that-has-your-kubectl-config\n  script:\n     - kubectl apply -f target/kubeyml/deployment.yml\n     - kubectl apply -f target/kubeyml/service.yml\n     - kubectl apply -f target/kubeyml/ingress.yml\n```\n\n### Properties\n\n| **sbt key**  | **description**  | **default**  |\n|---|---|---|\n| ingressRules  | A list of Rules (currently only supports HttpRule  |  N/A |\n| ingressName | The name of the ingress | The application name from deployment |\n| ingress  | Key configuration for modifying the ingress properties   |  Some values are derived from service |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaslabs%2Fsbt-kubeyml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaslabs%2Fsbt-kubeyml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaslabs%2Fsbt-kubeyml/lists"}