Skip to content

Instantly share code, notes, and snippets.

@LarsNieuwenhuizen
Created April 19, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsNieuwenhuizen/03c224e50871e123e4376f0518083cb1 to your computer and use it in GitHub Desktop.
Save LarsNieuwenhuizen/03c224e50871e123e4376f0518083cb1 to your computer and use it in GitHub Desktop.
K3S installation setup with Ansible
[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
---
- 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