These are the example files for my presentation about GitLab + Kubernetes for Continuous Integration and Delivery. They are also partly used in my GitLab CI posts.
INFO This isn't the best way to deploy application Docker images to K8s, this is more of an example how simple it can be.
The presentation can be found here: Kubernetes - WYNTK - GitLab CI + Kubernetes Presentation. The blog post these files are specifically used in is here: GitLab + Kubernetes: Perfect Match for Continuous Delivery with Container.
An uptodate list of all my blog posts around GitLab and Kubernetes can be found on this page. This list is just an excerpt of some of my GitLab posts:
- GitLab + Kubernetes: Using GitLab CI's Kubernetes Cluster feature
- GitLab + Kubernetes: Perfect Match for Continuous Delivery with Container
- Kubernetes - WYNTK - GitLab CI + Kubernetes Presentation
- GitLab + Kubernetes: Running CI Runners in Kubernetes
- GitLab + Kubernetes: GitLab on top of Kubernetes
- GitLab: Use Keycloak as SAML 2.0 OmniAuth Provider
Table of Contents
- Using this repository
- GitLab Docs References
- File Structure
This repository shows off/uses the following GitLab CI features:
- GitLab CI
- GitLab Container Registry
- GitLab CI Kubernetes Cluster Integration
Other features also shown are:
- coreos/prometheus-operator ServiceMonitor - for automatic monitoring of deployed applications.
The following points are required for this repository to work correctly:
- GitLab (>=
10.4) with the following features configured:
- Kubernetes cluster
- You need to be "bound" to the
cluster-admin) ClusterRole, see Kubernetes.io Using RBAC Authorization - User-facing Roles.
- An Ingress controller should already been deployed, see Kubernetes.io Ingress.
- You need to be "bound" to the
- Editor of your choice.
Using this repository
You have to replace the following addresses in all files:
gitlab.zerbytes.netwith your GitLab address (e.g.
registry.zerbytes.netwith your Docker registry address (e.g.
edenmal.net(in the Ingress manifest) with your domain name.
- You probably also want to change the subdomain name while you are at it.
presentation-gitlab-k8swith the Namespace name of your choice.
If you are using coreos/prometheus-operator, then you also need to replace
zerbytes-live-proj-monitoring with the Namespace your Prometheus instance is running in,
in this file
You then also want to
kubectl create/apply the file to your Kubernetes cluster during creation/apply process for the manifests in
You also need to create a "Docker Login" Secret which contains your GitLab Registry access data (e.g. Username and Access token with registry access) named
regsecret in the Namespace
A guide for that can be found here: Kubernetes.io - Pull an Image from a Private Registry.
The Namespace manifest is in the
Then you can just import the repository into your GitLab instance and are ready to go.
For information on how to use these files and setup GitLab Kubernetes cluster/integration, see the above blog post and in specific this post GitLab + Kubernetes: Perfect Match for Continuous Delivery with Container.
GitLab Docs References
- GitLab Kubernetes Integration Docs: https://docs.gitlab.com/ce/user/project/integrations/kubernetes.html
- GitLab Kubernetes Integration Docs Environment variables: https://docs.gitlab.com/ce/user/project/integrations/kubernetes.html#deployment-variables
As of GitLab
10.3 the Kubernetes Integration is marked as deprecated and with
10.4 it is now disabled, the following docs show the new feature called Clusters:
- GitLab 10.3 release - Kubernetes integration service: https://about.gitlab.com/2017/12/22/gitlab-10-3-released/#kubernetes-integration-service
- GitLab Clusters Feature Docs: https://docs.gitlab.com/ce/user/project/clusters/index.html
main.go- The Golang example application code.
vendor/- Contains the Golang example application dependencies (
Kubernetes Base GitLab CI Manifests
service-monitor.yaml- Contains a coreos/prometheus-operator ServiceMonitor manifest to automatically monitor the application(s).
namespace.yaml- Namespace in which the GitLab CI will deploy the application.
rbac.yaml- Contains GitLab CI RBAC Role, RoleBinding and ServiceAccount.
secret.yaml- Contains a TLS wildcard certificate for the application Ingress.
Dockerfile- Contains the Docker image build instructions.
.gitlab-ci.yml- Contains the GitLab CI instructions.
manifests/- Kubernetes manifests used to deploy the Docker image built in the CI pipeline.
Thanks to @shadycuz - GitHub for his comments with improvements for the code in this repository!
The files in this repo can be used under the MIT license, see LICENSE file.