[Infrastructure as Code (IaC) Pulumi] Use Pulumi kubernetes (K8S) Helm Chart to deploy GitLabRunner
GitLab Runner
GitLab Runner is an application that works with GitLab CI/CD to run jobs in a pipeline.
This article is about how to use Pulumi, kubernetes (K8S) provider, Helm Chart and TypeScript SDK to deploy GitLab Runner within Kubernetes (K8S).
Prerequisites
-
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
See Getting started | Kubernetes - https://kubernetes.io/docs/setup/ to leanr more.
-
Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
Pulumi is a modern infrastructure-as-code platform that allows you to use common programming languages, tools, and frameworks, to provision, update, and manage cloud infrastructure resources.
Install the Pulumi - https://www.pulumi.com/ CLI.
1
2Mac OS X
brew install pulumiSee Download and Install | Pulumi - https://www.pulumi.com/docs/get-started/install/ to learn more about others OS.
-
Node.js - https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Install Node.js - https://nodejs.org/en/ CLI.
1
2Mac OS X
brew install nodeSee Node.js - https://nodejs.org/en/ to learn more about others OS.
-
[Iterate faster, innovate together | GitLab - https://about.gitlab.com/]
Your GitLab server’s API is reachable from the cluster.
Before registering a runner, you need to first:
Install it on a server separate than where GitLab is installed
Obtain a token:
-
For a shared runner, have an administrator go to the GitLab Admin Area and click
Overview
>Runners
-
For a group runner, go to
Settings
>CI/CD
and expand the Runners section -
For a project-specific runner, go to
Settings
>CI/CD
and expand the Runners section
-
Usage
Pulumi New
Create the workspace directory.
1 | mkdir -p col-example-pulumi-typescript-gitlab-runner |
Pulumi login into local file system.
1 | pulumi login file://. |
Pulumi new a project with kubernetes-typescript SDK.
1 | pulumi new kubernetes-typescript |
The above command will create some files within the current directory.
1 | tree . -L 1 |
Install js-yaml
package to load and parse yaml file.
1 | npm i js-yaml |
Pulumi Configuration
Configure Kubernetes
By default, Pulumi will look for a kubeconfig file in the following locations, just like kubectl:
-
The environment variable:
$KUBECONFIG
, -
Or in current user’s default kubeconfig directory:
~/.kube/config
If the kubeconfig file is not in either of these locations, Pulumi will not find it, and it will fail to authenticate against the cluster. Set one of these locations to a valid kubeconfig file, if you have not done so already.
Configure Values.yaml
Edit values.yaml and replace content within {{ }}
.
1 | # values.yaml · master · GitLab.org / charts / GitLab Runner · GitLab |
See and modify main.ts file.
1 | // main.ts |
Pulumi Up
Run pulumi up to create the namespace and pods.
1 | pulumi up |
See pods about gitlab-runner.
1 | kubectl get pods -n gitlab-runner |
Pulumi Destroy
Destroy all resources created by Pulumi.
1 | pulumi destroy |
FAQs
“system:serviceaccount:gitlab-runner:default” cannot get resource “deployments” in API group “apps” in the namespace “gitlab-runner”
1 | Error from server (Forbidden): error when retrieving current configuration of: |
Use ServiceAccount gitlab-runner-gitlab-runner
to solve that issue.
1 | # values.yaml · master · GitLab.org / charts / GitLab Runner · GitLab |
References
[1] GitLab Runner Helm Chart | GitLab - https://docs.gitlab.com/runner/install/kubernetes.html
[4] GitLab Runner | GitLab - https://docs.gitlab.com/runner/
[5] Kubernetes Getting Started | Pulumi - https://www.pulumi.com/docs/get-started/kubernetes/
[6] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
[7] Kubernetes - https://kubernetes.io/
[8] TypeScript: Typed JavaScript at Any Scale. - https://www.typescriptlang.org/