{"id":13820738,"url":"https://github.com/fischerscode/my-k3s","last_synced_at":"2025-06-27T20:34:07.008Z","repository":{"id":41975670,"uuid":"392807035","full_name":"fischerscode/my-k3s","owner":"fischerscode","description":"The configuration and automatation of a k3s cluster.","archived":false,"fork":false,"pushed_at":"2025-01-26T18:42:33.000Z","size":868,"stargazers_count":3,"open_issues_count":250,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T08:57:34.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fischerscode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-04T19:39:02.000Z","updated_at":"2025-01-26T18:42:37.000Z","dependencies_parsed_at":"2024-01-13T16:24:33.712Z","dependency_job_id":"73d348c0-b567-44cf-9b39-b07ba5de106b","html_url":"https://github.com/fischerscode/my-k3s","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fischerscode/my-k3s","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fischerscode%2Fmy-k3s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fischerscode%2Fmy-k3s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fischerscode%2Fmy-k3s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fischerscode%2Fmy-k3s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fischerscode","download_url":"https://codeload.github.com/fischerscode/my-k3s/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fischerscode%2Fmy-k3s/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262327693,"owners_count":23294327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T08:01:08.115Z","updated_at":"2025-06-27T20:34:06.954Z","avatar_url":"https://github.com/fischerscode.png","language":"Jinja","funding_links":[],"categories":["Jinja"],"sub_categories":[],"readme":"**THIS PROJECT IS STILL WORK IN PROGRESS**\n\n# my-k3s\nThe configuration and automatation of a k3s cluster.\n\n\u003c!-- # Setup\n1. Setup the servers using `ansible-playbook main.yml --extra-vars=cluster_name=contabo_1`.\n2. Get kubeconfig: `ansible-playbook tools/get_kubeconfig.yml --extra-vars=cluster_name=contabo_1`\n3. Port forward API-Server `ssh -L 6443:10.1.0.1:6443 172.16.17.101`\n4. kubeconfig server\n5. `KUBECONFIG=kubeconfig-vagrant.yaml`\n6. Setup Flux:\n   1. Make sure GITHUB_TOKEN is set. Run `export GITHUB_TOKEN=$(pbpaste)` with a personal access token (everything in repo is enabled) in your clipboard.\n   2. For vagrant: `flux bootstrap github --owner=fischerscode --repository=my-k3s --path=clusters/vagrant --branch master --personal`\n\n      For contabo_1: `flux bootstrap github --owner=fischerscode --repository=my-k3s --path=clusters/contabo_1 --branch master --personal` --\u003e\n\n\n\u003c!-- # Testing\nYou can test this repository using vagrant.\n1. `vagrant up`\n2. `ansible-playbook tools/store_known_hosts.yml`\n3. `ansible-playbook main.yml --extra-vars=cluster_name=vagrant`\n4. Make sure GITHUB_TOKEN is set. Run `export GITHUB_TOKEN=$(pbpaste)` with a personal access token (everything in repo is enabled) in your clipboard.\n5. `flux bootstrap github --owner=fischerscode --repository=my-k3s --path=clusters/vagrant --branch master --personal` --\u003e\n\n\n## Flux\nFlux is used to automatically provision the manifests.\n\n### Install Flux\nMacOS: ```brew install fluxcd/tap/flux```\n\n\n\u003c!-- # Velero\nVelero is used to backup the cluster.\n\n## Install Velero\nMacOS: ```brew install velero``` --\u003e\n\n\n\u003c!-- ## Partition\n1. start Rescue system (ArchRescue)\n2. ssh as root\n3. `fdisk -l`\n4. `e2fsck -f /dev/sda3 -y`\n5. `resize2fs /dev/sda3 100663296s`\n6. `parted /dev/sda`\n7. `unit s`\n8. Print current config: `print free`\n9. Shrink 3 by 150GB (215-150=65) `resizepart 3 104857599s` \n10. `mkpart logical 104857600s 419430366s` (104857600 = 419430400 - 150 * 1024^3 /512)\n11. Print current config: `print free`\n12. `reboot` --\u003e\n\n## New Cluster\n1. Specify cluster name: `export CLUSTER=`\n2. Setup ansible vault and store the vault password in `$CLUSTER-ansible.key`\n3. Create inventory: `cp inventory-sample.yaml inventory-$CLUSTER.yaml`\n4. Edit your inventory (Generate vault entries using `pbpaste | ansible-vault encrypt_string --vault-password-file $CLUSTER-ansible.key --name k3sToken`. `--name` has to be the name of the encrypted key.)\n5. Copy cluster manifests: `cp -r clusters/sample clusters/$CLUSTER`\n6. Edit `clusters/$CLUSTER/infrastructure.yaml` manifest\n7. Copy infrastructure: `cp -r infrastructure/sample infrastructure/$CLUSTER`\n8. Generate files: `ansible-playbook -i inventory-$CLUSTER.yaml tools/generate_files.yml --extra-vars=cluster_name=$CLUSTER`\n9.  [Setup SOPS](#mozilla-sops)\n10. Create secrets: `./generate-secrets.sh`\n11. Store known hosts: `ansible-playbook -i inventory-$CLUSTER.yaml tools/store_known_hosts.yml`\n12. Install k3s (wait until it hangs at 'Enable and check K3s service'): `ansible-playbook -i inventory-$CLUSTER.yaml main.yml --extra-vars=cluster_name=$CLUSTER --vault-password-file $CLUSTER-ansible.key`\n13. Get access to the cluster:\n    1.   New terminal and `export CLUSTER=` again.\n    2.  Get kubeconfig: `ansible-playbook -i inventory-$CLUSTER.yaml tools/get_kubeconfig.yml --extra-vars=cluster_name=$CLUSTER`\n    3.  Tunnel api server: `ssh -L 6443:10.1.0.1:6443 IP_OF_A_MASTER`\n    4.  New terminal and `export CLUSTER=` again.\n    5.  Replace IP at server in `kubeconfig-$CLUSTER.yaml` with `127.0.0.1`.\n    6.  Use config: `KUBECONFIG=kubeconfig-$CLUSTER.yaml`\n14. Setup Flux:\n    1. Make sure GITHUB_TOKEN is set. Run `export GITHUB_TOKEN=$(pbpaste)` with a personal access token (everything in repo is enabled) in your clipboard.\n    2. Setup flux: `flux bootstrap github --owner=fischerscode --repository=my-k3s --path=clusters/$CLUSTER --branch master --personal`\n15. Playbook should finish now. If not check `flux get all`.\n16. Replace IP at server in `kubeconfig-$CLUSTER.yaml` with `kubernetes_api_public_address`.\n   \n### Afterwards:\n1. Add cluster to `.github/workflows/update-flux.yaml`\n2. get grafana admin password: `kubectl get secret -n monitoring grafana-cred --template={{.data.ADMIN_PASSWORD}} | base64 -d | pbcopy`\n\n## Mozilla SOPS\n1. `brew install gnupg sops`\n2. Generate a GPG/OpenPGP key with no passphrase (%no-protection):\n   ```\n   export KEY_NAME=\"$CLUSTER.my-k3s.fischerscode.com\"\n   export KEY_COMMENT=\"flux secrets\"\n\n   gpg --batch --full-generate-key \u003c\u003cEOF\n   %no-protection\n   Key-Type: 1\n   Key-Length: 4096\n   Subkey-Type: 1\n   Subkey-Length: 4096\n   Expire-Date: 0\n   Name-Comment: ${KEY_COMMENT}\n   Name-Real: ${KEY_NAME}\n   EOF\n   ```\n3. `gpg --list-keys \"${KEY_NAME}\"`\n4. Store the fingerprint: `export KEY_FP=`\n5. Backup private key:\n   1. To file: `gpg --export-secret-keys --armor ${KEY_NAME} \u003e $CLUSTER.key` (Ansible will search for this key and apply it as a secret if present.)\n   2. To clipboard: `gpg --export-secret-keys --armor ${KEY_NAME} | pbcopy`\n6. Add public key to git: `gpg --export --armor ${KEY_NAME} \u003e ./clusters/$CLUSTER/.sops.pub.asc`\n7. ```\n   cat \u003c\u003cEOF \u003e\u003e .sops.yaml\n     - path_regex: /$CLUSTER\\/.*\\.yaml$\n       encrypted_regex: ^(data|stringData)$\n       pgp: ${KEY_FP}\n     - path_regex: /$CLUSTER\\/.*\\.encrypted$\n       pgp: ${KEY_FP}\n   EOF\n   ```\n\n### Optional:\n9.  Remove private key: `gpg --delete-secret-keys ${KEY_NAME}`\n10. Import secret key: `gpg --import $CLUSTER.key`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffischerscode%2Fmy-k3s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffischerscode%2Fmy-k3s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffischerscode%2Fmy-k3s/lists"}