From 58a84d82b7d72a05dd0fee67fb6ce06a33a7827e Mon Sep 17 00:00:00 2001 From: GowthamChowta Date: Tue, 29 Mar 2022 12:31:05 -0400 Subject: [PATCH] Adding kubernetes setup files --- install-k8s.yml | 78 ++++++++++++++++++++++++++++++++++++++++++++ instance-creation.sh | 17 ++++++---- master.yml | 48 +++++++++++++++++++++++++++ users.yml | 17 ++++++++++ workers.yml | 27 +++++++++++++++ 5 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 install-k8s.yml create mode 100644 master.yml create mode 100644 users.yml create mode 100644 workers.yml diff --git a/install-k8s.yml b/install-k8s.yml new file mode 100644 index 0000000..188d29c --- /dev/null +++ b/install-k8s.yml @@ -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 + diff --git a/instance-creation.sh b/instance-creation.sh index 9d79ca3..51f8cd5 100644 --- a/instance-creation.sh +++ b/instance-creation.sh @@ -10,12 +10,15 @@ sudo chmod +x terraform && sudo cp terraform /usr/local/bin/ && sudo mv terraform /usr/bin/ && rm -rf terraform_0.14.4_linux_amd64.zip && +# Change the directory +cd jetstream_kubespray && +# Export cluser name +export CLUSTER=terraclu && +cp -r inventory/kubejetstream inventory/$CLUSTER && +cd inventory/$CLUSTER && +# Update the IP address you have provided +sed -i '/k8s_master_fips/c\k8s_master_fips =["'$IP'"]' cluster.tfvars && -export CLUSTER=terraclu -cp -r inventory/kubejetstream inventory/$CLUSTER -cd inventory/$CLUSTER -sed -i '/k8s_master_fips/c\k8s_master_fips "=['$IP']"' cluster.tfvars - -bash terraform_init.sh -bash terraform_apply.sh +bash terraform_init.sh && +bash terraform_apply.sh && diff --git a/master.yml b/master.yml new file mode 100644 index 0000000..5ec2a0b --- /dev/null +++ b/master.yml @@ -0,0 +1,48 @@ +- hosts: 'terraclu-k8s-master-1 ' + become: yes + tasks: + - name: change docker driver + shell: | + cat <