VMs

Anudha Mittal
4 min readSep 14, 2024

--

Goal is to replicate a remote Ubuntu VM locally on MacOS

  1. brew install multipass (did not install via MacPorts as of 9/13/24)
  2. multipass find gives a list of images
  3. download an image
  4. use multipass and the image to create an instance
  5. launch the instance → now the command line switches from userA@host to userB@VMinstance
  6. python is natively installed with ubuntu now
  7. have to install pip, one of the most common python package managers: sudo apt install python3-pip
  8. used pip install to get another python package manager: uv
  9. pip installs at a specific dir location → this location is not in the system environment variables by default → add to path to use uv from command line
  10. uv can install either to where system’s default python libs are stored or create a virtual env and then install more libs there
  11. created a virtual env: ML
  12. source ML/bin/activate → switches the terminal command line to show venv activated
  13. within the venv → uv pip install numpy

Resolved 1 package in 3ms

Installed 1 package in 8ms

14. deactivate gets out of the python venv and back to the ubuntu VM

Goal: Launch multiple VMs to create a cluster managed by kube. Use a bash script.

  • Configure the VM with that runs the Kubernetes Control Plane to have at least 2 GB memory and 2 CPUs, see screenshot.
  • Give executable permission to bash script: chmod +x launch_vms.sh
  • Run: ./launch_vms.sh

Next: install docker, run docker engine, install kube. When the docker engine is running, systemctl status docker will show:

The following commands will install kube

echo “deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /” | sudo tee /etc/apt/sources.list.d/kubernetes.list

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg — -dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

sudo swapoff -a

sudo kubeadm init — pod-network-cidr=192.168.0.0/16

Note that there is a font change in Medium, so copy/paste messes. Two dashes before dearmor.

Output:

Kubernetes Control-Plane Initialized

Disk space in VM is 99% used. Default 4G disk space allocated by multipass.

df -h [relevant output only]

Delete previous VMs and launching with new config.

multipass delete vm-1 vm-2 vm-3

multipass purge

Five VM’s launched with a yaml config file a sweetly clean shell script. Install docker, kube, nginx, python, vim.

cloud-init.yaml

#cloud-config

package_update: true

package_upgrade: true

packages:

- docker.io

- kubelet

- kubeadm

- kubectl

- nginx

- python3

- vim

- apt-transport-https

- ca-certificates

- curl

runcmd:

- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

- curl -s https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | apt-key add — # change

- apt-add-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

- apt-add-repository “deb https://apt.kubernetes.io/ kubernetes-xenial main”

- apt-get update

- apt-get install -y docker-ce docker-ce-cli containerd.io

- systemctl enable docker

- systemctl start docker

- swapoff -a # Disable swap for Kubernetes

- kubeadm init — pod-network-cidr=192.168.0.0/16

- mkdir -p /home/ubuntu/.kube

- cp /etc/kubernetes/admin.conf /home/ubuntu/.kube/config

- chown ubuntu:ubuntu /home/ubuntu/.kube/config

However. Random check on VM-3, checking docker status shows failed.

Manually sudo enabled and sudo started docker, which led to active status.

Modified cloud-init.yaml to add sudo. Five VMs launched successfully; docker had to be enabled and started manually again. :/

  • Number of VMs, VM memory, and CPU’s are specified in the bash script.
  • This is the current file to install packages when launching a VM(?), should also install jre and spark.

Sign up to discover human stories that deepen your understanding of the world.

--

--

No responses yet

Write a response