diff --git a/z2/k8s_manual/.vagrant/bundler/global.sol b/z2/k8s_manual/.vagrant/bundler/global.sol new file mode 100644 index 0000000..44881c1 --- /dev/null +++ b/z2/k8s_manual/.vagrant/bundler/global.sol @@ -0,0 +1 @@ +{"dependencies":[["racc",["~> 1.4"]],["nokogiri",["~> 1.6"]],["diffy",[">= 0"]],["rexml",[">= 0"]],["xml-simple",[">= 0"]],["logger",[">= 0"]],["mime-types-data",["~> 3.2025",">= 3.2025.0507"]],["mime-types",[">= 0"]],["io-console",["~> 0.5"]],["reline",[">= 0"]],["formatador",[">= 0.2","< 2.0"]],["excon",["~> 1.0"]],["builder",[">= 0"]],["fog-core",["~> 2"]],["ruby-libvirt",[">= 0.7.0"]],["json",[">= 0"]],["fog-xml",["~> 0.1.1"]],["multi_json",["~> 1.10"]],["fog-json",[">= 0"]],["fog-libvirt",[">= 0.6.0"]],["vagrant-libvirt",["= 0.12.2"]]],"checksum":"b69e3c206e3d26fb25b062fbb15a80865764c5efb5e9cce85cfac1f745449033","vagrant_version":"2.4.9"} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/action_provision b/z2/k8s_manual/.vagrant/machines/master/libvirt/action_provision new file mode 100644 index 0000000..09d400e --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/action_provision @@ -0,0 +1 @@ +1.5:fb1ee880-af31-47e4-8257-9b6942229d85 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/box_meta b/z2/k8s_manual/.vagrant/machines/master/libvirt/box_meta new file mode 100644 index 0000000..9044db5 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/box_meta @@ -0,0 +1 @@ +{"name":"generic/ubuntu2204","version":"4.3.12","provider":"libvirt","directory":"boxes/generic-VAGRANTSLASH-ubuntu2204/4.3.12/amd64/libvirt"} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/created_networks b/z2/k8s_manual/.vagrant/machines/master/libvirt/created_networks new file mode 100644 index 0000000..1f1e8ea --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/created_networks @@ -0,0 +1,16 @@ +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/creator_uid b/z2/k8s_manual/.vagrant/machines/master/libvirt/creator_uid new file mode 100644 index 0000000..e37d32a --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/creator_uid @@ -0,0 +1 @@ +1000 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/id b/z2/k8s_manual/.vagrant/machines/master/libvirt/id new file mode 100644 index 0000000..b6f5b55 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/id @@ -0,0 +1 @@ +fb1ee880-af31-47e4-8257-9b6942229d85 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/index_uuid b/z2/k8s_manual/.vagrant/machines/master/libvirt/index_uuid new file mode 100644 index 0000000..96affb8 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/index_uuid @@ -0,0 +1 @@ +021e3e0b226f406aac0bd39cd4969856 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/private_key b/z2/k8s_manual/.vagrant/machines/master/libvirt/private_key new file mode 100644 index 0000000..1f7bab0 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/private_key @@ -0,0 +1,8 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAA +AAtzc2gtZWQyNTUxOQAAACBS02VuYXy2eHhr3mUHj91WhrbQRF62QC5ulUeR +IK46KAAAAJD85A88/OQPPAAAAAtzc2gtZWQyNTUxOQAAACBS02VuYXy2eHhr +3mUHj91WhrbQRF62QC5ulUeRIK46KAAAAEBXYMaWzuG4tZdGHqPkk3q8jKE1 +NfvBVHJutsnBhtUTEFLTZW5hfLZ4eGveZQeP3VaGttBEXrZALm6VR5Egrjoo +AAAAB3ZhZ3JhbnQBAgMEBQY= +-----END OPENSSH PRIVATE KEY----- diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/synced_folders b/z2/k8s_manual/.vagrant/machines/master/libvirt/synced_folders new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/synced_folders @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/master/libvirt/vagrant_cwd b/z2/k8s_manual/.vagrant/machines/master/libvirt/vagrant_cwd new file mode 100644 index 0000000..f195687 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/master/libvirt/vagrant_cwd @@ -0,0 +1 @@ +/home/pavel/K8s_project/k8s_manual \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/action_provision b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/action_provision new file mode 100644 index 0000000..619aeb6 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/action_provision @@ -0,0 +1 @@ +1.5:e31b6a83-be42-4a1f-8afa-1241262e96df \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/box_meta b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/box_meta new file mode 100644 index 0000000..9044db5 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/box_meta @@ -0,0 +1 @@ +{"name":"generic/ubuntu2204","version":"4.3.12","provider":"libvirt","directory":"boxes/generic-VAGRANTSLASH-ubuntu2204/4.3.12/amd64/libvirt"} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/created_networks b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/created_networks new file mode 100644 index 0000000..1f1e8ea --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/created_networks @@ -0,0 +1,16 @@ +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/creator_uid b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/creator_uid new file mode 100644 index 0000000..e37d32a --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/creator_uid @@ -0,0 +1 @@ +1000 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/id b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/id new file mode 100644 index 0000000..236a25d --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/id @@ -0,0 +1 @@ +e31b6a83-be42-4a1f-8afa-1241262e96df \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/index_uuid b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/index_uuid new file mode 100644 index 0000000..0e62cdf --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/index_uuid @@ -0,0 +1 @@ +29daa6b87e3c4d6d90102d3ac373caae \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/private_key b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/private_key new file mode 100644 index 0000000..643df05 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/private_key @@ -0,0 +1,8 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAA +AAtzc2gtZWQyNTUxOQAAACBaK+qV9FCXssfPTv8IqW5VbEOOedFnsVP4MVrp +9qKQdAAAAJDqn/Ty6p/08gAAAAtzc2gtZWQyNTUxOQAAACBaK+qV9FCXssfP +Tv8IqW5VbEOOedFnsVP4MVrp9qKQdAAAAEBzm/9P82nTcicTfT0y+Ni3iPwE +c+AMggac/Ni1eDipeFor6pX0UJeyx89O/wipblVsQ4550WexU/gxWun2opB0 +AAAAB3ZhZ3JhbnQBAgMEBQY= +-----END OPENSSH PRIVATE KEY----- diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/synced_folders b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/synced_folders new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/synced_folders @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/vagrant_cwd b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/vagrant_cwd new file mode 100644 index 0000000..f195687 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-1/libvirt/vagrant_cwd @@ -0,0 +1 @@ +/home/pavel/K8s_project/k8s_manual \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/action_provision b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/action_provision new file mode 100644 index 0000000..d6f3cdf --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/action_provision @@ -0,0 +1 @@ +1.5:4bf079f3-c084-4087-a83f-97a585c3d705 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/box_meta b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/box_meta new file mode 100644 index 0000000..9044db5 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/box_meta @@ -0,0 +1 @@ +{"name":"generic/ubuntu2204","version":"4.3.12","provider":"libvirt","directory":"boxes/generic-VAGRANTSLASH-ubuntu2204/4.3.12/amd64/libvirt"} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/created_networks b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/created_networks new file mode 100644 index 0000000..1f1e8ea --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/created_networks @@ -0,0 +1,16 @@ +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 +a4ec2c9f-4014-4a68-a3a4-2a944bce1750 +68e2412b-1309-40a6-98f9-e7274b6a0604 diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/creator_uid b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/creator_uid new file mode 100644 index 0000000..e37d32a --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/creator_uid @@ -0,0 +1 @@ +1000 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/id b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/id new file mode 100644 index 0000000..d377037 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/id @@ -0,0 +1 @@ +4bf079f3-c084-4087-a83f-97a585c3d705 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/index_uuid b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/index_uuid new file mode 100644 index 0000000..0304fea --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/index_uuid @@ -0,0 +1 @@ +87c47bfa3e15444fb3943a829ffac979 \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/private_key b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/private_key new file mode 100644 index 0000000..936dde8 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/private_key @@ -0,0 +1,8 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAA +AAtzc2gtZWQyNTUxOQAAACDVc9ubngiOpSM6dPy43qqtGWfoM4wg3G+cp+3g +OVE3ZgAAAJC/UjXAv1I1wAAAAAtzc2gtZWQyNTUxOQAAACDVc9ubngiOpSM6 +dPy43qqtGWfoM4wg3G+cp+3gOVE3ZgAAAECQ0UWHxmdvU+y4URXN7VJvOLco +IqGP55L4DDr0WIC5hNVz25ueCI6lIzp0/Ljeqq0ZZ+gzjCDcb5yn7eA5UTdm +AAAAB3ZhZ3JhbnQBAgMEBQY= +-----END OPENSSH PRIVATE KEY----- diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/synced_folders b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/synced_folders new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/synced_folders @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/vagrant_cwd b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/vagrant_cwd new file mode 100644 index 0000000..f195687 --- /dev/null +++ b/z2/k8s_manual/.vagrant/machines/worker-2/libvirt/vagrant_cwd @@ -0,0 +1 @@ +/home/pavel/K8s_project/k8s_manual \ No newline at end of file diff --git a/z2/k8s_manual/.vagrant/rgloader/loader.rb b/z2/k8s_manual/.vagrant/rgloader/loader.rb new file mode 100644 index 0000000..b6c81bf --- /dev/null +++ b/z2/k8s_manual/.vagrant/rgloader/loader.rb @@ -0,0 +1,12 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +# This file loads the proper rgloader/loader.rb file that comes packaged +# with Vagrant so that encoded files can properly run with Vagrant. + +if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] + require File.expand_path( + "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]) +else + raise "Encoded files can't be read outside of the Vagrant installer." +end diff --git a/z2/k8s_manual/Vagrantfile b/z2/k8s_manual/Vagrantfile new file mode 100644 index 0000000..520707c --- /dev/null +++ b/z2/k8s_manual/Vagrantfile @@ -0,0 +1,20 @@ +Vagrant.configure("2") do |config| + config.vm.box = "generic/ubuntu2204" + + nodes = [ + { name: "master", ip: "192.168.56.10", mem: 3072, cpus: 2 }, + { name: "worker-1", ip: "192.168.56.11", mem: 3072, cpus: 2 }, + { name: "worker-2", ip: "192.168.56.12", mem: 3072, cpus: 2 } + ] + + nodes.each do |node| + config.vm.define node[:name] do |n| + n.vm.hostname = node[:name] + n.vm.network "private_network", ip: node[:ip], libvirt__forward_mode: "nat" + n.vm.provider :libvirt do |v| + v.memory = node[:mem] + v.cpus = node[:cpus] + end + end + end +end diff --git a/z2/k8s_manual/ansible.cfg b/z2/k8s_manual/ansible.cfg new file mode 100644 index 0000000..4dd424d --- /dev/null +++ b/z2/k8s_manual/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +inventory = inventory.ini +host_key_checking = False diff --git a/z2/k8s_manual/inventory.ini b/z2/k8s_manual/inventory.ini new file mode 100644 index 0000000..4e4a1f1 --- /dev/null +++ b/z2/k8s_manual/inventory.ini @@ -0,0 +1,11 @@ +[master] +master ansible_host=192.168.56.10 + +[workers] +worker-1 ansible_host=192.168.56.11 +worker-2 ansible_host=192.168.56.12 + +[all:vars] +ansible_user=vagrant +ansible_ssh_private_key_file=.vagrant/machines/{{ inventory_hostname }}/libvirt/private_key +ansible_ssh_common_args='-o StrictHostKeyChecking=no' diff --git a/z2/k8s_manual/k8s-setup.yml b/z2/k8s_manual/k8s-setup.yml new file mode 100644 index 0000000..c3597c4 --- /dev/null +++ b/z2/k8s_manual/k8s-setup.yml @@ -0,0 +1,18 @@ +--- +- name: Prepare K8s nodes + hosts: all + become: true + roles: + - common + +- name: Configure Master node + hosts: master + become: true + roles: + - master + +- name: Configure Worker nodes + hosts: workers + become: true + roles: + - worker diff --git a/z2/k8s_manual/roles/common/README.md b/z2/k8s_manual/roles/common/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/z2/k8s_manual/roles/common/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/z2/k8s_manual/roles/common/defaults/main.yml b/z2/k8s_manual/roles/common/defaults/main.yml new file mode 100644 index 0000000..236d282 --- /dev/null +++ b/z2/k8s_manual/roles/common/defaults/main.yml @@ -0,0 +1,30 @@ +--- +k8s_version: "1.31" +k8s_package_version: "1.31.14-1.1" + +k8s_kernel_modules: + - overlay + - br_netfilter + +k8s_sysctl_params: + - { name: "net.bridge.bridge-nf-call-iptables", value: "1" } + - { name: "net.bridge.bridge-nf-call-ip6tables", value: "1" } + - { name: "net.ipv4.ip_forward", value: "1" } + +k8s_required_packages: + - containerd + - conntrack + - socat + - apt-transport-https + - curl + +k8s_packages: + - kubelet + - kubeadm + - kubectl + +containerd_config_path: /etc/containerd/config.toml + +k8s_gpg_key_url: "https://pkgs.k8s.io/core:/stable:/v{{ k8s_version }}/deb/Release.key" +k8s_gpg_keyring: /etc/apt/keyrings/kubernetes-apt-keyring.gpg +k8s_repo: "deb [signed-by={{ k8s_gpg_keyring }}] https://pkgs.k8s.io/core:/stable:/v{{ k8s_version }}/deb/ /" diff --git a/z2/k8s_manual/roles/common/handlers/main.yml b/z2/k8s_manual/roles/common/handlers/main.yml new file mode 100644 index 0000000..ae9c7ca --- /dev/null +++ b/z2/k8s_manual/roles/common/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for common +- name: Restart Containerd + service: name=containerd state=restarted diff --git a/z2/k8s_manual/roles/common/meta/main.yml b/z2/k8s_manual/roles/common/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/z2/k8s_manual/roles/common/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/z2/k8s_manual/roles/common/tasks/main.yml b/z2/k8s_manual/roles/common/tasks/main.yml new file mode 100644 index 0000000..7a26087 --- /dev/null +++ b/z2/k8s_manual/roles/common/tasks/main.yml @@ -0,0 +1,84 @@ +--- +- name: Disable SWAP + shell: | + swapoff -a + sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab + +- name: Mask swap.target to prevent swap after reboot + systemd: + name: swap.target + masked: yes + +- name: Load kernel modules + modprobe: + name: "{{ item }}" + state: present + loop: "{{ k8s_kernel_modules }}" + +- name: Persist kernel modules across reboots + copy: + dest: /etc/modules-load.d/k8s.conf + content: "{% for mod in k8s_kernel_modules %}{{ mod }}\n{% endfor %}" + +- name: Set sysctl parameters + sysctl: + name: "{{ item.name }}" + value: "{{ item.value }}" + state: present + sysctl_file: /etc/sysctl.d/k8s.conf + reload: yes + loop: "{{ k8s_sysctl_params }}" + +- name: Install containerd & utils + apt: + name: "{{ k8s_required_packages }}" + state: present + update_cache: yes + +- name: Check if containerd is already configured + stat: + path: "{{ containerd_config_path }}" + register: containerd_config + +- name: Generate default containerd config + shell: | + mkdir -p /etc/containerd + containerd config default > {{ containerd_config_path }} + when: not containerd_config.stat.exists + notify: Restart Containerd + +- name: Enable systemdCgroup in containerd + replace: + path: "{{ containerd_config_path }}" + regexp: "SystemdCgroup = false" + replace: "SystemdCgroup = true" + notify: Restart Containerd + +- name: Download K8s GPG key + get_url: + url: "{{ k8s_gpg_key_url }}" + dest: "{{ k8s_gpg_keyring | regex_replace('.gpg$', '.asc') }}" + mode: "0644" + +- name: Dearmor K8s GPG key + shell: "gpg --dearmor -o {{ k8s_gpg_keyring }} {{ k8s_gpg_keyring | regex_replace('.gpg$', '.asc') }}" + args: + creates: "{{ k8s_gpg_keyring }}" + +- name: Add K8s repository + apt_repository: + repo: "{{ k8s_repo }}" + state: present + filename: kubernetes + +- name: Install K8s tools + apt: + name: "{{ k8s_packages | map('regex_replace', '$', '=' + k8s_package_version) | list }}" + state: present + update_cache: yes + +- name: Hold K8s packages at current version + dpkg_selections: + name: "{{ item }}" + selection: hold + loop: "{{ k8s_packages }}" diff --git a/z2/k8s_manual/roles/common/tests/inventory b/z2/k8s_manual/roles/common/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/z2/k8s_manual/roles/common/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/z2/k8s_manual/roles/common/tests/test.yml b/z2/k8s_manual/roles/common/tests/test.yml new file mode 100644 index 0000000..31cf1ac --- /dev/null +++ b/z2/k8s_manual/roles/common/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - common diff --git a/z2/k8s_manual/roles/common/vars/main.yml b/z2/k8s_manual/roles/common/vars/main.yml new file mode 100644 index 0000000..fed6035 --- /dev/null +++ b/z2/k8s_manual/roles/common/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for common diff --git a/z2/k8s_manual/roles/master/README.md b/z2/k8s_manual/roles/master/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/z2/k8s_manual/roles/master/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/z2/k8s_manual/roles/master/defaults/main.yml b/z2/k8s_manual/roles/master/defaults/main.yml new file mode 100644 index 0000000..f839ca0 --- /dev/null +++ b/z2/k8s_manual/roles/master/defaults/main.yml @@ -0,0 +1,20 @@ +--- +# defaults file for master +master_apiserver_address: "192.168.56.10" +master_pod_network_cidr: "10.244.0.0/16" +master_user: vagrant + +flannel_manifest_url: "https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml" +metrics_server_manifest_url: "https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml" +metrics_server_insecure_tls: true +metrics_server_ready_retries: 20 +metrics_server_ready_delay: 10 + +master_remove_taint: true + +argocd_manifest_url: "https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml" +local_path_provisioner_url: "https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.35/deploy/local-path-storage.yaml" + +install_helm: "https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4" + +git_repo_url: "https://github.com/miracleqxz/K8s_project.git" diff --git a/z2/k8s_manual/roles/master/handlers/main.yml b/z2/k8s_manual/roles/master/handlers/main.yml new file mode 100644 index 0000000..e6ce833 --- /dev/null +++ b/z2/k8s_manual/roles/master/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for master diff --git a/z2/k8s_manual/roles/master/meta/main.yml b/z2/k8s_manual/roles/master/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/z2/k8s_manual/roles/master/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/z2/k8s_manual/roles/master/tasks/main.yml b/z2/k8s_manual/roles/master/tasks/main.yml new file mode 100644 index 0000000..25cc7b9 --- /dev/null +++ b/z2/k8s_manual/roles/master/tasks/main.yml @@ -0,0 +1,124 @@ +--- +# tasks file for master +- name: Initialize K8s cluster + shell: > + kubeadm init + --apiserver-advertise-address={{ master_apiserver_address }} + --pod-network-cidr={{ master_pod_network_cidr }} + args: + creates: /etc/kubernetes/admin.conf + +- name: Setup kubeconfig for {{ master_user }} + shell: | + mkdir -p /home/{{ master_user }}/.kube + cp -i /etc/kubernetes/admin.conf /home/{{ master_user }}/.kube/config + chown {{ master_user }}:{{ master_user }} /home/{{ master_user }}/.kube/config + args: + creates: "/home/{{ master_user }}/.kube/config" + +- name: Wait for API server to be ready + become: false + shell: kubectl cluster-info + register: api_check + until: api_check.rc == 0 + retries: 30 + delay: 10 + changed_when: false + +- name: Install Flannel CNI + become: false + shell: "kubectl apply -f {{ flannel_manifest_url }}" + +- name: Check if metrics server is installed + become: false + shell: kubectl get deployment metrics-server -n kube-system -o name + register: metrics_check + failed_when: false + changed_when: false + +- name: Remove taint + become: false + shell: "kubectl taint nodes {{ inventory_hostname }} node-role.kubernetes.io/control-plane:NoSchedule-" + register: taint_result + failed_when: taint_result.rc != 0 and 'not found' not in taint_result.stderr + changed_when: taint_result.rc == 0 + when: master_remove_taint + +- name: Install metrics server + become: false + shell: "kubectl apply -f {{ metrics_server_manifest_url }}" + when: metrics_check.rc != 0 + +- name: Check if insecure-tls flag is already set + become: false + shell: > + kubectl get deployment metrics-server -n kube-system + -o jsonpath='{.spec.template.spec.containers[0].args}' + register: metrics_args + changed_when: false + when: metrics_server_insecure_tls + +- name: Patch metrics server to allow insecure TLS + become: false + shell: > + kubectl patch deployment metrics-server -n kube-system --type='json' + -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]' + when: + - metrics_server_insecure_tls + - "'--kubelet-insecure-tls' not in metrics_args.stdout" + +- name: Wait for metrics server to be ready + become: false + shell: kubectl get deployment metrics-server -n kube-system -o jsonpath='{.status.readyReplicas}' + register: ready_replicas + until: ready_replicas.stdout == "1" + retries: "{{ metrics_server_ready_retries }}" + delay: "{{ metrics_server_ready_delay }}" + changed_when: false + +- name: Get join command + shell: kubeadm token create --print-join-command + register: join_command_raw + +- name: Set join command fact + set_fact: + join_command: "{{ join_command_raw.stdout }}" + +- name: Install Helm + shell: curl {{ install_helm }} | bash + args: + creates: /usr/local/bin/helm + +- name: Install local-path-provisioner + become: false + shell: kubectl apply -f {{ local_path_provisioner_url }} + +- name: Set local-path as default StorageClass + become: false + shell: > + kubectl patch storageclass local-path + -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' + +- name: Create argocd namespace + become: false + shell: kubectl create namespace argocd + register: argocd_ns + failed_when: argocd_ns.rc != 0 and 'already exists' not in argocd_ns.stderr + changed_when: argocd_ns.rc == 0 + +- name: Install ArgoCD + become: false + shell: kubectl apply -n argocd -f {{ argocd_manifest_url }} --server-side + +- name: Patch ArgoCD server to NodePort + become: false + shell: > + kubectl patch svc argocd-server -n argocd + -p '{"spec": {"type": "NodePort"}}' + +- name: Clone Git repository + git: + repo: "{{ git_repo_url }}" + dest: /home/{{ master_user }}/K8s_project + version: main + become: false diff --git a/z2/k8s_manual/roles/master/tests/inventory b/z2/k8s_manual/roles/master/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/z2/k8s_manual/roles/master/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/z2/k8s_manual/roles/master/tests/test.yml b/z2/k8s_manual/roles/master/tests/test.yml new file mode 100644 index 0000000..6331e5d --- /dev/null +++ b/z2/k8s_manual/roles/master/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - master diff --git a/z2/k8s_manual/roles/master/vars/main.yml b/z2/k8s_manual/roles/master/vars/main.yml new file mode 100644 index 0000000..16d64c7 --- /dev/null +++ b/z2/k8s_manual/roles/master/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for master diff --git a/z2/k8s_manual/roles/worker/README.md b/z2/k8s_manual/roles/worker/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/z2/k8s_manual/roles/worker/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/z2/k8s_manual/roles/worker/defaults/main.yml b/z2/k8s_manual/roles/worker/defaults/main.yml new file mode 100644 index 0000000..3659722 --- /dev/null +++ b/z2/k8s_manual/roles/worker/defaults/main.yml @@ -0,0 +1,3 @@ +--- +# defaults file for worker +master_hostname: master diff --git a/z2/k8s_manual/roles/worker/handlers/main.yml b/z2/k8s_manual/roles/worker/handlers/main.yml new file mode 100644 index 0000000..47e28d7 --- /dev/null +++ b/z2/k8s_manual/roles/worker/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for worker diff --git a/z2/k8s_manual/roles/worker/meta/main.yml b/z2/k8s_manual/roles/worker/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/z2/k8s_manual/roles/worker/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/z2/k8s_manual/roles/worker/tasks/main.yml b/z2/k8s_manual/roles/worker/tasks/main.yml new file mode 100644 index 0000000..5ee0676 --- /dev/null +++ b/z2/k8s_manual/roles/worker/tasks/main.yml @@ -0,0 +1,6 @@ +--- +# tasks file for worker +- name: Join Workers to cluster + shell: "{{ hostvars[master_hostname]['join_command'] }}" + args: + creates: /etc/kubernetes/kubelet.conf diff --git a/z2/k8s_manual/roles/worker/tests/inventory b/z2/k8s_manual/roles/worker/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/z2/k8s_manual/roles/worker/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/z2/k8s_manual/roles/worker/tests/test.yml b/z2/k8s_manual/roles/worker/tests/test.yml new file mode 100644 index 0000000..cec03c6 --- /dev/null +++ b/z2/k8s_manual/roles/worker/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - worker diff --git a/z2/k8s_manual/roles/worker/vars/main.yml b/z2/k8s_manual/roles/worker/vars/main.yml new file mode 100644 index 0000000..ac17343 --- /dev/null +++ b/z2/k8s_manual/roles/worker/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for worker