{"id":20376658,"url":"https://github.com/andrebriggs/go-docker-k8s-demo","last_synced_at":"2025-04-12T07:37:34.864Z","repository":{"id":150973735,"uuid":"166629334","full_name":"andrebriggs/go-docker-k8s-demo","owner":"andrebriggs","description":"A simple dockerized golang application with a helm chart","archived":false,"fork":false,"pushed_at":"2020-03-25T06:46:23.000Z","size":42,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-26T02:51:07.697Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/andrebriggs.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,"publiccode":null,"codemeta":null}},"created_at":"2019-01-20T06:08:54.000Z","updated_at":"2023-08-29T10:43:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"892cb244-078e-4db3-a688-d26928fff929","html_url":"https://github.com/andrebriggs/go-docker-k8s-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/andrebriggs%2Fgo-docker-k8s-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fgo-docker-k8s-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fgo-docker-k8s-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fgo-docker-k8s-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrebriggs","download_url":"https://codeload.github.com/andrebriggs/go-docker-k8s-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248536094,"owners_count":21120680,"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-11-15T01:39:01.534Z","updated_at":"2025-04-12T07:37:34.843Z","avatar_url":"https://github.com/andrebriggs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoLang App --\u003e Docker --\u003e k8s\n\nA \"hello world\" app to demonstrate simple web server. Contains a Dockerfile that is based off of instructions [here](https://medium.com/travis-on-docker/how-to-dockerize-your-go-golang-app-542af15c27a2). \n\nWe also will push the dockerized GoLang app to a Kubernetes cluster using an included yaml file.\n## Docker Pull and Run\nDocker version can be run with the commands\n```\n$ docker pull andrebriggs/goserver\n$ docker run --rm -p 8080:8080  andrebriggs/goserver\n```\n\nTest that the app is running locally by running\n```\n$ curl http://localhost:8080\n```\n\nYou should see \n```\nCongratulations! Version 1.0 of your application is running on Kubernetes.\n```\n\n## Docker Build and Push\nIf you want to roll your own image use the following commands below, otherwise skip to the next section. \n```\n$ docker run --rm -v \"$PWD\":/go/src/github.com/andrebriggs/goserver -w /go/src/github.com/andrebriggs/goserver iron/go:dev go build -o bin/myapp\n$ docker build -t andrebriggs/goserver:latest .\n```\nNote that in the first line we __build__ \"myapp\" outside of the Dockerfile. The dependency of go at __iron/go:dev__ isn't a part of the final image so we save space. Be sure to replace __andrebriggs__ with your own DockerHub account name\n\nFInally I pushed the image to DockerHub\n```\n$ docker push andrebriggs/goserver\n```\n## Kubernetes Setup\n\nOnce pushed I can declaratively set a Kubernetes environment (assuming one is created) to use this resource\n```\n$ kubectl create -f k8s\n```\nTo verify the creation with can ask kubectl to describe the service with the command\n```\n$ kubectl describe svc mywebapp\n```\nThe result will be similar to this\n```\nName:                     mywebapp\nNamespace:                default\nLabels:                   app=mywebapp\nAnnotations:              kubectl.kubernetes.io/last-applied-configuration:\n                            {\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"mywebapp\"},\"name\":\"mywebapp\",\"namespace\":\"default\"},\"spe...\nSelector:                 app=mywebapp\nType:                     LoadBalancer\nIP:                       10.0.210.108\nLoadBalancer Ingress:     137.116.69.143\nPort:                     http  8080/TCP\nTargetPort:               8080/TCP\nNodePort:                 http  31855/TCP\nEndpoints:                10.200.0.69:8080\nSession Affinity:         None\nExternal Traffic Policy:  Cluster\nEvents:\n  Type    Reason                Age    From                Message\n  ----    ------                ----   ----                -------\n  Normal  EnsuringLoadBalancer  6m2s   service-controller  Ensuring load balancer\n  Normal  EnsuredLoadBalancer   5m14s  service-controller  Ensured load balancer\n```\nMake a note of the external IP address (LoadBalancer Ingress) exposed by the service. Read more about this [here](https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/).\n\nYou should be able to access the web app \n\n```\n$ curl http://(LoadBalancer Ingress IP):8080\nCongratulations! Version 1.0 of your application is running on Kubernetes.\n```\n\n## Update the Docker image \n\nSuppose you make changes to [server.go](server.go) file to update hardcoded version to __1.2__ and want to push new changes the Docker image tag as a __v1.2__. Do the following commands\n```\n$ docker run --rm -v \"$PWD\":/go/src/github.com/andrebriggs/goserver -w /go/src/github.com/andrebriggs/goserver iron/go:dev go build -o bin/myapp\n$ docker build -t andrebriggs/goserver:v1.2 .\n$ docker tag andrebriggs/goserver:latest andrebriggs/goserver:v1.2\n$ docker push andrebriggs/goserver:v1.2\n```\n\n## Rollout a new deployment\nEdit the manifest [YAML file](k8s/mywebapp-all-in-one.yaml) to alter the .spec.containers.image to be andrebriggs/goserver:v1.2\n```\n    ...\n    spec:\n      containers:\n      - name: mywebapp\n        image: andrebriggs/goserver:v1.2\n        imagePullPolicy: IfNotPresent\n        ports:\n        - containerPort: 8080\n```\n\nAlso edit the .spec.replicas value to be 10\n\nSave then run\n\n```\n$ kubectl apply -f k8s --record\n```\n\nThen immediately run the following to check the status of the deploy\n```\nkubectl rollout status deployment mywebapp-v1\n```\nOnce done try hitting the endpoint again with curl and see your changes.\n```\nCongratulations! Version 1.2 of your application is running on Kubernetes.\n```\n\n## Helm Chart\nThere is a helm chart for this repo in the [mywebapp](mywebapp/Chart.yaml) directory. It is used in a [Fabrikate](https://github.com/Microsoft/fabrikate) definition [here](https://github.com/andrebriggs/fabrikate-go-server). \n\n## Kubernetes tear down\nRun the commands\n```\n$ kubectl delete services mywebapp\n$ kubectl delete deployment mywebapp\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrebriggs%2Fgo-docker-k8s-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrebriggs%2Fgo-docker-k8s-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrebriggs%2Fgo-docker-k8s-demo/lists"}