Skip to content

Commit

Permalink
Adding Ansible files and directory
Browse files Browse the repository at this point in the history
  • Loading branch information
orenzp committed Jul 14, 2021
1 parent 0315cdb commit df50f76
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Lint
'on':
pull_request:
push:
branches:
- master

jobs:

test:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.7.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint ansible-lint ansible

- name: Run yamllint.
run: yamllint .

- name: Run ansible-lint.
run: ansible-lint
12 changes: 12 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[defaults]
nocows = True
roles_path = ./roles
inventory = ./hosts.ini

remote_tmp = $HOME/.ansible/tmp
local_tmp = $HOME/.ansible/tmp
pipelining = True
become = True
host_key_checking = False
deprecation_warnings = False
callback_whitelist = profile_tasks
10 changes: 10 additions & 0 deletions ansible/hosts.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[masters]
K8S01 ansible_host=192.168.1.11 ansible_user=ubuntu

[workers]
K8S02 ansible_host=192.168.1.12 ansible_user=ubuntu
K8S03 ansible_host=192.168.1.13 ansible_user=ubuntu

[k3s_cluster:children]
masters
workers
78 changes: 78 additions & 0 deletions ansible/k3s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
- hosts: "masters, workers"
remote_user: ubuntu
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh

tasks:
- name: Create containerd config file
file:
path: "/etc/modules-load.d/containerd.conf"
state: "touch"


- name: Add conf for containerd
blockinfile:
path: "/etc/modules-load.d/containerd.conf"
block: |
overlay
br_netfilter
- name: modprobe
shell: |
sudo modprobe overlay
sudo modprobe br_netfilter
- name: Set system configurations for Kubernetes networking
file:
path: "/etc/sysctl.d/99-kubernetes-cri.conf"
state: "touch"

- name: Add conf for containerd
blockinfile:
path: "/etc/sysctl.d/99-kubernetes-cri.conf"
block: |
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
- name: Apply new settings
command: sudo sysctl --system

- name: install containerd
shell: |
sudo apt-get update && sudo apt-get install -y containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl restart containerd
- name: disable swap
shell: |
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
- name: install and configure dependencies
shell: |
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- name: Create kubernetes repo file
file:
path: "/etc/apt/sources.list.d/kubernetes.list"
state: "touch"

- name: Add K8s Source
blockinfile:
path: "/etc/apt/sources.list.d/kubernetes.list"
block: |
deb https://apt.kubernetes.io/ kubernetes-xenial main
- name: install kubernetes
shell: |
sudo apt-get update
sudo apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00
sudo apt-mark hold kubelet kubeadm kubectl
18 changes: 18 additions & 0 deletions ansible/users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- hosts: 'workers, masters'
become: yes

tasks:
- name: create the kube user account
user: name=kube append=yes state=present createhome=yes shell=/bin/bash

- name: allow 'kube' to use sudo without needing a password
lineinfile:
dest: /etc/sudoers
line: 'kube ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'

- name: set up authorized keys for the kube user
authorized_key: user=kube key="{{item}}"
with_file:
- ~/.ssh/id_rsa.pub

0 comments on commit df50f76

Please sign in to comment.