Home Build & Deploy Your Own Code in Your Homelab!
Post
Cancel

Build & Deploy Your Own Code in Your Homelab!

So you’re a software engineer or a developer who wants to self-host your own code in your own homelab? Well this is the tutorial for you! In this step-by-step guide we’ll walk through setting up a repo, building and testing our own code (with unit tests) in a self-hosted Gitlab CI runner in our CI pipeline, then we’ll build a Docker image and push it up to a container registry, then we’ll use kubectl in our CD pipeline to deploy our Docker container to our self-hosted kubernetes cluster! This all happens in a couple of minutes and then we’ll truly have continuous integration and continuous delivery in our homelab!

📺 Watch Video

Helpful videos

1 - Set Up Kubernetes with Rancher

2 - Set up a reverse proxy and SSL with Traefik

3 - Expose Rancher and Kubernetes API Securely

GitLab react app

See the app here:

https://github.com/techno-tim/techno-react

Docker file:

https://github.com/techno-tim/techno-react/blob/master/Dockerfile

Kubernetes deployment yaml

https://github.com/techno-tim/techno-react/blob/master/kubernetes/deployment.yaml

nginx config for your react application

https://github.com/techno-tim/techno-react/blob/master/nginx.conf

pbcopy for WSL on Windows

https://www.techtronic.us/pbcopy-pbpaste-for-wsl/ https://www.techtronic.us/pbcopy-pbpaste-for-wsl/

Example config.toml for your GitLab runner.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "rancher-gitlab-runner"
  url = "https://gitlab.com"
  token = "your-gitlab-runner-token"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = [\"/var/run/docker.sock:/var/run/docker.sock\", \"/cache\"]
    shm_size = 0

example ~/.kube/config for your GitLab secret

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Config
clusters:
- name: "cluster1"
  cluster:
    server: "https://your.rancher.url/k8s/clusters/c-cluster-id"
users:
- name: "cluster1"
  user:
    token: "your kubernetes token"

contexts:
- name: "cluster1"
  context:
    user: "cluster1"
    cluster: "cluster1"

current-context: "cluster1"

⚙️ See all the hardware I recommend at https://l.technotim.live/gear

🚀 Don’t forget to check out the 🚀Launchpad repo with all of the quick start source files

This post is licensed under CC BY 4.0 by the author.

SSL, Traefik, and OAuth for Rancher! (Google, GitHub, Keycloak, Azure, and more!)

Bridge Mode with UniFi Access Points