Skip to content

Commit eeae3aa

Browse files
authored
Add config.yml
1 parent 2356def commit eeae3aa

File tree

5 files changed

+87
-86
lines changed

5 files changed

+87
-86
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ For more detailed information about kubespray, you can review the [official docu
1010

1111
Before you begin, make sure you have the following prerequisites installed on your machine:
1212

13-
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads) _(I tested it with version `6.1.44 r156814`)_
14-
- [Vagrant](https://developer.hashicorp.com/vagrant/downloads) _(I tested it with version `2.3.6`)_
13+
- [VirtualBox](https://www.virtualbox.org/wiki/Downloads) _(Tested on version `6.1.44 r156814`)_
14+
- [Vagrant](https://developer.hashicorp.com/vagrant/downloads) _(Tested on version `2.3.6`)_
1515

1616
## Getting Started
1717

18+
Review the [`config.yml`](config.yml) file and make any changes you need. After that:
19+
1820
```bash
1921
vagrant up
2022
```
2123

22-
## Quick Details
23-
24-
1. Customize the VM by reviewing the [`vagrant/utilities.rb`](vagrant/utilities.rb) file for options like CPU, memory, and OS.
25-
26-
1. To override the values you want in the `kubespray` project, review the [`ansible/extra-vars.yml`](ansible/extra-vars.yml) file.
27-
2824
## Contribution
2925

3026
[Pull requests](https://github.com/m18unet/kubespray-single-node/compare) are welcome! Feel free to contribute and improve the project by submitting your changes.

Vagrantfile

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
# vi: set ft=ruby :
33

44
Vagrant.require_version ">= 2.1.0", "< 3.0.0"
5-
65
require 'yaml'
7-
require_relative 'vagrant/utilities.rb'
6+
7+
# Import configuration from config.yml
8+
cfg = YAML.load_file("config.yml")['vagrant']
9+
10+
# Check if the VM operating system is supported
11+
SUPPORTED_OS = {
12+
"debian11" => { :box => "generic/debian11", :version => "4.2.16" },
13+
"ubuntu2204" => { :box => "generic/ubuntu2204", :version => "4.2.16" },
14+
}
15+
16+
if ! SUPPORTED_OS.key?(cfg['vm_os'])
17+
puts "Unsupported OS : '#{cfg['vm_os']}'"
18+
supported_os_list = SUPPORTED_OS.keys.map { |os| "'#{os}'" }
19+
puts "Supported OS are : #{supported_os_list.join(', ')}"
20+
exit 1
21+
end
822

923
Vagrant.configure("2") do |config|
10-
config.vm.box = SUPPORTED_OS[VM_OS_NAME][:box]
11-
config.vm.box_version = SUPPORTED_OS[VM_OS_NAME][:version]
24+
config.vm.box = SUPPORTED_OS[cfg['vm_os']][:box]
25+
config.vm.box_version = SUPPORTED_OS[cfg['vm_os']][:version]
1226

1327
config.vm.provider "virtualbox"
1428
config.vm.synced_folder ".", "/vagrant"
@@ -17,11 +31,11 @@ Vagrant.configure("2") do |config|
1731

1832
config.vm.define "node1"
1933
config.vm.hostname = "node1"
20-
config.vm.network :private_network, ip: VM_IP_ADDR
34+
config.vm.network :private_network, ip: cfg['vm_ip_addr']
2135

2236
config.vm.provider :virtualbox do |vb|
23-
vb.cpus = VM_CPUS
24-
vb.memory = VM_MEMORY
37+
vb.cpus = cfg['vm_cpus']
38+
vb.memory = cfg['vm_memory']
2539
vb.name = "kubespray-single-node_node1"
2640
vb.gui = false
2741
vb.linked_clone = true
@@ -30,26 +44,26 @@ Vagrant.configure("2") do |config|
3044

3145
config.vm.provision "init", type: "shell", privileged: true, run: "once", inline: <<-SHELL
3246
set -eu -o pipefail
33-
git clone https://github.com/kubernetes-sigs/kubespray.git "#{KUBESPRAY_DIR}" \
34-
--branch "#{KUBESPRAY_VERSION}" \
47+
git clone https://github.com/kubernetes-sigs/kubespray.git "#{cfg['kubespray_dir']}" \
48+
--branch "v#{cfg['kubespray_version']}" \
3549
--depth=1 \
36-
--single-branch 2> /dev/null || (cd "#{KUBESPRAY_DIR}" && git pull)
37-
chown -R "#{VM_USERNAME}:#{VM_USERNAME}" "#{KUBESPRAY_DIR}"
50+
--single-branch 2> /dev/null || (cd "#{cfg['kubespray_dir']}" && git pull)
51+
chown -R "#{cfg['vm_username']}:#{cfg['vm_username']}" "#{cfg['kubespray_dir']}"
3852
SHELL
3953

4054
config.vm.provision "ansible_local" do |ansible|
4155
ansible.install = true
4256
ansible.install_mode = "pip_args_only"
4357
ansible.compatibility_mode = "2.0"
44-
ansible.pip_args = "-r #{KUBESPRAY_DIR}/requirements.txt"
58+
ansible.pip_args = "-r #{cfg['kubespray_dir']}/requirements.txt"
4559

46-
ansible.provisioning_path = KUBESPRAY_DIR
60+
ansible.provisioning_path = cfg['kubespray_dir']
4761
ansible.config_file = "ansible.cfg"
4862
ansible.inventory_path = "inventory/local/hosts.ini"
4963
ansible.limit = "node1"
5064
ansible.playbook = "cluster.yml"
51-
ansible.extra_vars = {"ip": VM_IP_ADDR}.merge(YAML.load(File.read("ansible/extra-vars.yml")))
52-
# ansible.tags = ["ingress-controller"]
65+
ansible.extra_vars = {"ip": cfg['vm_ip_addr']}.merge(YAML.load(File.read("config.yml")))['ansible']['extra_vars']
66+
# ansible.tags = ['ingress-controller']
5367
ansible.become = true
5468
ansible.become_user = "root"
5569

@@ -60,13 +74,13 @@ Vagrant.configure("2") do |config|
6074
config.vm.provision "post", type: "shell", privileged: true, run: "once", inline: <<-SHELL
6175
set -eu -o pipefail
6276
63-
KUBE_DIR="/home/#{VM_USERNAME}/.kube"
64-
mkdir -p $KUBE_DIR
65-
chmod 755 $KUBE_DIR
77+
KUBE_DIR="/home/#{cfg['vm_username']}/.kube"
78+
mkdir -p ${KUBE_DIR}
79+
chmod 755 ${KUBE_DIR}
6680
67-
ln -s /etc/kubernetes/admin.conf $KUBE_DIR/config -f
68-
chown -R "#{VM_USERNAME}:#{VM_USERNAME}" $KUBE_DIR
69-
chmod 644 $KUBE_DIR/config
81+
ln -s /etc/kubernetes/admin.conf ${KUBE_DIR}/config -f
82+
chown -R "#{cfg['vm_username']}:#{cfg['vm_username']}" ${KUBE_DIR}
83+
chmod 644 ${KUBE_DIR}/config
7084
7185
echo -e "alias k=kubectl" > /etc/profile.d/kubectl.sh
7286
echo -e "complete -o default -F __start_kubectl k" >> /etc/profile.d/kubectl.sh

ansible/extra-vars.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

config.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
vagrant:
3+
vm_cpus: 4
4+
vm_memory: 8192
5+
vm_ip_addr: '10.10.22.57'
6+
vm_username: vagrant
7+
vm_os: debian11 # NOTE: Check the Vagrantfile to see SUPPORTED_OS
8+
kubespray_version: '2.22.1'
9+
kubespray_dir: /opt/kubespray
10+
11+
ansible:
12+
extra_vars:
13+
kube_version: v1.26.5
14+
cluster_name: cluster.local
15+
container_manager: containerd
16+
etcd_deployment_type: kubeadm
17+
18+
kube_proxy_mode: iptables
19+
kube_network_plugin: flannel
20+
flannel_interface: eth1
21+
flannel_backend_type: host-gw
22+
23+
kube_service_addresses: 10.233.0.0/18
24+
kube_pods_subnet: 10.233.64.0/18
25+
26+
enable_nodelocaldns: false
27+
helm_enabled: true
28+
krew_enabled: true
29+
metrics_server_enabled: true
30+
31+
local_path_provisioner_enabled: true
32+
local_path_provisioner_namespace: platform
33+
34+
ingress_nginx_enabled: true
35+
ingress_nginx_host_network: true
36+
ingress_nginx_namespace: platform
37+
ingress_nginx_class: nginx
38+
39+
ntp_enabled: true
40+
ntp_manage_config: true
41+
ntp_servers:
42+
- "0.pool.ntp.org iburst"
43+
- "1.pool.ntp.org iburst"
44+
- "2.pool.ntp.org iburst"
45+
- "3.pool.ntp.org iburst"
46+
47+
override_system_hostname: false
48+
auto_renew_certificates: true

vagrant/utilities.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)