This project allows to create a k8s cluster on-demand with only basic GitOps services running on it, such as ArgoCD and Gitea. Any other tools/services could be added using the GitOps approach. You can use it as a template for your own cluster.
- Hetzner Cloud API token
- Cloudflare API token
- Domain name in Cloudflare for your cluster
- Use
playfolder, or create new one, using it as a template - Create new snapshot of MicroOS image by running
export HCLOUD_TOKEN="your_hcloud_token"
packer init hcloud-microos-snapshots.pkr.hcl
packer build hcloud-microos-snapshots.pkr.hcl- Create
.envfile based on .env.example with snapshot IDs and credentials - Source the
.envfile to load environment variables:
source .env- To create hetzner resources and deploy k3s on them, run couple of times if needed (it can fail 1st time due to CRDs not being ready):
terraform apply --target=module.kube-hetzner- Wait for k3s to be ready and DNS to be propagated and to configure Gitea, ArgoCD, Dex, run what's left:
terraform applyAll credentials and urls for services can be found in play_credentials.yaml file, which is created after terraform apply command. Kubeconfig is outputed as play_kubeconfig.yaml file.
In order to fast and easy access you can export it to your shell:
export KUBECONFIG=$(pwd)/play_kubeconfig.yamlAs you first helm chart it's better to use something simple, like hello world app. Commit following files to your gitops repository:
hello/Chart.yaml
apiVersion: v2
name: hello
version: 0.0.0
dependencies:
- name: hello
version: 0.1.2
repository: https://cloudecho.github.io/charts/hello/values.yaml
hello:
replicaCount: 2Terraform creates resources on Hetzner, which are used to run k3s. Then k3s is used to deploy ArgoCD, Gitea and Dex. To deploy those helm charts Terraform uses HelmChart resource.
Terraform does the following extra:
- creates in Gitea new repository named
gitops, which is monitored by ArgoCD - creates webhook in Gitea to trigger ArgoCD sync on any push to
gitopsrepository - uploads public key to Gitea to allow ArgoCD and you to access it, using SSH
- configures Dex to use Gitea as OAuth2 provider, so you can access ArgoCD using Gitea credentials
diagram can be edited using draw.io
diagram can be edited using draw.io
TL;DR; Use https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner
Thanks to kube-hetzner for inspiration and for the module itself.
I think it's a great setup to start with if you want to create ready to use cluster, but I would recommend to do those things for production:
- do not use Gitea as a primary authentication provider, use something like Keycloak or Authelia
- do not use Gitea as gitops repository, use something like Github or Gitlab (main problem is that gitops remains in cluster which it tries to configure)
- do it highly-available
- do not use flannel as a CNI, I think Calico is better choice
