{"id":22214002,"url":"https://github.com/xmlking/ko-demo","last_synced_at":"2025-03-25T06:24:01.243Z","repository":{"id":142313648,"uuid":"195706594","full_name":"xmlking/ko-demo","owner":"xmlking","description":"basic go project using ko for deployment , KIND as Kubernetes runtime ","archived":false,"fork":false,"pushed_at":"2019-07-16T21:54:52.000Z","size":3618,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T20:22:13.814Z","etag":null,"topics":["docker","gcloud","gcr","go-modules","golang","hello-world","ko"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xmlking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-07-07T23:30:01.000Z","updated_at":"2019-08-29T02:18:03.000Z","dependencies_parsed_at":"2024-02-15T05:43:33.983Z","dependency_job_id":null,"html_url":"https://github.com/xmlking/ko-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlking%2Fko-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlking%2Fko-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlking%2Fko-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xmlking%2Fko-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xmlking","download_url":"https://codeload.github.com/xmlking/ko-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245409568,"owners_count":20610554,"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":["docker","gcloud","gcr","go-modules","golang","hello-world","ko"],"created_at":"2024-12-02T21:12:54.294Z","updated_at":"2025-03-25T06:24:01.215Z","avatar_url":"https://github.com/xmlking.png","language":"Makefile","readme":"# ko-demo\n\n**ko** is a `build/publish/deploy` tool for `go` applications on `Kubernetes`\n\nIt allows you to:\n\n- build Go binaries\n- containerize them and publish to a registry\n- automatically update Kubernetes manifests to references the correct container image\n\n## Prerequisite\n\n\u003e run then outside **this project root** and `$GOPATH`\n\n```bash\n# go lang  build/publish/deploy tool\ngo get -u github.com/google/ko/cmd/ko\n```\n\n## Local\n\nYou can certainly build/run your code locally:\n\n### Run\n\n```bash\ngo run main.go\n```\n\n### Test\n\n```bash\ncurl http://localhost:8080\n```\n\n## Deploy\n\n### Configure a Registry\n\nTo specify the registry that you want to use, set the KO_DOCKER_REPO variable, for instance:\n\nto publish locally set: `export KO_DOCKER_REPO=ko.local`\n\n```bash\nexport PROJECT_ID=ngx-starter-kit\nexport KO_DOCKER_REPO=gcr.io/${PROJECT_ID}\n```\n\n### Usage\n\nWrite a Kubernetes manifest with an import path that is similar to a Go import path like:\n\n```yaml\napiVersion: apps/v1beta1\nkind: Deployment\nmetadata:\n  name: hello-world\nspec:\n---\ntemplate:\n---\nspec:\n  containers:\n    - name: hello-world\n      image: github.com/xmlking/ko-demo\n```\n\n### Deploying\n\nThen to start the build, containerize and deploy a single `ko` command is necessary.\n\n```bash\nko apply -f deploy/\n\n# -P or --preserve-import-paths\nko apply -P -f deploy/\n\n# Deploy to minikube w/o registry.\nko apply -L -f deploy/\n\n# This is the same as above.\nKO_DOCKER_REPO=ko.local ko apply -f deploy/\n```\n\nTo deploy in a different namespace:\n\n```bash\nko -n nondefault apply -f deploy/\n```\n\nYou will see a Pod running and you will be able to call your Go function:\n\n```bash\nkubectl get pods\nNAME                                            READY     STATUS      RESTARTS   AGE\nhello-world-59868cf5f9-5gqhj                    1/1       Running     0          5s\n\nkubectl port-forward pod/hello-world-59868cf5f9-5gqhj 8080:8080 \u0026\n[1] 99038\n\ncurl localhost:8080\nHandling connection for 8080\nHello world !\n```\n\n### Teardown\n\n```bash\nko delete -f deploy/\n```\n\n### Build/publish but do not deploy\n\nIf all you want to do is build the Go binary and publish an image to the registry then, with the Demo project cloned in your \\$GOPATH.\n\n```bash\nko publish github.com/xmlking/ko-demo\n# publish to local docker repo\nko resolve -L -f deploy/\n```\n\n### Release Management\n\nko is also useful to help manageing releases\n\n```bash\n# publish to  docker repo ar KO_DOCKER_REPO\nko resolve -P -f deploy/ \u003e release.yaml\n# publish to local docker repo\nko resolve -P -L -f deploy/ \u003e release.yaml\n```\n\nThis will publish all of the binary components as container images to gcr.io/xmlking/... and create a `release.yaml` file containing all of the configuration for your application with inlined image references.\n\nThis resulting configuration may then be installed onto Kubernetes clusters via:\n\n```bash\nkubectl apply -f release.yaml\n```\n\n### Run Docker\n\n```bash\ndocker run -it -p 8080:8080  ko.local/github.com/xmlking/ko-demo\n# test\ncurl http://localhost:8080\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmlking%2Fko-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxmlking%2Fko-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxmlking%2Fko-demo/lists"}