{"id":14975824,"url":"https://github.com/carvel-dev/simple-app-on-kubernetes","last_synced_at":"2025-04-06T22:12:17.222Z","repository":{"id":46182681,"uuid":"185699045","full_name":"carvel-dev/simple-app-on-kubernetes","owner":"carvel-dev","description":"K8s simple Go app example deployed with k14s tools","archived":false,"fork":false,"pushed_at":"2023-01-23T18:27:59.000Z","size":48,"stargazers_count":30,"open_issues_count":1,"forks_count":297,"subscribers_count":18,"default_branch":"develop","last_synced_at":"2025-03-30T21:09:04.013Z","etag":null,"topics":["carvel","k8s","kapp","kubernetes","yaml","ytt"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/carvel-dev.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":"SECURITY.md","support":null}},"created_at":"2019-05-09T00:39:47.000Z","updated_at":"2025-02-13T09:09:42.000Z","dependencies_parsed_at":"2023-02-13T02:01:05.341Z","dependency_job_id":null,"html_url":"https://github.com/carvel-dev/simple-app-on-kubernetes","commit_stats":null,"previous_names":["k14s/k8s-simple-app","k14s/k8s-simple-app-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvel-dev%2Fsimple-app-on-kubernetes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvel-dev%2Fsimple-app-on-kubernetes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvel-dev%2Fsimple-app-on-kubernetes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carvel-dev%2Fsimple-app-on-kubernetes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carvel-dev","download_url":"https://codeload.github.com/carvel-dev/simple-app-on-kubernetes/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557770,"owners_count":20958047,"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":["carvel","k8s","kapp","kubernetes","yaml","ytt"],"created_at":"2024-09-24T13:52:43.292Z","updated_at":"2025-04-06T22:12:17.185Z","avatar_url":"https://github.com/carvel-dev.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](logos/CarvelLogo.png)\n\n# k8s-simple-app-example\n\nExample repo shows how to use tools from carvel dev: [ytt](https://carvel.dev/ytt), [kbld](https://carvel.dev/kbld), [kapp](https://carvel.dev/kapp) and [kwt](https://github.com/vmware-tanzu/carvel-kwt) to work with a simple Go app on Kubernetes.\n\nAssociated blog post: [Deploying Kubernetes Applications with ytt, kbld, and kapp](https://carvel.dev/blog/deploying-apps-with-ytt-kbld-kapp/).\n\n## Install Carvel Tools\n\nHead over to [carvel.dev](https://carvel.dev/) for installation instructions.\n\n## Deploying Application\n\nEach top level step has an associated `config-step-*` directory. Refer to [Directory Layout](#directory-layout) for details about files.\n\n### Step 1: Deploying application\n\nIntroduces [kapp](https://carvel.dev/kapp) for deploying k8s resources.\n\n```bash\nkapp deploy -a simple-app -f config-step-1-minimal/\nkapp inspect -a simple-app --tree\nkapp logs -f -a simple-app\n```\n\n### Step 1a: Viewing application\n\nOnce deployed successfully, you can access frontend service at `127.0.0.1:8080` in your browser via `kubectl port-forward` command:\n\n```bash\nkubectl port-forward svc/simple-app 8080:80\n```\n\nYou will have to restart port forward command after making any changes as pods are recreated. Alternatively consider using [kwt](https://github.com/vmware-tanzu/carvel-kwt) which exposes cluser IP subnets and cluster DNS to your machine and does not require any restarts:\n\n```bash\nsudo -E kwt net start\n```\n\nand open [`http://simple-app.default.svc.cluster.local/`](http://simple-app.default.svc.cluster.local/).\n\n### Step 1b: Modifying application configuration\n\nModify `HELLO_MSG` environment value from `stranger` to something else in `config-step-1-minimal/config.yml`, and run:\n\n```bash\nkapp deploy -a simple-app -f config-step-1-minimal/ --diff-changes\n```\n\nIn following steps we'll use `-c` shorthand for `--diff-changes`.\n\n### Step 2: Configuration templating\n\nIntroduces [ytt](https://carvel.dev/ytt) templating for more flexible configuration.\n\n```bash\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-2-template/)\n```\n\nytt provides a way to configure data values from command line as well:\n\n```bash\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-2-template/ -v hello_msg=another-stranger)\n```\n\nNew message should be returned from the app in the browser.\n\n### Step 2a: Configuration patching\n\nIntroduces [ytt overlays](https://carvel.dev/ytt/docs/latest/lang-ref-ytt-overlay/) to patch configuration without modifying original `config.yml`.\n\n```bash\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-2-template/ -f config-step-2a-overlays/custom-scale.yml)\n```\n\n### Step 2b: Customizing configuration data values per environment\n\nRequires ytt v0.13.0+.\n\nIntroduces [use of multiple data values](https://carvel.dev/ytt/docs/latest/ytt-data-values/) to show layering of configuration for different environment without modifying default `values.yml`.\n\n```bash\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-2-template/ -f config-step-2b-multiple-data-values/)\n```\n\n### Step 3: Building container images locally\n\nIntroduces [kbld](https://carvel.dev/kbld) functionality for building images from source code. This step requires Minikube. If Minikube is not available, skip to the next step.\n\n```bash\neval $(minikube docker-env)\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-3-build-local/ | kbld -f-)\n```\n\nNote that rerunning above command again should be a noop, given that nothing has changed.\n\n### Step 3a: Modifying application source code\n\nUncomment `fmt.Fprintf(w, \"\u003cp\u003elocal change\u003c/p\u003e\")` line in `app.go`, and re-run above command:\n\n```bash\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-3-build-local/ | kbld -f-)\n```\n\nObserve that new container was built, and deployed. This change should be returned from the app in the browser.\n\n### Step 4: Building and pushing container images to registry\n\nIntroduces [kbld](https://carvel.dev/kbld) functionality to push to remote registries. This step can work with Minikube or any remote cluster.\n\n```bash\ndocker login -u dkalinin -p ...\nkapp deploy -a simple-app -c -f \u003c(ytt -f config-step-4-build-and-push/ -v push_images_repo=gcr.io/projectX/k8s-simple-app | kbld -f-)\n```\n\n### Step 5: Clean up cluster resources\n\n```bash\nkapp delete -a simple-app\n```\n\nThere is currently no functionality in kbld to remove pushed images from registry.\n\n## Directory Layout\n\n- [`app.go`](app.go): simple Go HTTP server\n- [`Dockerfile`](Dockerfile): Dockerfile to build Go app\n- `config-step-1-minimal/`\n  - [`config.yml`](config-step-1-minimal/config.yml): basic k8s Service and Deployment configuration for the app\n- `config-step-2-template/`\n  - [`config.yml`](config-step-2-template/config.yml): slightly modified configuration to use `ytt` features, such as data module and functions\n  - [`values.yml`](config-step-2-template/values.yml): defines extracted data values used in `config.yml`\n- `config-step-2a-overlays/`\n  - [`custom-scale.yml`](config-step-2a-overlays/custom-scale.yml): ytt overlay to set number of deployment replicas to 3\n- `config-step-3-build-local/`\n  - [`build.yml`](config-step-3-build-local/build.yml): tells `kbld` about how to build container image from source (app.go + Dockerfile)\n  - [`config.yml`](config-step-3-build-local/config.yml): _same as prev step_\n  - [`values.yml`](config-step-3-build-local/values.yml): _same as prev step_\n- `config-step-4-build-and-push/`\n  - [`build.yml`](config-step-4-build-and-push/build.yml): _same as prev step_\n  - [`push.yml`](config-step-4-build-and-push/push.yml): tells `kbld` about how to push container image to remote registry\n  - [`config.yml`](config-step-4-build-and-push/config.yml): _same as prev step_\n  - [`values.yml`](config-step-4-build-and-push/values.yml): defines shared configuration, including configuration for pushing container images\n\n### Join the Community and Make Carvel Better\nCarvel is better because of our contributors and maintainers. It is because of you that we can bring great software to the community.\nPlease join us during our online community meetings. Details can be found on our [Carvel website](https://carvel.dev/community/).\n\nYou can chat with us on Kubernetes Slack in the #carvel channel and follow us on Twitter at @carvel_dev.\n\nCheck out which organizations are using and contributing to Carvel: [Adopter's list](https://github.com/vmware-tanzu/carvel/blob/master/ADOPTERS.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarvel-dev%2Fsimple-app-on-kubernetes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarvel-dev%2Fsimple-app-on-kubernetes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarvel-dev%2Fsimple-app-on-kubernetes/lists"}