Tag: SSH keys

  • Launching a Compute Instance Using the Google Cloud Console and Cloud SDK (gcloud)

    Google Cloud Platform (GCP) offers two primary methods for launching Compute Engine virtual machines (VMs): the Google Cloud Console (web interface) and the Cloud SDK (gcloud command-line tool). This guide demonstrates a hybrid approach, leveraging both tools for streamlined and customizable instance deployment.

    Prerequisites

    1. Active GCP Project: Ensure you have an active Google Cloud Platform project.
    2. SSH Key Pair:
      • If needed, generate an SSH key pair on your local machine using ssh-keygen.
      • Add the public key to your project’s metadata:
        • In the Cloud Console, navigate to Compute Engine > Metadata > SSH Keys.
        • Click “Edit,” then “Add Item,” and paste your public key.
    3. Firewall Rule: Configure a firewall rule permitting ingress SSH traffic (port 22) from your authorized IP address(es).

    Step 1: Initial Configuration (Google Cloud Console)

    1. Open the Cloud Console and navigate to Compute Engine > VM instances.

    2. Click Create Instance.

    3. Provide the following details:

      • Name: A descriptive name for your instance.
      • Region/Zone: The desired geographical location for your instance.
      • Machine Type: Select the appropriate vCPU and memory configuration for your workload.
      • Boot Disk:
        • Image: Choose your preferred operating system (e.g., Ubuntu, Debian).
        • Boot disk type: Typically, “Standard Persistent Disk (pd-standard)” is suitable.
        • Size: Specify the desired storage capacity.
      • Firewall: Enable “Allow HTTP traffic” and “Allow HTTPS traffic” if required.
      • Networking: Adjust network settings if you have specific requirements.
      • Advanced Options (Optional):
        • Preemptibility: If cost optimization is a priority, consider preemptible instances.
        • Availability Policy: For high availability, configure a regional policy.
    4. Click “Create” to initiate instance creation.

    Step 2: Advanced Configuration (Cloud SDK)

    1. Authenticate: Ensure you are authenticated with your GCP project:

      gcloud auth login
      gcloud config set project your-project-id 
      
    2. Create Instance: Execute the following gcloud command, replacing placeholders with your specific values:

      gcloud compute instances create instance-name \
          --zone=your-zone \
          --machine-type=machine-type \
          --image=image-name \
          --image-project=image-project \
          --boot-disk-size=disk-sizeGB \
          --boot-disk-type=pd-balanced \
          --metadata-from-file=startup-script=gs://your-bucket/startup.sh \
          --tags=http-server,https-server \
          --maintenance-policy=maintenance-policy \ 
          --preemptible  # (Optional) 
      
    3. Additional Disks (Optional): To attach additional disks, use:

      gcloud compute instances attach-disk instance-name \
         --disk=disk-name \
         --zone=your-zone
      

    Step 3: Connect via SSH:

    gcloud compute ssh instance-name --zone=your-zone
  • Deploying and Implementing Compute Engine Resources

    Compute Engine is Google Cloud’s infrastructure as a service (IaaS) offering, providing scalable virtual machines and other resources in the cloud.

    Launching a compute instance using the Google Cloud console and Cloud SDK (gcloud)

    One of the most fundamental tasks in Compute Engine is launching a virtual machine instance. This can be done through the Google Cloud console, a web-based interface for managing Google Cloud resources, or through the Cloud SDK, a command-line interface for Google Cloud.

    When launching an instance, you can specify key attributes like the machine type, the operating system image, the disk size and type, and the network configuration. You can also specify SSH keys to enable remote access to the instance.

    Creating an autoscaled managed instance group using an instance template

    Another key feature of Compute Engine is the ability to create managed instance groups. These are groups of virtual machine instances that are automatically scaled up or down based on demand. To create a managed instance group, you first need to create an instance template, which defines the configuration for the instances in the group.

    Once you have an instance template, you can create a managed instance group and configure autoscaling policies based on metrics like CPU utilization or load balancing traffic.

    Generating/uploading a custom SSH key for instances

    SSH keys are used to enable secure remote access to virtual machine instances in Compute Engine. By default, Compute Engine creates a new SSH key pair for each instance, but you can also specify a custom SSH key when launching an instance.

    To generate an SSH key pair, you can use tools like OpenSSH or PuTTYgen. Once you have a key pair, you can upload the public key to Compute Engine and associate it with one or more instances.

    Installing and configuring the Cloud Monitoring and Logging Agent

    Cloud Monitoring and Logging provide powerful tools for monitoring and managing Compute Engine resources. To use these tools, you first need to install and configure the Cloud Monitoring and Logging agent on your virtual machine instances.

    The agent collects metrics and logs from the instance and sends them to Cloud Monitoring and Logging for analysis and visualization. You can configure the agent to collect custom metrics and logs, as well as integrate with third-party monitoring and logging tools.

    Assessing compute quotas and requesting increases

    Finally, it’s important to be aware of the compute quotas and limits that apply to your Google Cloud project. These quotas restrict the number of resources you can create in Compute Engine, such as the number of virtual CPUs, persistent disks, and IP addresses.

    If you need to exceed these quotas, you can request a quota increase through the Google Cloud console. Be sure to provide a detailed justification for the increase, as well as any relevant performance data.