This commit is contained in:
parent
f9edbc0f2a
commit
2a5e12dcad
@ -16,13 +16,13 @@ def test_k3s_running_and_enabled(host):
|
||||
|
||||
def test_k3s_node_ready(host):
|
||||
jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa
|
||||
nodes = host.run(f"kubectl get nodes -o jsonpath='{jsonpth}'").stdout
|
||||
nodes = host.run(f"k3s kubectl get nodes -o jsonpath='{jsonpth}'").stdout
|
||||
|
||||
assert "rocky9-k3s:Ready=True;" in nodes
|
||||
|
||||
|
||||
def test_k3s_cluster_ready(host):
|
||||
cluster = host.run("kubectl get --raw='/readyz'").stdout
|
||||
cluster = host.run("k3s kubectl get --raw='/readyz'").stdout
|
||||
|
||||
assert cluster == "ok"
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
-p RestartSec=2
|
||||
-p Restart=on-failure
|
||||
--unit=k3s-init
|
||||
k3s server {{ __k3s_server_init_args }}
|
||||
{{ __k3s_binary }} server {{ __k3s_server_init_args }}
|
||||
creates: "{{ __k3s_service_file }}"
|
||||
args:
|
||||
warn: False
|
||||
@ -31,7 +31,7 @@
|
||||
- block:
|
||||
- name: Verify that all nodes actually joined
|
||||
command: >-
|
||||
k3s kubectl get nodes
|
||||
{{ __k3s_binary }} kubectl get nodes
|
||||
-l "node-role.kubernetes.io/master=true"
|
||||
-o=jsonpath="{.items[*].metadata.name}"
|
||||
register: __k3s_init_nodes
|
||||
|
@ -83,17 +83,5 @@
|
||||
when:
|
||||
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
||||
- not __k3s_installed.stat.exists
|
||||
|
||||
- name: Create kubectl symlink
|
||||
file:
|
||||
src: /usr/local/bin/k3s
|
||||
dest: /usr/local/bin/kubectl
|
||||
state: link
|
||||
|
||||
- name: Create crictl symlink
|
||||
file:
|
||||
src: /usr/local/bin/k3s
|
||||
dest: /usr/local/bin/crictl
|
||||
state: link
|
||||
become: True
|
||||
become_user: root
|
||||
|
109
tasks/reset.yml
109
tasks/reset.yml
@ -1,58 +1,63 @@
|
||||
---
|
||||
- name: Disable services
|
||||
service:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: False
|
||||
failed_when: False
|
||||
loop:
|
||||
- k3s
|
||||
- k3s-init
|
||||
- block:
|
||||
- name: Disable services
|
||||
service:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: False
|
||||
failed_when: False
|
||||
loop:
|
||||
- k3s
|
||||
- k3s-init
|
||||
- kubepods
|
||||
|
||||
- name: Kill containerd-shim-runc
|
||||
register: __k3s_pkill_containerd_shim_runc
|
||||
command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc"
|
||||
changed_when: __k3s_pkill_containerd_shim_runc.rc == 0
|
||||
failed_when: False
|
||||
- name: Kill containerd-shim-runc
|
||||
register: __k3s_pkill_containerd_shim_runc
|
||||
command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc"
|
||||
changed_when: __k3s_pkill_containerd_shim_runc.rc == 0
|
||||
failed_when: False
|
||||
|
||||
- name: Get the list of mounted filesystems
|
||||
shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ item }}"
|
||||
loop:
|
||||
- /run/k3s
|
||||
- /var/lib/kubelet
|
||||
- /run/netns
|
||||
- /var/lib/kubelet/pods
|
||||
- /var/lib/kubelet/plugins
|
||||
- /run/netns/cni-
|
||||
- "{{ __k3s_data_dir }}"
|
||||
register: __k3s_mounted_fs
|
||||
args:
|
||||
executable: /bin/bash
|
||||
failed_when: False
|
||||
changed_when: False
|
||||
- name: Get the list of mounted filesystems
|
||||
shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ item }}"
|
||||
loop:
|
||||
- /run/k3s
|
||||
- /var/lib/kubelet
|
||||
- /run/netns
|
||||
- /var/lib/kubelet/pods
|
||||
- /var/lib/kubelet/plugins
|
||||
- /run/netns/cni-
|
||||
- "{{ __k3s_data_dir }}"
|
||||
register: __k3s_mounted_fs
|
||||
args:
|
||||
executable: /bin/bash
|
||||
failed_when: False
|
||||
changed_when: False
|
||||
|
||||
- name: Umount filesystem
|
||||
mount:
|
||||
path: "{{ item }}"
|
||||
state: unmounted
|
||||
loop: "{{ __k3s_mounted_fs.results | map(attribute='stdout_lines') | list | flatten | reverse }}"
|
||||
- name: Umount filesystem
|
||||
mount:
|
||||
path: "{{ item }}"
|
||||
state: unmounted
|
||||
loop: "{{ __k3s_mounted_fs.results | map(attribute='stdout_lines') | list | flatten | reverse }}"
|
||||
|
||||
- name: Remove service files, binaries and data
|
||||
file:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /usr/local/bin/k3s
|
||||
- "{{ __k3s_service_file }}"
|
||||
- "{{ __k3s_config_dir }}"
|
||||
- "{{ __k3s_data_dir }}"
|
||||
- "{{ __k3s_log_dir }}"
|
||||
- /etc/cni
|
||||
- /run/k3s
|
||||
- /run/flannel
|
||||
- /var/lib/kubelet
|
||||
- /var/lib/cni/
|
||||
- name: Remove service files, binaries and data
|
||||
file:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /usr/local/bin/k3s
|
||||
- "{{ __k3s_service_file }}"
|
||||
- "{{ __k3s_config_dir }}"
|
||||
- "{{ __k3s_data_dir }}"
|
||||
- "{{ __k3s_log_dir }}"
|
||||
- /etc/cni
|
||||
- /run/k3s
|
||||
- /run/flannel
|
||||
- /var/lib/kubelet
|
||||
- /var/lib/cni
|
||||
- /var/run/netns
|
||||
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: True
|
||||
- name: Reload systemd daemon
|
||||
systemd:
|
||||
daemon_reload: True
|
||||
become: True
|
||||
become_user: root
|
||||
|
@ -19,46 +19,16 @@
|
||||
enabled: True
|
||||
state: started
|
||||
|
||||
- name: Wait for node-token
|
||||
wait_for:
|
||||
path: "{{ __k3s_data_dir }}/server/node-token"
|
||||
|
||||
- name: Read node-token from server
|
||||
slurp:
|
||||
path: "{{ __k3s_data_dir }}/server/node-token"
|
||||
register: __k3s_node_token
|
||||
|
||||
- name: Store server node-token
|
||||
set_fact:
|
||||
token: "{{ __k3s_node_token.content | b64decode | regex_replace('\n', '') }}"
|
||||
|
||||
- name: Set server address
|
||||
command: >-
|
||||
k3s kubectl config set-cluster default
|
||||
{{ __k3s_binary }} kubectl config set-cluster default
|
||||
--server=https://{{ __k3s_server_ip }}:6443
|
||||
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml
|
||||
changed_when: False
|
||||
|
||||
- name: Create directory .kube
|
||||
file:
|
||||
path: "{{ ansible_user_dir }}/.kube"
|
||||
state: directory
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
mode: 0740
|
||||
|
||||
- name: Copy kube config to user home
|
||||
copy:
|
||||
src: "{{ __k3s_config_dir }}/k3s.yaml"
|
||||
dest: "{{ ansible_user_dir }}/.kube/config"
|
||||
remote_src: True
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
mode: "preserve"
|
||||
|
||||
- name: Wait for initial setup
|
||||
command: >-
|
||||
kubectl get deployment coredns
|
||||
{{ __k3s_binary }} kubectl get deployment coredns
|
||||
-n kube-system
|
||||
-o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %}
|
||||
register: __k3s_init_setup
|
||||
@ -66,6 +36,7 @@
|
||||
retries: 6
|
||||
delay: 10
|
||||
changed_when: False
|
||||
when: k3s_server | bool
|
||||
|
||||
- name: Remove auto-deploying manifests
|
||||
file:
|
||||
@ -74,5 +45,6 @@
|
||||
loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}"
|
||||
loop_control:
|
||||
label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"
|
||||
when: ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
||||
become: True
|
||||
become_user: root
|
||||
|
@ -9,7 +9,7 @@ After=network-online.target
|
||||
Type=notify
|
||||
ExecStartPre=-/sbin/modprobe br_netfilter
|
||||
ExecStartPre=-/sbin/modprobe overlay
|
||||
ExecStart=/usr/local/bin/k3s {{ "server" if k3s_server | bool else "agent" }} --config {{ __k3s_config_dir }}/config.yaml
|
||||
ExecStart={{ __k3s_binary }} {{ "server" if k3s_server | bool else "agent" }} --config {{ __k3s_config_dir }}/config.yaml
|
||||
KillMode=process
|
||||
Delegate=yes
|
||||
LimitNOFILE=1048576
|
||||
|
@ -1,4 +1,5 @@
|
||||
---
|
||||
__k3s_binary: /usr/local/bin/k3s
|
||||
__k3s_server_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip }}"
|
||||
|
||||
__k3s_server_init_args: >-
|
||||
|
Loading…
Reference in New Issue
Block a user