-
Notifications
You must be signed in to change notification settings - Fork 839
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
Support HA mode with embedded DB #97
Changes from all commits
99323d0
e82a7c2
c866d64
c3e6bc8
072d624
6f105f0
19ff7b5
7ec3049
8b5b6e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ rules: | |
level: warning | ||
truthy: | ||
allowed-values: ['true', 'false', 'yes', 'no'] | ||
braces: | ||
max-spaces-inside: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
--- | ||
ansible_user: root | ||
k3s_server_location: /var/lib/rancher/k3s | ||
k3s_server_init_args: >- | ||
{% if groups['master'] | length > 1 %} | ||
{% if ansible_host == hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) %} | ||
--cluster-init | ||
{% else %} | ||
--server https://{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}:6443 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, wouldn't this be equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The apiserver_endpoint could be something other than a master host. It can be a load balancer, VIP, or something similar. You'll want to use that endpoint once the cluster is running but just to start it you just connect to any existing master host. |
||
{% endif %} | ||
--token {{ k3s_token }} | ||
{% endif %} | ||
{{ extra_server_args | default('') }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,39 @@ | ||
--- | ||
- name: Clean previous runs of k3s-init | ||
ansible.builtin.systemd: | ||
name: k3s-init | ||
state: stopped | ||
failed_when: false | ||
|
||
- name: Clean previous runs of k3s-init | ||
ansible.builtin.command: systemctl reset-failed k3s-init # noqa: command-instead-of-module | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Init cluster inside the transient k3s-init service | ||
ansible.builtin.command: | ||
cmd: "systemd-run -p RestartSec=2 \ | ||
-p Restart=on-failure \ | ||
--unit=k3s-init \ | ||
k3s server {{ k3s_server_init_args }}" | ||
creates: "{{ systemd_dir }}/k3s.service" | ||
|
||
- name: Verification | ||
block: | ||
- name: Verify that all nodes actually joined (check k3s-init.service if this fails) | ||
ansible.builtin.command: | ||
cmd: k3s kubectl get nodes -l "node-role.kubernetes.io/master=true" -o=jsonpath="{.items[*].metadata.name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be |
||
register: nodes | ||
until: nodes.rc == 0 and (nodes.stdout.split() | length) == (groups['master'] | length) | ||
retries: 20 | ||
delay: 10 | ||
changed_when: false | ||
always: | ||
- name: Kill the temporary service used for initialization | ||
ansible.builtin.systemd: | ||
name: k3s-init | ||
state: stopped | ||
failed_when: false | ||
|
||
- name: Copy K3s service file | ||
register: k3s_service | ||
|
@@ -22,17 +57,17 @@ | |
|
||
- name: Register node-token file access mode | ||
ansible.builtin.stat: | ||
path: "{{ k3s_server_location }}/server/node-token" | ||
path: "{{ k3s_server_location }}/server" | ||
register: p | ||
|
||
- name: Change file access node-token | ||
ansible.builtin.file: | ||
path: "{{ k3s_server_location }}/server/node-token" | ||
path: "{{ k3s_server_location }}/server" | ||
mode: "g+rx,o+rx" | ||
|
||
- name: Read node-token from master | ||
ansible.builtin.slurp: | ||
path: "{{ k3s_server_location }}/server/node-token" | ||
src: "{{ k3s_server_location }}/server/node-token" | ||
register: node_token | ||
|
||
- name: Store Master node-token | ||
|
@@ -41,7 +76,7 @@ | |
|
||
- name: Restore node-token file access | ||
ansible.builtin.file: | ||
path: "{{ k3s_server_location }}/server/node-token" | ||
path: "{{ k3s_server_location }}/server" | ||
mode: "{{ p.stat.mode }}" | ||
|
||
- name: Create directory .kube | ||
|
@@ -59,10 +94,10 @@ | |
owner: "{{ ansible_user }}" | ||
mode: "u=rw,g=,o=" | ||
|
||
- name: Replace https://localhost:6443 by https://master-ip:6443 | ||
- name: Configure kubectl cluster to server endpoint | ||
ansible.builtin.command: >- | ||
/usr/local/bin/k3s kubectl config set-cluster default | ||
--server=https://{{ master_ip }}:6443 | ||
--server=https://{{ apiserver_endpoint }}:{{ apiserver_port | default(6443) }} | ||
--kubeconfig ~{{ ansible_user }}/.kube/config | ||
changed_when: true | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that the same as
ansible_host == apiserver_endpoint
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That definitely tracks for me