This page covers how to create a Compute Engine Linux instance on Google Cloud Platform (GCP).
16. Select a Machine Type
What is a Machine Type? A machine type determines the number of virtual CPUs (vCPUs) and memory (GB) allocated to your Compute Engine instance. You should select an appropriate type based on your workload requirements.
Key Considerations:
- E2 series (General Purpose): e.g., e2-micro, e2-small, e2-medium. Suitable for various workloads and cost-effective. Some types are eligible for the Free Tier.
- N2/N2D series (General Purpose): e.g., n2-standard, n2d-highmem. Offers higher performance and flexibility.
- C2/C2D series (Compute Optimized): e.g., c2-standard, c2d-highcpu. Optimized for high-performance computing (HPC) workloads.
- Custom Machine Types: You can create custom machine types if specific vCPU and memory combinations are required.
How to Select:
When creating an instance, in the 'Machine configuration' section, select the 'Series' and 'Machine type'. For initial use or testing purposes, consider 'e2-micro' from the 'E2' series.
17. Configure Boot Disk
What is a Boot Disk? The boot disk is a persistent disk that contains the instance's operating system and startup programs. Here you select the Linux OS image.
Key Considerations:
- Operating System: You can choose from various Linux distributions such as Debian, Ubuntu, CentOS, Red Hat Enterprise Linux (RHEL), SUSE Linux Enterprise Server.
- Version: You can specify a particular version of each OS.
- Disk Type: You can choose between Standard Persistent Disk, SSD Persistent Disk, and Balanced Persistent Disk. SSDs offer faster performance but come at a higher cost.
- Size: Set the disk capacity in GB. You can start with a default (e.g., 10GB) and expand it later as needed.
How to Configure:
In the 'Boot disk' section, click the 'Change' button to set your desired OS image, disk type, and size.
18. Configure Firewall Rules
What are Firewall Rules? GCP firewall rules control network traffic going to and from VM instances. Without opening specific ports, external access to your instance will be blocked.
Key Rules:
- Allow HTTP traffic (Port 80): If running a web server, you must enable this rule to receive web requests.
- Allow HTTPS traffic (Port 443): Required for secure web traffic (SSL/TLS) and essential when operating a web server.
- SSH (Port 22): Allowed by default for remote access to your instance. For enhanced security, you can restrict it to specific IP addresses if needed.
How to Configure:
When creating an instance, in the 'Firewall' section, you can simply select the 'Allow HTTP traffic' and/or 'Allow HTTPS traffic' checkboxes to enable these rules. More detailed firewall rules can be configured under 'VPC network > Firewall'.
19. SSH Key Management and Connection
What is SSH Key Management? GCP primarily supports browser-based SSH access and SSH access via the gcloud CLI. These methods automatically manage SSH keys for your convenience. However, you can also register and use your own SSH keys.
How to Connect:
- Browser-based SSH: In the GCP console, click the 'SSH' button next to your instance in the list to directly access the terminal within your browser. This is the simplest method.
- gcloud CLI: Google Cloud SDK를 설치한 후 터미널에서 명령어를 사용하여 접속합니다.
gcloud compute ssh YOUR_INSTANCE_NAME --zone YOUR_ZONE
- Custom SSH Key:
- Generate an SSH key pair locally:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -C "your_username"
- Add the content of your public key (`~/.ssh/id_rsa.pub`) to the instance's metadata or project-wide SSH keys.
- Connect using the SSH command:
ssh -i ~/.ssh/id_rsa your_username@YOUR_INSTANCE_EXTERNAL_IP
- Generate an SSH key pair locally:
20. External IP Address
What is an External IP Address? An external IP address assigned to a Compute Engine instance allows access to the instance via the internet.
Key Considerations:
- Ephemeral vs. Static: By default, an ephemeral external IP is assigned, which can change when the instance is stopped/started. For production environments, it is recommended to assign a 'Static External IP' to ensure service continuity.
How to Allocate:
An ephemeral external IP is automatically assigned during instance creation. To change it to a static IP, you can 'promote' the external IP address to 'Static' in the 'VPC network > IP addresses' menu.