@orpha
To launch a Kubernetes cluster using Vagrant, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Vagrant.configure("2") do |config| # Define master node config.vm.define "master" do |master| master.vm.box = "ubuntu/bionic64" master.vm.network "private_network", ip: "192.168.33.10" master.vm.provision "shell", path: "scripts/master.sh" end # Define worker nodes (1..2).each do |i| config.vm.define "worker#{i}" do |worker| worker.vm.box = "ubuntu/bionic64" worker.vm.network "private_network", ip: "192.168.33.1#{i+1}" worker.vm.provision "shell", path: "scripts/worker.sh" end end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#!/bin/bash # Update package list apt-get update # Install Docker apt-get install -y docker.io systemctl start docker systemctl enable docker # Install kubeadm, kubelet, and kubectl apt-get install -y apt-transport-https curl curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF apt-get update apt-get install -y kubelet kubeadm kubectl |
1 2 3 |
vagrant up vagrant ssh master sudo kubeadm init |
1
|
kubectl get nodes |
You should see the master and worker nodes listed in the output.
That's it! You have successfully launched a Kubernetes cluster using Vagrant.