This is a complete template for a golang microservice deployed on a Kubernetes cluster via gitlab-ci.
The bare docker image with an http server and ca-certificates weights < 6MB.
Quick parachute drop without cloning:
curl -L https://github.com/kypp/go-gitlab-k8s/archive/master.tar.gz | tar xz --strip-components 1
Stuff you might want to do after the drop:
- Change the go module name in app/go.mod and chart name in chart/Chart.yaml
- Ensure the
KUBE_INGRESS_BASE_DOMAIN
is set, either on a higher level (see documentation) or by uncommenting the 7th line in the.gitlab-ci.yml
file - Create the GitLab project
- In
Settings->Repository->Deploy Tokens
create a token namedgitlab-deploy-token
withread_registry
scope (see here for explanation) - Push to GitLab
Includes:
- two-stage production Dockerfile for optimal image size
- docker-compose for development with live reload (for local development simply
docker-compose up
) - automated kubernetes deployment based on GitLab autodevops
- basic health check endpoint (at /healthz)
Credits:
- Gitlab CI/CD AutoDevOps: https://docs.gitlab.com/ee/topics/autodevops/
- Tips for minimal secure golang docker image: article on medium
- go-reload script: https://github.com/alexedwards/go-reload