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 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -c k0s-config.yaml > kubeconfig
brunnels marked this conversation as resolved.
Show resolved Hide resolved
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" }
brunnels marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 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
3 changes: 3 additions & 0 deletions bootstrap/configure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
- name: Template Kubernetes configuration
ansible.builtin.include_tasks: tasks/kubernetes/main.yaml

- name: Template Kubernetes optional configuration
ansible.builtin.include_tasks: tasks/optional/main.yaml

- name: Template Kubernetes addon configuration
ansible.builtin.include_tasks: tasks/addons/main.yaml
2 changes: 1 addition & 1 deletion bootstrap/tasks/addons/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 }}"

34 changes: 34 additions & 0 deletions bootstrap/tasks/optional/coredns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
brunnels marked this conversation as resolved.
Show resolved Hide resolved
- name: Set addon facts
ansible.builtin.set_fact:
optional_name: coredns
optional_namespace: kube-system

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

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

- name: Template encrypted files for {{ optional_namespace }}/{{ optional_name }}
block:
- name: Template encrypted files
when: item.state == 'file' and 'sops' in item.path
community.sops.sops_encrypt:
path: "{{ repository_path }}/kubernetes/apps/{{ optional_namespace }}/{{ optional_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/optional/{{ optional_name }}/"]
7 changes: 7 additions & 0 deletions bootstrap/tasks/optional/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

- name: Process optional opendns
brunnels marked this conversation as resolved.
Show resolved Hide resolved
when: bootstrap_distribution == "k3s"
ansible.builtin.include_tasks: coredns.yaml


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
2 changes: 1 addition & 1 deletion bootstrap/tasks/validation/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
success_msg: Required bootstrap var {{ item }} exists and is defined
fail_msg: Required bootstrap var {{ item }} does not exists or is not defined
loop:
- bootstrap_distribution
- bootstrap_acme_email
- bootstrap_age_public_key
- bootstrap_cilium_loadbalancer_mode
Expand All @@ -25,7 +26,6 @@
- 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_node_cidr
- bootstrap_service_cidr
- bootstrap_timezone
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 @@ -16,7 +16,11 @@ data:
id: 1
containerRuntime:
integration: containerd
{% if k0s.enabled | default(false) %}
socketPath: /var/run/k0s/containerd.sock
{% else %}
socketPath: /var/run/k3s/containerd/containerd.sock
{% endif %}
brunnels marked this conversation as resolved.
Show resolved Hide resolved
endpointRoutes:
enabled: true
hubble:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ kind: Kustomization
resources:
- ./namespace.yaml
- ./cilium/ks.yaml
{% if bootstrap_distribution == "k3s" %}
- ./coredns/ks.yaml
{% endif %}
brunnels marked this conversation as resolved.
Show resolved Hide resolved
- ./metrics-server/ks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./namespace.yaml
- ./local-path-provisioner/ks.yaml
- ./openebs/ks.yaml
- ./snapshot-controller/ks.yaml
- ./volsync/ks.yaml
{% if csi_driver_nfs.enabled | default(false) %}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: openebs
spec:
interval: 30m
chart:
spec:
chart: openebs
version: 3.3.0
sourceRef:
kind: HelmRepository
name: openebs
namespace: flux-system
maxHistory: 2
install:
remediation:
retries: 3
upgrade:
cleanupOnFail: true
remediation:
retries: 3
uninstall:
keepHistory: false
values:
localprovisioner:
hostpathClass:
enabled: true
isDefaultClass: false
{% if bootstrap_distribution == 'k3s' %}
basePath: "{{ bootstrap_local_storage_path | default('/var/lib/rancher/k3s/local-hostpath', true) }}"
{% else %}
basePath: "{{ bootstrap_local_storage_path | default('/var/openebs/local', true) }}"
{% endif %}
brunnels marked this conversation as resolved.
Show resolved Hide resolved

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./helmrelease.yaml
- ./helmrelease.yaml
brunnels marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: &app local-path-provisioner
name: &app openebs
namespace: flux-system
spec:
targetNamespace: storage
commonMetadata:
labels:
app.kubernetes.io/name: *app
path: ./kubernetes/apps/storage/local-path-provisioner/app
path: ./kubernetes/apps/kube-system/openebs/app
brunnels marked this conversation as resolved.
Show resolved Hide resolved
prune: true
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false
wait: true
brunnels marked this conversation as resolved.
Show resolved Hide resolved
interval: 30m
retryInterval: 1m
timeout: 5m
2 changes: 0 additions & 2 deletions bootstrap/templates/node.sops.yaml.j2

This file was deleted.

1 change: 1 addition & 0 deletions bootstrap/vars/addons.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ system_upgrade_controller:
# WARNING: Only enable this if you also track the version of k3s in the
# ansible configuration files. Running ansible against an already provisioned
# cluster with this enabled might cause your cluster to be downgraded.
# Note that if bootstrap_distribution is set to k0s enable: true will be ignored.
brunnels marked this conversation as resolved.
Show resolved Hide resolved
enabled: false

# https://github.com/morphy2k/rss-forwarder
Expand Down
Loading