feat: added install kubectl and helm

This commit is contained in:
2024-02-26 11:20:30 +00:00
parent 00e4f7e5ab
commit f3ae6b8b9f
6 changed files with 68 additions and 6 deletions

View File

@@ -8,3 +8,11 @@ k3s_datastore_endpoint: ""
k3s_token: "" k3s_token: ""
k3s_kubeconfig_mode: "600" k3s_kubeconfig_mode: "600"
k3s_version: "v1.28.3+k3s2" k3s_version: "v1.28.3+k3s2"
k3s_kubectl_force_update: false
k3s_kubectl_version: "v1.28.3"
k3s_kubectl_url: "https://dl.k8s.io/release/{{ k3s_kubectl_version }}/bin/linux/amd64/kubectl"
k3s_helm_force_update: false
k3s_helm_version: "v3.13.1"
k3s_helm_url: "https://github.com/helm/helm/releases/download/{{ k3s_helm_version }}/helm-{{ k3s_helm_version }}-linux-amd64.tar.gz"

View File

@@ -18,3 +18,15 @@
enabled: yes enabled: yes
name: k3s name: k3s
when: k3s_env.changed or k3s_master.changed when: k3s_env.changed or k3s_master.changed
- name: Ensure the .kube directory exists
file:
path: /root/.kube
state: directory
mode: '0700'
- name: Link /etc/rancher/k3s/k3s.yaml to /root/.kube/config
file:
src: /etc/rancher/k3s/k3s.yaml
dest: /root/.kube/config
state: link

View File

@@ -6,7 +6,7 @@
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}" dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root owner: root
group: root group: root
mode: 0755 mode: 0750
when: ansible_facts.architecture == "x86_64" when: ansible_facts.architecture == "x86_64"
- name: Download k3s binary arm64 - name: Download k3s binary arm64
@@ -16,7 +16,7 @@
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}" dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root owner: root
group: root group: root
mode: 0755 mode: 0750
when: when:
- ( ansible_facts.architecture is search("arm") and - ( ansible_facts.architecture is search("arm") and
ansible_facts.userspace_bits == "64" ) or ansible_facts.userspace_bits == "64" ) or
@@ -29,7 +29,7 @@
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}" dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root owner: root
group: root group: root
mode: 0755 mode: 0750
when: when:
- ansible_facts.architecture is search("arm") - ansible_facts.architecture is search("arm")
- ansible_facts.userspace_bits == "32" - ansible_facts.userspace_bits == "32"

View File

@@ -0,0 +1,15 @@
---
- name: Download helm binary
get_url:
url: "{{ k3s_helm_url }}"
dest: "/tmp/helm-{{ k3s_helm_version }}.tar.gz"
when: ansible_facts.architecture == "x86_64"
- name: extract binary
unarchive:
src: "/tmp/helm-{{ k3s_helm_version }}.tar.gz"
dest: "{{ k3s_binary_dir }}/helm"
owner: root
group: "root"
mode: 0750
remote_src: true

View File

@@ -0,0 +1,9 @@
---
- name: Download kubectl binary
get_url:
url: "{{ k3s_kubectl_url }}"
dest: "{{ k3s_binary_dir }}/kubectl"
owner: root
group: root
mode: 0750
when: ansible_facts.architecture == "x86_64"

View File

@@ -1,15 +1,33 @@
--- ---
- name: check if binary already exists - name: check if binary k3s already exists
stat: stat:
path: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}" path: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
register: binary_check_result register: binary_k3s_check_result
- name: install binary - name: install binary
include_tasks: installation.yml include_tasks: installation.yml
when: not binary_check_result.stat.exists or k3s_force_update when: not binary_k3s_check_result.stat.exists or k3s_force_update
- name: general preparation - name: general preparation
include_tasks: preparation.yml include_tasks: preparation.yml
- name: check if binary kubectl already exists
stat:
path: "{{ k3s_binary_dir }}/kubectl"
register: binary_kubectl_check_result
- name: install binary kubectl
include_tasks: installation_kubectl.yml
when: not binary_kubectl_check_result.stat.exists or k3s_kubectl_force_update
- name: check if binary helm already exists
stat:
path: "{{ k3s_binary_dir }}/helm"
register: binary_helm_check_result
- name: install binary helm
include_tasks: installation_helm.yml
when: not binary_helm_check_result.stat.exists or k3s_helm_force_update
- name: configuration - name: configuration
include_tasks: configuration.yml include_tasks: configuration.yml