Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add k0s support #1123

Merged
merged 29 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ae2718a
ignore idea
brunnels Jan 8, 2024
20764e9
Initial work on support for k0s
brunnels Jan 8, 2024
61d4078
* Changed config param to bootstrap_distribution
brunnels Jan 8, 2024
9cf455d
* Switched to single storage path for openebs
brunnels Jan 9, 2024
1d984ba
* added the storageclass name to be declarative
brunnels Jan 9, 2024
3600011
* added newline
brunnels Jan 9, 2024
86ff24c
* fixed spacing in K0sTasks
brunnels Jan 9, 2024
3bb45e1
* updated configure task to use venv
brunnels Jan 10, 2024
7ce2910
* tweaked configure task cmd
brunnels Jan 10, 2024
f40699b
* tweaked k0s task cmd
brunnels Jan 11, 2024
384d074
* fixed whitespace
brunnels Jan 11, 2024
2f31c7a
add k0sctl to brew tasks
onedr0p Jan 11, 2024
9915a21
Update bootstrap/vars/config.sample.yaml
onedr0p Jan 11, 2024
394a261
Update bootstrap/vars/config.sample.yaml
onedr0p Jan 11, 2024
3f98769
Update k0s-config.yaml.j2
onedr0p Jan 11, 2024
ed9aad9
Update config.sample.yaml
onedr0p Jan 11, 2024
efd3f80
controllerManager and scheduler bind to `0.0.0.0` for metrics
onedr0p Jan 11, 2024
1598f73
Update custom-cilium-helmchart.yaml.j2.j2
onedr0p Jan 11, 2024
e9c0eec
Update helmvalues.yaml.j2
onedr0p Jan 11, 2024
cacc851
Update bootstrap/tasks/addons/main.yaml
onedr0p Jan 11, 2024
3252c39
first pass at readme updates
onedr0p Jan 11, 2024
d6ded50
update placement of k0sconfig options
onedr0p Jan 11, 2024
ce13bd5
disable telemetry on k0sctl too
onedr0p Jan 11, 2024
5a7808d
disable k0s telemetry in env too
onedr0p Jan 11, 2024
43eca2c
update: jinja spacing in k0sconfig
onedr0p Jan 11, 2024
f2bc783
fix: ensure bootstrap_local_storage_path is delete on nuke
onedr0p Jan 11, 2024
178f2fa
fix: update renovate regex for k3s/k0s
onedr0p Jan 11, 2024
91455ce
fix: update nuke playbook and only include k3s task when k3s
onedr0p Jan 11, 2024
ef99521
fix: update nuke playbook and only include k3s task when k3s and incl…
onedr0p Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
},
// custom versioning
{
"description": "Use custom versioning for k3s",
"description": "Use custom versioning for k0s/k3s",
"matchDatasources": ["github-releases"],
"versioning": "regex:^v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?<compatibility>\\+k3s)(?<build>\\d+)$",
"matchPackagePatterns": ["k3s"]
"versioning": "regex:^v(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?<compatibility>\\+k[0|3]s)(?<build>\\d+)$",
"matchPackagePatterns": ["k0s", "k3s"]
},
// commit message topics
{
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ kubeconfig
.venv*
# Taskfile
.tasks
# intellij
.idea

8 changes: 7 additions & 1 deletion .taskfiles/FluxTasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ tasks:
- kubectl apply --server-side --filename {{.KUBERNETES_DIR}}/flux/vars/cluster-settings-user.yaml
- kubectl apply --server-side --kustomize {{.KUBERNETES_DIR}}/flux/config
preconditions:
- { msg: "Flux already appears installed", sh: "exit $(( ! $(kubectl get namespace flux-system) ))" }
- { msg: "Flux already appears installed", sh: "kubectl get namespace flux-system &>/dev/null && exit 1 || exit 0" }
- { msg: "Age private key not found", sh: "test -f {{.ROOT_DIR}}/age.key" }

github-deploy-key:
cmds:
- sops --decrypt {{.KUBERNETES_DIR}}/bootstrap/github-deploy-key.sops.yaml | kubectl apply -f -
preconditions:
- { msg: "Flux is not installed", sh: "kubectl get namespace flux-system &>/dev/null && exit 0 || exit 1" }

apply:
desc: Apply a Flux Kustomization resource for a cluster
summary: |
Expand Down
25 changes: 25 additions & 0 deletions .taskfiles/K0sTasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
version: "3"

tasks:

kubeconfig:
desc: Gets k0s cluster kubeconfig
cmds:
- k0sctl kubeconfig --config k0s-config.yaml > kubeconfig
preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" }

apply:
desc: Apply k0s cluster k0s-config.yaml
cmds:
- k0sctl apply --config k0s-config.yaml
- task: kubeconfig
preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" }

reset:
desc: Resets the k0s cluster
cmd: k0sctl reset --config k0s-config.yaml
preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" }
4 changes: 2 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ includes:
aliases: ["k8s"]
taskfile: .taskfiles/KubernetesTasks.yaml
flux: .taskfiles/FluxTasks.yaml
k0s: .taskfiles/K0sTasks.yaml

tasks:

Expand Down Expand Up @@ -45,7 +46,6 @@ tasks:
configure:
desc: Configure repository from Ansible vars
prompt: Any conflicting config in the root kubernetes and ansible directories will be overwritten... continue?
dir: "{{.BOOTSTRAP_DIR}}"
cmd: ansible-playbook configure.yaml
cmd: ./.venv/bin/ansible-playbook {{.BOOTSTRAP_DIR}}/configure.yaml
env:
ANSIBLE_DISPLAY_SKIPPED_HOSTS: "false"
10 changes: 7 additions & 3 deletions bootstrap/configure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
ansible.builtin.set_fact:
repository_path: "{{ repository.stdout }}"

- name: Override kube-vip address when there is a single master node and no address is defined
when: bootstrap_nodes.master | length == 1 and not bootstrap_kube_vip_addr
- name: Override kubeapi address when there is a single master node and no address is defined
when: bootstrap_nodes.master | length == 1 and not bootstrap_kubeapi_addr
ansible.builtin.set_fact:
bootstrap_kube_vip_enabled: false
bootstrap_kube_vip_addr: "{{ bootstrap_nodes.master[0].address }}"
bootstrap_kubeapi_addr: "{{ bootstrap_nodes.master[0].address }}"

- name: Verify configuration
ansible.builtin.include_tasks: tasks/validation/main.yaml

- name: Template Sops configuration
ansible.builtin.include_tasks: tasks/sops/main.yaml

- name: Template k0s configuration
when: bootstrap_distribution == "k0s"
ansible.builtin.include_tasks: tasks/k0s/main.yaml

- name: Template Ansible configuration
ansible.builtin.include_tasks: tasks/ansible/main.yaml
onedr0p marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
34 changes: 34 additions & 0 deletions bootstrap/tasks/addons/coredns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Set addon facts
ansible.builtin.set_fact:
addon_name: coredns
addon_namespace: kube-system

- name: Ensure directories exist for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'directory'
ansible.builtin.file:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path }}"
state: directory
mode: "0755"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]

- name: Template unencrypted files for {{ addon_namespace }}/{{ addon_name }}
when: item.state == 'file' and 'sops' not in item.path
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
mode: "0644"
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]

- name: Template encrypted files for {{ addon_namespace }}/{{ addon_name }}
block:
- name: Template encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ addon_namespace }}/{{ addon_name }}/{{ item.path | replace('.j2', '') }}"
encrypted_regex: ^(data|stringData)$
age: ["{{ bootstrap_age_public_key }}"]
content_yaml: "{{ lookup('ansible.builtin.template', item.src) | from_yaml }}"
mode: "0644"
force: true
with_community.general.filetree: ["../templates/addons/{{ addon_name }}/"]
6 changes: 5 additions & 1 deletion bootstrap/tasks/addons/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---

- name: Process optional coredns
when: bootstrap_distribution == "k3s"
ansible.builtin.include_tasks: coredns.yaml

- name: Process addon csi-driver-nfs
when: csi_driver_nfs.enabled | default(false)
ansible.builtin.include_tasks: csi_driver_nfs.yaml
Expand All @@ -21,7 +25,7 @@
ansible.builtin.include_tasks: kube_prometheus_stack.yaml

- name: Process addon system-upgrade-controller
when: system_upgrade_controller.enabled | default(false)
when: (bootstrap_distribution == "k3s") and (system_upgrade_controller.enabled | default(false))
onedr0p marked this conversation as resolved.
Show resolved Hide resolved
ansible.builtin.include_tasks: system_upgrade_controller.yaml

- name: Process addon weave-gitops
Expand Down
11 changes: 1 addition & 10 deletions bootstrap/tasks/ansible/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,4 @@
mode: "0644"
force: true
with_community.general.filetree: ["../templates/ansible/"]
- name: Template encrypted node secrets
community.sops.sops_encrypt:
path: "{{ repository_path }}/ansible/inventory/host_vars/{{ item.name }}.sops.yaml"
age: ["{{ bootstrap_age_public_key }}"]
content_yaml: "{{ lookup('ansible.builtin.template', 'templates/node.sops.yaml.j2', template_vars=dict(password=item.password)) | from_yaml }}"
mode: "0644"
force: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
label: "{{ item.address }}"

6 changes: 6 additions & 0 deletions bootstrap/tasks/k0s/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Template k0s configuration file
ansible.builtin.template:
src: "templates/k0s-config.yaml.j2"
dest: "{{ repository_path }}/k0s-config.yaml"
mode: "0644"
4 changes: 4 additions & 0 deletions bootstrap/tasks/validation/github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
fail_msg: Github user {{ bootstrap_github_username }} does not exist

- name: Query Github repo
when: not bootstrap_private_github_repo | default(false)
ansible.builtin.uri:
url: https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}
timeout: 5
Expand All @@ -22,12 +23,14 @@
register: result

- name: Check if repo exists
when: not bootstrap_private_github_repo | default(false)
ansible.builtin.assert:
that: result.json.full_name == bootstrap_github_username + '/' + bootstrap_github_repository_name
success_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} exists
fail_msg: Github repo {{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }} does not exist

- name: Query Github repo branch
when: not bootstrap_private_github_repo | default(false)
ansible.builtin.uri:
url: https://api.github.com/repos/{{ bootstrap_github_username }}/{{ bootstrap_github_repository_name }}/branches/{{ bootstrap_github_repository_branch | default('main', true) }}
timeout: 5
Expand All @@ -36,6 +39,7 @@
register: result

- name: Check if repo branch exists
when: not bootstrap_private_github_repo | default(false)
ansible.builtin.assert:
that: result.json.name == bootstrap_github_repository_branch | default('main', true)
success_msg: Github repo branch {{ bootstrap_github_repository_branch | default('main', true) }} exists
Expand Down
28 changes: 14 additions & 14 deletions bootstrap/tasks/validation/net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@
success_msg: external ingress address {{ bootstrap_external_ingress_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: external ingress address {{ bootstrap_external_ingress_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify kube-vip
- name: Verify kubeapi address
ansible.builtin.assert:
that: bootstrap_kube_vip_addr is ansible.utils.ipv4
success_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is valid.
fail_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is invalid.
that: bootstrap_kubeapi_addr is ansible.utils.ipv4
success_msg: kubeapi address {{ bootstrap_kubeapi_addr }} is valid.
fail_msg: kubeapi address {{ bootstrap_kubeapi_addr }} is invalid.

- name: Verify kube-vip in node CIDR
- name: Verify kubeapi address in node CIDR
ansible.builtin.assert:
that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_kube_vip_addr)
success_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is not within {{ bootstrap_node_cidr }}.
that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_kubeapi_addr)
success_msg: kubeapi address {{ bootstrap_kubeapi_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: kubeapi address {{ bootstrap_kubeapi_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify all IP addresses are unique
ansible.builtin.assert:
Expand All @@ -117,7 +117,7 @@
bootstrap_k8s_gateway_addr,
bootstrap_external_ingress_addr,
bootstrap_internal_ingress_addr,
bootstrap_kube_vip_addr
bootstrap_kubeapi_addr
] | unique | length == 4
success_msg: All IP addresses are unique.
fail_msg: All IP addresses are not unique.
Expand All @@ -133,12 +133,12 @@
loop_control:
label: "{{ item.address }}"

- name: Verify nodes are not the same IPs as k8s_gateway, ingress external/internal or kube-vip
when: bootstrap_kube_vip_enabled | default(true)
- name: Verify nodes are not the same IPs as k8s_gateway, ingress external/internal or kubeapi address
when: (bootstrap_distribution == "k3s") and (bootstrap_kube_vip_enabled | default(true))
ansible.builtin.assert:
that: item.address not in (bootstrap_k8s_gateway_addr, bootstrap_external_ingress_addr, bootstrap_internal_ingress_addr, bootstrap_kube_vip_addr)
success_msg: Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kube-vip.
fail_msg: Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kube-vip.
that: item.address not in (bootstrap_k8s_gateway_addr, bootstrap_external_ingress_addr, bootstrap_internal_ingress_addr, bootstrap_kubeapi_addr)
success_msg: Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kubeapi.
fail_msg: Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kubeapi.
quiet: true
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
loop_control:
Expand Down
11 changes: 6 additions & 5 deletions bootstrap/tasks/validation/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@
- bootstrap_cloudflare_tunnel_id
- bootstrap_cloudflare_tunnel_secret
- bootstrap_cluster_cidr
- bootstrap_distribution
- bootstrap_external_ingress_addr
- bootstrap_flux_github_webhook_token
- bootstrap_github_repository_name
- bootstrap_github_repository_branch
- bootstrap_github_repository_name
- bootstrap_github_username
- bootstrap_external_ingress_addr
- bootstrap_internal_ingress_addr
- bootstrap_ipv6_enabled
- bootstrap_k8s_gateway_addr
- bootstrap_kube_vip_addr
- bootstrap_local_path_provisioner_path
brunnels marked this conversation as resolved.
Show resolved Hide resolved
- bootstrap_kubeapi_addr
- bootstrap_local_storage_path
- bootstrap_node_cidr
- bootstrap_service_cidr
- bootstrap_timezone

- name: Verify bootstrap node names are valid
ansible.builtin.assert:
that: item.name is match('^[a-z0-9-]+$')
that: item.name is match('^[a-z0-9-\.]+$')
success_msg: Node name {{ item.name }} is valid
fail_msg: Node name {{ item.name }} is not valid
loop: "{{ bootstrap_nodes.master + bootstrap_nodes.worker | default([]) }}"
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/templates/addons/grafana/app/helmrelease.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
uninstall:
keepHistory: false
dependsOn:
- name: local-path-provisioner
- name: openebs
namespace: storage
values:
deploymentStrategy:
Expand Down Expand Up @@ -168,6 +168,6 @@ spec:
- *host
persistence:
enabled: true
storageClassName: local-hostpath
storageClassName: openebs-hostpath
testFramework:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
uninstall:
keepHistory: false
dependsOn:
- name: local-path-provisioner
- name: openebs
namespace: storage
valuesFrom:
- name: kube-prometheus-stack-values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ data:
storageSpec:
volumeClaimTemplate:
spec:
storageClassName: local-hostpath
storageClassName: openebs-hostpath
resources:
requests:
storage: 10Gi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ k3s_etcd_datastore: true
{% else %}
k3s_etcd_datastore: false
{% endif %}
k3s_registration_address: "{% raw %}{{ kube_vip_addr }}{% endraw %}"
k3s_registration_address: "{% raw %}{{ kubeapi_addr }}{% endraw %}"
# /var/lib/rancher/k3s/server/manifests
k3s_server_manifests_templates:
- custom-cilium-helmchart.yaml.j2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
timezone: "{{ bootstrap_timezone }}"
github_username: "{{ bootstrap_github_username }}"
coredns_addr: "{{ bootstrap_service_cidr.split(',')[0] | ansible.utils.nthhost(10) }}"
kube_vip_addr: "{{ bootstrap_kube_vip_addr }}"
kubeapi_addr: "{{ bootstrap_kubeapi_addr }}"
cluster_cidr: "{{ bootstrap_cluster_cidr.split(',')[0] }}"
service_cidr: "{{ bootstrap_service_cidr.split(',')[0] }}"
node_cidr: "{{ bootstrap_node_cidr }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ k3s_server:
node-ip: "{% raw %}{{ ansible_host }}{% endraw %}"
{% endif %}
tls-san:
- "{% raw %}{{ kube_vip_addr }}{% endraw %}"
- "{% raw %}{{ kubeapi_addr }}{% endraw %}"
docker: false
flannel-backend: "none" # This needs to be in quotes
disable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
ipv6:
enabled: true
{% endif %}
k8sServiceHost: "{% raw %}{{ kube_vip_addr }}{% endraw %}"
k8sServiceHost: "{% raw %}{{ kubeapi_addr }}{% endraw %}"
k8sServicePort: 6443
kubeProxyReplacement: true
kubeProxyReplacementHealthzBindAddr: 0.0.0.0:10256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
args: ["manager"]
env:
- name: address
value: "{% raw %}{{ kube_vip_addr }}{% endraw %}"
value: "{% raw %}{{ kubeapi_addr }}{% endraw %}"
- name: vip_arp
value: "true"
- name: lb_enable
Expand Down