Skip to content

Basic operations on virtual machine

In this section you will create new virtual machine, log into it, and run some basic commands to check its state.

1. Create instance with docker

In the manager in section Compute in Instances click on Create an instance.

  1. In section "Select a model" choose Discovery B3-8 - an instance with 2 CPU and 8GB RAM.

  2. Select a region: pick any. - During labs we will use SBG5

  3. Select an image: Ubuntu 22.04

  4. Select SSH key that you previously added.

  5. Configure your instance: Post-installation script

    #cloud-config
    
    # Configure a limited user
    users:
      - default
      - name: admin
        groups:
          - sudo
        sudo:
          - ALL=(ALL) NOPASSWD:ALL
        shell: /bin/bash
    
    # Perform System Updates
    package_update: true
    package_upgrade: true
    
    # Harden SSH access
    runcmd:
      - sed -i '/PermitRootLogin/d' /etc/ssh/sshd_config
      - echo "PermitRootLogin no" >> /etc/ssh/sshd_config
      - systemctl restart sshd
    
    # Install additional software packages
    packages:
      - nginx
      - mysql-server
      - php
    

  6. Instance count: 2

  7. Configure your network: select Public mode

  8. Select a billing period: Hourly

2. Login into newly create instance

Lets use OpenSSH client

ssh -i ~/roadshow-workspace/key ubuntu@${IP}
You will get question The authenticity of host can't be established. Are you sure you want to continue connecting just confirm with: yes

Lets use putty.exe client

In putty in session paste the IP address. putty

In section Connection -> SSH -> Auth select path to file with your private key priv.ppk. putty

You will get the question that putty didn't recognize this host just Accept.no putty

Type the name of user you want login as. In our case its ubuntu. putty

3. Checking newly created instance

Let's run some basic commands to check the instance properties.

To show RAM usage:

free

To show number of CPU cores:

nproc

To list block devices:

lsblk

4. Adding additional volume to instance

Additional volumes can be added though the Manager.

In section Storage go to Block storage and click on Create a volume

Because of geo-limitations choose the same region where you created your instance.

After creating instance click on three dots and click on Attach to instance putty

After attaching volume to instance issue lsblk command once again.

Mounting additional volume on an instance

The disk comes without any partitions nor filesystems, so you need to create them:

  • partition table:
sudo parted -s /dev/sdX mklabel gpt
  • partition:
sudo parted -s /dev/sdX mkpart data 0% 100%
  • filesystem:
sudo mkfs.ext4 /dev/sdX1
  • mount the disk
    sudo mount /dev/sdX1 /mnt
    

Checking volume performance

Install fio

sudo apt update
sudo apt -y install fio

Change directory to /mnt

cd /mnt
Run this simple and short test:
sudo fio --name=test --bs=4k --ioengine=libaio --iodepth=4 --size=1g --direct=1 --runtime=30

Create docker container with nginx

To run and publish docker container with nginx on port 80 issue this command:

sudo docker run -d -p 80:80 --name nginx nginx:latest