-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bae568
commit 58a84d8
Showing
5 changed files
with
180 additions
and
7 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,78 @@ | ||
--- | ||
- hosts: 'terraclu-k8s-node-1, terraclu-k8s-master-1 ' | ||
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.22.0-00 kubeadm=1.22.0-00 kubectl=1.22.0-00 | ||
sudo apt-mark hold kubelet kubeadm kubectl | ||
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,48 @@ | ||
- hosts: 'terraclu-k8s-master-1 ' | ||
become: yes | ||
tasks: | ||
- name: change docker driver | ||
shell: | | ||
cat <<EOF | sudo tee /etc/docker/daemon.json | ||
{"exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts": {"max-size": "100m"},"storage-driver": "overlay2"} | ||
EOF | ||
- name: update and reset the changes | ||
shell: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart docker | ||
sudo kubeadm reset -f | ||
- name: initialize the cluster | ||
shell: sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --kubernetes-version 1.22.0 | ||
args: | ||
chdir: $HOME | ||
creates: cluster_initialized.txt | ||
|
||
- name: for accessing kubectl | ||
shell: | | ||
mkdir -p $HOME/.kube | ||
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config | ||
sudo chown $(id -u):$(id -g) $HOME/.kube/config | ||
- name: install Pod network | ||
become: yes | ||
become_user: kube | ||
shell: sudo kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml | ||
args: | ||
chdir: $HOME | ||
|
||
- name: Get the token for joining the worker nodes | ||
become: yes | ||
become_user: kube | ||
shell: sudo kubeadm token create --print-join-command | ||
register: kubernetes_join_command | ||
|
||
- debug: | ||
msg: "{{ kubernetes_join_command.stdout }}" | ||
|
||
- name: Copy join command to local file. | ||
become: yes | ||
local_action: copy content="{{ kubernetes_join_command.stdout_lines[0] }}" dest="/tmp/kubernetes_join_command" mode=0777 |
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,17 @@ | ||
- hosts: 'terraclu-k8s-node-1, terraclu-k8s-master-1 ' | ||
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 |
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,27 @@ | ||
- hosts: 'terraclu-k8s-node-1 ' | ||
become: yes | ||
gather_facts: yes | ||
|
||
tasks: | ||
- name: change docker driver | ||
shell: | | ||
cat <<EOF | sudo tee /etc/docker/daemon.json | ||
{"exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts": {"max-size": "100m"},"storage-driver": "overlay2"} EOF | ||
- name: update and reset the changes | ||
shell: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart docker | ||
sudo kubeadm reset -f | ||
- name: Copy join command from Ansiblehost to the worker nodes. | ||
become: yes | ||
copy: | ||
src: /tmp/kubernetes_join_command | ||
dest: /tmp/kubernetes_join_command | ||
mode: 0777 | ||
|
||
- name: Join the Worker nodes to the cluster. | ||
become: yes | ||
command: sh /tmp/kubernetes_join_command | ||
register: joined_or_not |