Created
April 19, 2020 10:23
-
-
Save LarsNieuwenhuizen/03c224e50871e123e4376f0518083cb1 to your computer and use it in GitHub Desktop.
K3S installation setup with Ansible
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
[cluster] | |
kubemaster ansible_host=192.168.2.40 ansible_user=pi | |
worker-1 ansible_host=192.168.2.41 ansible_user=pi | |
worker-2 ansible_host=192.168.2.42 ansible_user=pi | |
worker-3 ansible_host=192.168.2.43 ansible_user=pi | |
[cluster-masters] | |
kubemaster ansible_host=192.168.2.40 ansible_user=pi | |
[cluster-workers] | |
worker-1 ansible_host=192.168.2.41 ansible_user=pi | |
worker-2 ansible_host=192.168.2.42 ansible_user=pi | |
worker-3 ansible_host=192.168.2.43 ansible_user=pi |
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
--- | |
- name: Initialize k3s master nodes | |
hosts: cluster-masters | |
gather_facts: yes | |
tasks: | |
- name: Install and start k3s | |
shell: 'curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --docker --no-deploy traefik" sh' | |
- name: Get token | |
shell: 'cat /var/lib/rancher/k3s/server/node-token' | |
become: true | |
register: cluster_token | |
- name: Create facts | |
set_fact: | |
cluster_token: '{{ cluster_token.stdout }}' | |
- name: Starter workers | |
hosts: cluster-workers | |
gather_facts: yes | |
tasks: | |
- name: Start cluster worker node | |
shell: 'curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent --docker" K3S_URL=https://kubemaster:6443 K3S_TOKEN={{ hostvars.kubemaster.cluster_token }} sh' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment