ci on my home
jenkins and k8s in my homelab, and why i gave up on it.
why set up an overkill architecture for a personal website?
because i don't know k8s and jenkins. haha. and i wanted to get into devops. sometimes the ci/cd is more interesting than the application you're shipping.
prerequisites
- a physical machine with at least 16gb of ram and 100gb of storage
- a domain name
vm and machine setup
i use proxmox ve to manage the physical machine. it's tailor-made for vms and free.
then:
- a 4gb vm for jenkins, with
kubectlinstalled so i can pass the kubeconfig to the jenkins agent - an 8gb vm for the k8s node
- a 4gb vm for the docker registry
jenkins setup
i run jenkins with docker compose in its own vm, because it's easier to manage and won't pollute that vm's environment.
services:
jenkins:
image: jenkins/jenkins:lts-jdk17
privileged: true
user: root
restart: always
ports:
- "8080:8080"
- "50000:50000"
container_name: jenkins
volumes:
- /usr/bin/docker:/usr/bin/docker
- ~/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/local/bin/kubectl:/usr/local/bin/kubectl:romounting /var/run/docker.sock is what lets the jenkins agent spin up containers โ for validating commits, or for building applications.
to give jenkins access to the cluster:
- install
kubectlin the vm - save the kubeconfig in jenkins using its credentials system
withCredentials in the pipeline then reads that credential back out at build time (below).
jenkinsfile and k8s yaml
you can configure a jenkinsfile two ways: in the web ui, or in the repo. i picked the repo, so the ci/cd config and the source code live in the same place.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Hello, World!'
}
}
}
}the build artifact
you'd think a docker registry is as simple as:
services:
registry:
image: registry:2
ports:
- "5000:5000"
volumes:
- registry_data:/var/lib/registryit is not. k8s flat out refuses to pull from a registry that isn't serving https, and i spent a good few days banging my head against that. every microk8s node has to be told to accept the insecure registry, which is a pain at one node and worse at ten.
i ended up setting up pihole for dns resolution and nginx proxy manager to handle the dns-01 challenge, so the registry could have a real certificate and stop being "insecure" at all.
k8s deployment
the deploy stage is why jenkins needs cluster access in the first place. every merge triggers a deploy of the latest build:
stage('Deploy') {
steps {
withCredentials([file(credentialsId: 'KUBECONFIG', variable: 'K8S_FILE')]) {
sh """
export KUBECONFIG=${K8S_FILE}
kubectl apply -f deployment.yml
"""
}
}
}the cluster and the cloudflare tunnel
i used microk8s rather than upstream kubernetes, because upstream is a memory-hungry monster and my node has 8gb.
the cloudflare tunnel does a lot of work here:
- it's free
- it hides my real ip
- it issues ssl certificates automatically
nginx or traefik would cover the first and third points, but neither hides your public ip. anyone hitting the console would see my homelab's address, which was the whole reason i went with the tunnel.
what i'd tell you before you start
the yaml is the easy part. the hard part is the boring middle: certificates, dns, and getting one machine to trust another. budget your weekend for that.
and then i gave up on it
this whole setup ran my site for a while, and then i switched to cloudflare.
not because it didn't work โ it did โ but because maintaining it was so annoying. every new service meant another ingress, another certificate, another thing that could quietly break while i was asleep. a homelab ci/cd pipeline is a wonderful way to learn devops and a terrible way to ship a blog.
so now the pipeline lives on cloudflare, where someone else worries about the certificates. the homelab still exists. it just has fewer jobs to do.