Virtual machines (VMs) are the backbone of modern cloud infrastructure, enabling developers to deploy applications, test software, and manage workloads with ease. In this blog, we'll explore how to create virtual machines on three leading cloud platforms: AWS, Azure, and GCP. We'll provide code snippets and step-by-step instructions to get you started.
AWS (Amazon Web Services)
AWS offers a robust and scalable cloud computing environment. The Elastic Compute Cloud (EC2) service is commonly used to create and manage virtual machines.
Step-by-Step Guide to Creating an EC2 Instance
- Sign in to the AWS Management Console.
- Navigate to the EC2 Dashboard.
-
Launch Instance:
- Click on the “Launch Instance” button.
-
Choose an Amazon Machine Image (AMI):
- Select an AMI. For this example, we’ll use the Amazon Linux 2 AMI.
-
Choose an Instance Type:
- Select an instance type. The t2.micro instance is a good choice for beginners.
-
Configure Instance Details:
- Configure settings like the number of instances, network, and IAM role.
-
Add Storage:
- Specify the storage size and type.
-
Add Tags:
- Add tags to organize and manage your instances.
-
Configure Security Group:
- Configure firewall settings to control traffic to your instance.
-
Review and Launch:
- Review your settings and click “Launch”. Choose an existing key pair or create a new one for SSH access.
Code Snippet (AWS CLI)
Using the AWS CLI, you can launch an EC2 instance with a simple command:
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--count 1 \
--instance-type t2.micro \
--key-name MyKeyPair \
--security-group-ids sg-0a1b2c3d4e5f6g7h8 \
--subnet-id subnet-0ab1c2d3e4f5g6h7i
Azure (Microsoft Azure)
Azure offers Virtual Machines (VMs) as part of its comprehensive cloud services. Azure VMs support a wide range of operating systems and configurations.
Step-by-Step Guide to Creating an Azure VM
- Sign in to the Azure Portal.
- Navigate to Virtual Machines.
-
Create a New VM:
- Click on the “Create” button and select “Virtual Machine”.
-
Basics:
- Fill in the basic information such as subscription, resource group, and VM name.
-
Choose Image and Size:
- Select the OS image and VM size. For this example, we’ll use Ubuntu Server 20.04 LTS and the Standard_B1s size.
-
Administrator Account:
- Set up an administrator account with a username and SSH public key.
-
Disks:
- Configure the OS disk and any additional data disks.
-
Networking:
- Configure the network settings including virtual network, subnet, and public IP.
-
Management, Monitoring, and Advanced:
- Configure optional settings as needed.
-
Review and Create:
- Review your settings and click “Create”.
Code Snippet (Azure CLI)
Using the Azure CLI, you can create a VM with the following command:
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys
GCP (Google Cloud Platform)
Google Cloud Platform provides Compute Engine for creating and managing virtual machines. GCP VMs offer high performance and flexibility.
Step-by-Step Guide to Creating a GCP VM Instance
- Sign in to the Google Cloud Console.
- Navigate to Compute Engine.
-
Create an Instance:
- Click on the “Create Instance” button.
-
Configure Instance:
- Set the instance name, region, and zone.
-
Choose Machine Type:
- Select a machine type. The e2-micro is suitable for small tasks.
-
Boot Disk:
- Choose an operating system image. For this example, we’ll use Debian GNU/Linux.
-
Firewall Rules:
- Enable HTTP and HTTPS traffic if needed.
-
Create:
- Click the “Create” button to launch the instance.
Code Snippet (gcloud CLI)
Using the gcloud CLI, you can create a VM instance with the following command:
gcloud compute instances create my-instance \
--image-family debian-10 \
--image-project debian-cloud \
--machine-type e2-micro \
--zone us-central1-a
Conclusion
Creating virtual machines on AWS, Azure, and GCP is straightforward and can be accomplished using their respective management consoles or CLI tools. Each platform offers unique features and flexibility to cater to different needs and preferences. Whether you are a beginner or an experienced developer, these cloud platforms provide the tools necessary to deploy and manage your VMs efficiently.
Happy cloud computing!
Top comments (1)
Very Informative. 👏
I created an article a while back regarding VMs on Azure using SSH as well as RDP for GUI based VMs and hosting websites cost free on them. Do check that out as well.
huzzaifaasim.medium.com/a-beginner...