-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from k3s-io/default_k3s_script
Fix HA, simplify provisioning, add Vagrant test cluster
- Loading branch information
Showing
16 changed files
with
239 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
warn_list: | ||
- var-naming[no-role-prefix] | ||
- yaml[comments-indentation] | ||
- yaml[line-length] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# ENV['VAGRANT_NO_PARALLEL'] = 'no' | ||
NODE_ROLES = ["server-0", "server-1", "server-2", "agent-0", "agent-1"] | ||
NODE_BOXES = ['generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004', 'generic/ubuntu2004'] | ||
NODE_CPUS = 2 | ||
NODE_MEMORY = 2048 | ||
# Virtualbox >= 6.1.28 require `/etc/vbox/network.conf` for expanded private networks | ||
NETWORK_PREFIX = "10.10.10" | ||
|
||
def provision(vm, role, node_num) | ||
vm.box = NODE_BOXES[node_num] | ||
vm.hostname = role | ||
# We use a private network because the default IPs are dynamicly assigned | ||
# during provisioning. This makes it impossible to know the server-0 IP when | ||
# provisioning subsequent servers and agents. A private network allows us to | ||
# assign static IPs to each node, and thus provide a known IP for the API endpoint. | ||
node_ip = "#{NETWORK_PREFIX}.#{100+node_num}" | ||
# An expanded netmask is required to allow VM<-->VM communication, virtualbox defaults to /32 | ||
vm.network "private_network", ip: node_ip, netmask: "255.255.255.0" | ||
|
||
vm.provision "ansible", run: 'once' do |ansible| | ||
ansible.compatibility_mode = "2.0" | ||
ansible.playbook = "playbook/site.yml" | ||
ansible.groups = { | ||
"server" => NODE_ROLES.grep(/^server/), | ||
"agent" => NODE_ROLES.grep(/^agent/), | ||
"k3s_cluster:children" => ["server", "agent"], | ||
} | ||
ansible.extra_vars = { | ||
k3s_version: "v1.26.5+k3s1", | ||
api_endpoint: "#{NETWORK_PREFIX}.100", | ||
token: "myvagrant", | ||
# Required to use the private network configured above | ||
extra_server_args: "--node-external-ip #{node_ip} --flannel-iface eth1", | ||
extra_agent_args: "--node-external-ip #{node_ip} --flannel-iface eth1", | ||
} | ||
end | ||
end | ||
|
||
Vagrant.configure("2") do |config| | ||
# Default provider is libvirt, virtualbox is only provided as a backup | ||
config.vm.provider "libvirt" do |v| | ||
v.cpus = NODE_CPUS | ||
v.memory = NODE_MEMORY | ||
end | ||
config.vm.provider "virtualbox" do |v| | ||
v.cpus = NODE_CPUS | ||
v.memory = NODE_MEMORY | ||
end | ||
|
||
NODE_ROLES.each_with_index do |name, i| | ||
config.vm.define name do |node| | ||
provision(node.vm, name, i) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,17 @@ | ||
--- | ||
- name: Download k3s binary x64 | ||
- name: Download k3s install script | ||
ansible.builtin.get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt | ||
url: https://get.k3s.io/ | ||
timeout: 120 | ||
dest: /usr/local/bin/k3s | ||
dest: /usr/local/bin/k3s-install.sh | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: ansible_facts.architecture == "x86_64" | ||
|
||
- name: Download k3s binary arm64 | ||
ansible.builtin.get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64 | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm64.txt | ||
timeout: 120 | ||
dest: /usr/local/bin/k3s | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: | ||
- ( ansible_facts.architecture is search("arm") and | ||
ansible_facts.userspace_bits == "64" ) or | ||
ansible_facts.architecture is search("aarch64") | ||
|
||
- name: Download k3s binary armhf | ||
ansible.builtin.get_url: | ||
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-armhf | ||
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm.txt | ||
timeout: 120 | ||
dest: /usr/local/bin/k3s | ||
owner: root | ||
group: root | ||
mode: 0755 | ||
when: | ||
- ansible_facts.architecture is search("arm") | ||
- ansible_facts.userspace_bits == "32" | ||
- name: Download k3s binary | ||
ansible.builtin.command: | ||
cmd: /usr/local/bin/k3s-install.sh | ||
environment: | ||
INSTALL_K3S_SKIP_START: "true" | ||
INSTALL_K3S_VERSION: "{{ k3s_version }}" | ||
changed_when: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
k3s_server_location: "/var/lib/rancher/k3s" | ||
systemd_dir: "/etc/systemd/system" | ||
api_port: 6443 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
k3s_server_location: "/var/lib/rancher/k3s" | ||
systemd_dir: "/etc/systemd/system" | ||
api_port: 6443 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.