Vagrantfile & Scripts to setup Kubernetes Cluster using Kubeadm for CKA, CKAD and CKS practice environment
Vagrantfile and Scripts to Automate Kubernetes Setup using Kubeadm [Practice Environment for CKA/CKAD and CKS Exams]
A fully automated setup for CKA, CKAD, and CKS practice labs is tested on the following systems:
- Windows
- Ubuntu Desktop
- Mac Intel-based systems
Kubernetes Certification Voucher (UpTo 38% OFF) 🎉
If you are learning Kubernetes and preparing for Kubernetes certifications, these voucher codes will help you save money on your certification registration.
CKA, CKAD, CKS, KCNA etc.. aspirants can save 30% today
[!IMPORTANT]
Use code DCUBE30 at https://kube.promo/devops. It is a limited-time offer from the Linux Foundation.
Use code DCUBE30 with the following bundles to save upto 38%
- CKA + CKAD: kube.promo/cka-ckad
- CKA + CKS Bundle: kube.promo/bundle
- CKA + CKAD + CKS Exam bundle: kube.promo/k8s-bundle
Checkout all the latest bundle offers at Linux Foundation Coupon repo.
[!NOTE]>⌛ Act fast—this limited-time offer won’t be around much longer!
You have one year of validity to appear for the certification exam after registration
Organized Kubernetes & CKA Learning
If you Looking for an organized way to learn Kubernetes and prepare for the CKA exam with practice questions?
Check out our Complete CKA Certification Course.
It includes illustrations, hands-on exercises, real-world examples, and dedicated Discord support.
[!NOTE]>⌛ For a lmited time, use code DCUBE30 to get 30% OFF today!
Setup Prerequisites
- A working Vagrant setup using Vagrant + VirtualBox
Documentation
Current k8s version for CKA, CKAD, and CKS exam: 1.30
The setup is updated with 1.31 cluster version.
Refer to this link for documentation full: https://devopscube.com/kubernetes-cluster-vagrant/
Prerequisites
- Working Vagrant setup
- 8 Gig + RAM workstation as the Vms use 3 vCPUS and 4+ GB RAM
For MAC/Linux Users
The latest version of Virtualbox for Mac/Linux can cause issues.
Create/edit the /etc/vbox/networks.conf file and add the following to avoid any network-related issues.
* 0.0.0.0/0 ::/0
or run below commands
sudo mkdir -p /etc/vbox/
echo "* 0.0.0.0/0 ::/0" | sudo tee -a /etc/vbox/networks.conf
So that the host only networks can be in any range, not just 192.168.56.0/21 as described here: https://discuss.hashicorp.com/t/vagrant-2-2-18-osx-11-6-cannot-create-private-network/30984/23
Bring Up the Cluster
To provision the cluster, execute the following commands.
git clone https://github.com/scriptcamp/vagrant-kubeadm-kubernetes.git
cd vagrant-kubeadm-kubernetes
vagrant up
Set Kubeconfig file variable
cd vagrant-kubeadm-kubernetes
cd configs
export KUBECONFIG=$(pwd)/config
or you can copy the config file to .kube directory.
cp config ~/.kube/
Install Kubernetes Dashboard
The dashboard is automatically installed by default, but it can be skipped by commenting out the dashboard version in settings.yaml before running vagrant up.
If you skip the dashboard installation, you can deploy it later by enabling it in settings.yaml and running the following:
vagrant ssh -c "/vagrant/scripts/dashboard.sh" controlplane
Kubernetes Dashboard Access
To get the login token, copy it from _config/token
Port forward:
kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443
Open the site in your browser:
https://localhost:8443
To shutdown the cluster,
vagrant halt
To restart the cluster,
vagrant up
To destroy the cluster,
vagrant destroy -f
Network graph
+-------------------+
| External |
| Network/Internet |
+-------------------+
|
|
+-------------+--------------+
| Host Machine |
| (Internet Connection) |
+-------------+--------------+
|
| NAT
+-------------+--------------+
| K8s-NATNetwork |
| 192.168.99.0/24 |
+-------------+--------------+
|
|
+-------------+--------------+
| k8s-Switch (Internal) |
| 192.168.99.1/24 |
+-------------+--------------+
| | |
| | |
+-------+--+ +---+----+ +-+-------+
| Master | | Worker | | Worker |
| Node | | Node 1 | | Node 2 |
|192.168.99| |192.168.| |192.168. |
| .99 | | 99.81 | | 99.82 |
+----------+ +--------+ +---------+
This network graph shows:
- The host machine connected to the external network/internet.
- The NAT network (K8s-NATNetwork) providing a bridge between the internal network and the external network.
- The internal Hyper-V switch (k8s-Switch) connecting all the Kubernetes nodes.
- The master node and two worker nodes, each with their specific IP addresses, all connected to the internal switch.