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):
|
def test_k3s_node_ready(host):
|
||||||
jsonpth = '{range .items[*]}{@.metadata.name}:{range @.status.conditions[?(@.type=="Ready")]}{@.type}={@.status};{end}{end}' # noqa
|
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
|
assert "rocky9-k3s:Ready=True;" in nodes
|
||||||
|
|
||||||
|
|
||||||
def test_k3s_cluster_ready(host):
|
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"
|
assert cluster == "ok"
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
-p RestartSec=2
|
-p RestartSec=2
|
||||||
-p Restart=on-failure
|
-p Restart=on-failure
|
||||||
--unit=k3s-init
|
--unit=k3s-init
|
||||||
k3s server {{ __k3s_server_init_args }}
|
{{ __k3s_binary }} server {{ __k3s_server_init_args }}
|
||||||
creates: "{{ __k3s_service_file }}"
|
creates: "{{ __k3s_service_file }}"
|
||||||
args:
|
args:
|
||||||
warn: False
|
warn: False
|
||||||
@ -31,7 +31,7 @@
|
|||||||
- block:
|
- block:
|
||||||
- name: Verify that all nodes actually joined
|
- name: Verify that all nodes actually joined
|
||||||
command: >-
|
command: >-
|
||||||
k3s kubectl get nodes
|
{{ __k3s_binary }} kubectl get nodes
|
||||||
-l "node-role.kubernetes.io/master=true"
|
-l "node-role.kubernetes.io/master=true"
|
||||||
-o=jsonpath="{.items[*].metadata.name}"
|
-o=jsonpath="{.items[*].metadata.name}"
|
||||||
register: __k3s_init_nodes
|
register: __k3s_init_nodes
|
||||||
|
@ -83,17 +83,5 @@
|
|||||||
when:
|
when:
|
||||||
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
- ansible_hostname == hostvars[k3s_server_nodes[0]]['ansible_hostname']
|
||||||
- not __k3s_installed.stat.exists
|
- 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: True
|
||||||
become_user: root
|
become_user: root
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
- block:
|
||||||
- name: Disable services
|
- name: Disable services
|
||||||
service:
|
service:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
@ -8,6 +9,7 @@
|
|||||||
loop:
|
loop:
|
||||||
- k3s
|
- k3s
|
||||||
- k3s-init
|
- k3s-init
|
||||||
|
- kubepods
|
||||||
|
|
||||||
- name: Kill containerd-shim-runc
|
- name: Kill containerd-shim-runc
|
||||||
register: __k3s_pkill_containerd_shim_runc
|
register: __k3s_pkill_containerd_shim_runc
|
||||||
@ -51,8 +53,11 @@
|
|||||||
- /run/k3s
|
- /run/k3s
|
||||||
- /run/flannel
|
- /run/flannel
|
||||||
- /var/lib/kubelet
|
- /var/lib/kubelet
|
||||||
- /var/lib/cni/
|
- /var/lib/cni
|
||||||
|
- /var/run/netns
|
||||||
|
|
||||||
- name: Reload systemd daemon
|
- name: Reload systemd daemon
|
||||||
systemd:
|
systemd:
|
||||||
daemon_reload: True
|
daemon_reload: True
|
||||||
|
become: True
|
||||||
|
become_user: root
|
||||||
|
@ -19,46 +19,16 @@
|
|||||||
enabled: True
|
enabled: True
|
||||||
state: started
|
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
|
- name: Set server address
|
||||||
command: >-
|
command: >-
|
||||||
k3s kubectl config set-cluster default
|
{{ __k3s_binary }} kubectl config set-cluster default
|
||||||
--server=https://{{ __k3s_server_ip }}:6443
|
--server=https://{{ __k3s_server_ip }}:6443
|
||||||
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml
|
--kubeconfig {{ __k3s_config_dir }}/k3s.yaml
|
||||||
changed_when: False
|
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
|
- name: Wait for initial setup
|
||||||
command: >-
|
command: >-
|
||||||
kubectl get deployment coredns
|
{{ __k3s_binary }} kubectl get deployment coredns
|
||||||
-n kube-system
|
-n kube-system
|
||||||
-o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %}
|
-o go-template={% raw %}'{{ .status.availableReplicas }}'{% endraw %}
|
||||||
register: __k3s_init_setup
|
register: __k3s_init_setup
|
||||||
@ -66,6 +36,7 @@
|
|||||||
retries: 6
|
retries: 6
|
||||||
delay: 10
|
delay: 10
|
||||||
changed_when: False
|
changed_when: False
|
||||||
|
when: k3s_server | bool
|
||||||
|
|
||||||
- name: Remove auto-deploying manifests
|
- name: Remove auto-deploying manifests
|
||||||
file:
|
file:
|
||||||
@ -74,5 +45,6 @@
|
|||||||
loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}"
|
loop: "{{ k3s_server_manifests_urls + k3s_server_manifests_templates }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: "{{ __k3s_manifests_dir }}/{{ item.dest | default(item.url) | default(item) | basename | replace('.j2', '') }}"
|
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: True
|
||||||
become_user: root
|
become_user: root
|
||||||
|
@ -9,7 +9,7 @@ After=network-online.target
|
|||||||
Type=notify
|
Type=notify
|
||||||
ExecStartPre=-/sbin/modprobe br_netfilter
|
ExecStartPre=-/sbin/modprobe br_netfilter
|
||||||
ExecStartPre=-/sbin/modprobe overlay
|
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
|
KillMode=process
|
||||||
Delegate=yes
|
Delegate=yes
|
||||||
LimitNOFILE=1048576
|
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_ip: "{{ hostvars[k3s_server_nodes[0]].k3s_node_ip }}"
|
||||||
|
|
||||||
__k3s_server_init_args: >-
|
__k3s_server_init_args: >-
|
||||||
|
Loading…
Reference in New Issue
Block a user