Creating a Kubernetes Cluster Environment on Ubuntu 22.04.1 with Vagrant and VMware (Type 2 Hypervisor)
In this article, we will explore the process of creating a Kubernetes cluster environment using Vagrant, Ubuntu 22.04.1, and VMware (Type 2 Hypervisor) for learning and testing purposes. We will cover key concepts, subtitles, and detailed context related to the topic. The article will be at least 800 words long and provide you with a comprehensive understanding of the process.
Prerequisites
- A host operating system running Ubuntu 22.04.1
- Vagrant installed on the host operating system
- VMware Type 2 Hypervisor installed and running on the host operating system
Step 1: Provisioning Ubuntu 22.04.1 Virtual Machines
To start, we will use Vagrant to provision Ubuntu 22.04.1 virtual machines. Create a new directory for your project and navigate into it. Then, create a new Vagrantfile with the following contents:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider :vmware_desktop do |v|
v.gui = true
v.memory = "2048"
end
config.vm.define "master" do |master|
master.vm.network "private_network", ip: "192.168.50.10"
end
config.vm.define "node1" do |node1|
node1.vm.network "private_network", ip: "192.168.50.11"
end
config.vm.define "node2" do |node2|
node2.vm.network "private_network", ip: "192.168.50.12"
end
This configuration creates three Ubuntu 22.04.1 virtual machines: a master node and two worker nodes. Each machine has a private network IP address and is provisioned with 2GB of memory.
Step 2: Installing Docker on Ubuntu 22.04.1
Next, we need to install Docker on each virtual machine. To do this, ssh into each virtual machine and run the following commands:
sudo apt update
sudo apt install docker.io
Step 3: Configuring Kubernetes on Ubuntu 22.04.1
Now that Docker is installed, we can move on to configuring Kubernetes. On the master node, run the following commands:
sudo apt update
sudo apt install apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
On each worker node, run the following commands:
sudo apt update
sudo apt install -y docker.io
sudo apt-mark hold docker.io
Step 4: Initializing the Kubernetes Cluster
Now that Kubernetes is installed on each virtual machine, we can initialize the cluster on the master node. Run the following command:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
This command initializes the Kubernetes cluster and specifies a pod network CIDR of 10.244.0.0/16. Save the kubeadm join token, as you will need it later to join the worker nodes to the cluster.
Step 5: Configuring kubectl on the Master Node
To configure kubectl on the master node, run the following command:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
This command copies the Kubernetes configuration file to the correct location and updates the ownership to match your user account.
Step 6: Joining the Worker Nodes to the Cluster
To join the worker nodes to the cluster, run the following command on each worker node, using the kubeadm join token from the master node:
sudo kubeadm join --token 192.168.50.10:6443 --discovery-token-ca-cert-hash sha256:
Replace
Step 7: Installing a Pod Network
A pod network is required for communication between pods in the cluster. In this example, we will use the Flannel network. On the master node, run the following command:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
This command installs the Flannel network configuration into the cluster.
Step 8: Verifying the Cluster
To verify the cluster, run the following command on the master node:
kubectl get nodes
This command will display the status of each node in the cluster.
In this article, we covered the process of creating a Kubernetes cluster environment on Ubuntu 22.04.1 using Vagrant and VMware (Type 2 Hypervisor). We provisioned Ubuntu 22.04.1 virtual machines, installed Docker and Kubernetes, initialized the cluster on the master node, joined the worker nodes to the cluster, installed a pod network, and verified the cluster was functioning properly. This environment provides a useful platform for learning and testing Kubernetes in a controlled environment.
References
- Ubuntu 22.04.1: https://releases.ubuntu.com/focal/
- Vagrant: https://www.vagrantup.com/
- VMware Type 2 Hypervisor: https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html
- Kubernetes on Ubuntu 22.04.1: https://kubernetes.io/docs/setup/production-environment/container-runtimes/
- Flannel Network: https://github.com/coreos/flannel