• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

instances

GCP List of BMS Servers

September 15, 2022

Here’s how to list Bare Metal Servers in Google Cloud Platform via gcloud.

gcloud bms instances list --region REGION --project PROJECT

gcloud bms instances list --region REGION --project PROJECT

Result

NAME            ID                 PROJECT         REGION       MACHINE_TYPE           CLIENT_IPS    PRIVATE_IPS                    STATE
server-001      at-xxxxxxx-svr001  project-01      us-central1  o2-ultramem-896-metal  10.0.0.1      192.168.253.1,192.168.252.1    RUNNING
server-002      at-xxxxxxx-svr002  project-02      us-central1  o2-ultramem-896-metal  10.0.0.2      192.168.253.2,192.168.252.2    RUNNING

NAME ID PROJECT REGION MACHINE_TYPE CLIENT_IPS PRIVATE_IPS STATE server-001 at-xxxxxxx-svr001 project-01 us-central1 o2-ultramem-896-metal 10.0.0.1 192.168.253.1,192.168.252.1 RUNNING server-002 at-xxxxxxx-svr002 project-02 us-central1 o2-ultramem-896-metal 10.0.0.2 192.168.253.2,192.168.252.2 RUNNING

Obviously you can see the same from GCP’s Console.

Filed Under: Cloud Tagged With: bms, gcp, instances, list

GCP Update Instance Metadata

June 13, 2021

How to update an instance metadata in GCP.

gcloud compute instances add-metadata instance-name \
--metadata key-name=value \
--project your-project-id \
--zone us-central1-a

gcloud compute instances add-metadata instance-name \ --metadata key-name=value \ --project your-project-id \ --zone us-central1-a

In this example, we are adding enable-oslogin=TRUE.

gcloud compute instances add-metadata instance-name \
--metadata enable-oslogin=TRUE \
--project your-project-id \
--zone us-central1-a

gcloud compute instances add-metadata instance-name \ --metadata enable-oslogin=TRUE \ --project your-project-id \ --zone us-central1-a

Filed Under: Cloud Tagged With: compute, create, gcp, instances, metadata

GCP List of SQL Instances

February 28, 2021

Here’s how to list SQL instances within your GCP project.

gcloud sql instances list --project your-project-id

gcloud sql instances list --project your-project-id

Output:

NAME             DATABASE_VERSION         LOCATION       TIER              PRIMARY_ADDRESS  PRIVATE_ADDRESS  STATUS
database1        SQLSERVER_2017_STANDARD  us-central1-a  db-n1-standard-1  -                10.10.10.11    RUNNABLE
database2        SQLSERVER_2017_STANDARD  us-central1-c  db-n1-standard-1  -                10.10.10.12    RUNNABLE

NAME DATABASE_VERSION LOCATION TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS database1 SQLSERVER_2017_STANDARD us-central1-a db-n1-standard-1 - 10.10.10.11 RUNNABLE database2 SQLSERVER_2017_STANDARD us-central1-c db-n1-standard-1 - 10.10.10.12 RUNNABLE

Filed Under: Cloud Tagged With: gcloud, gcp, instances, list, sql

AWS Spot Instances Running Docker

February 14, 2021

I have an AMI with docker installed. Here’s how I launch a spot instance using Terraform.

Here’s my Terraform script.

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
  }
}
provider "aws" {
  profile = "default"
  region  = "us-east-1"
}
resource "aws_spot_instance_request" "docker" {
  ami                           = "ami-xxxxxxxxxxxxxxxx"
  spot_price                    = "0.0031"
  wait_for_fulfillment          = "true"
  key_name                      = "servers"
  instance_type                 = "t3.micro"
  subnet_id                     = "subnet-xxxxxxxxxxxxxxxx"
  security_groups               = ["sg-xxxxxxxxxxxxxxxxxx"]
  associate_public_ip_address   = "true"
  user_data = <<-EOF
              #!/bin/bash
              hostnamectl set-hostname docker
              EOF
  tags = {
        Name = "docker-0.1"
  }
}
resource "aws_ec2_tag" "tagging" {
  resource_id                   = aws_spot_instance_request.docker.spot_instance_id
  key                           = "Name"
  value                         = "docker-0.1"
}

terraform { required_providers { aws = { source = "hashicorp/aws" } } } provider "aws" { profile = "default" region = "us-east-1" } resource "aws_spot_instance_request" "docker" { ami = "ami-xxxxxxxxxxxxxxxx" spot_price = "0.0031" wait_for_fulfillment = "true" key_name = "servers" instance_type = "t3.micro" subnet_id = "subnet-xxxxxxxxxxxxxxxx" security_groups = ["sg-xxxxxxxxxxxxxxxxxx"] associate_public_ip_address = "true" user_data = <<-EOF #!/bin/bash hostnamectl set-hostname docker EOF tags = { Name = "docker-0.1" } } resource "aws_ec2_tag" "tagging" { resource_id = aws_spot_instance_request.docker.spot_instance_id key = "Name" value = "docker-0.1" }

I use “aws_ec2_tag” resource to tag the instance properly.

In addition, I use user_data to run a script, to set the hostname.

To launch via Terraform, I run the following commands.

terraform init
terraform apply

terraform init terraform apply

When done, I could stop the instance to stop incurring charges. Or just simply destroy it via Terraform.

terraform destroy

terraform destroy

It’s not bad deal for an instance that costs only $0.0031 per hour.

Filed Under: Cloud Tagged With: aws, docker, instances, spot, tags, terraform

GCP List Instances with Service Account

September 23, 2020

Here’s how to list GCP instances with a specific service account.

gcloud compute instances list \
--project your-project-id \
--format="value(name,serviceAccounts[].email)" \
--filter="serviceAccounts.email=your-service-account@email.com AND name~\bwp"

gcloud compute instances list \ --project your-project-id \ --format="value(name,serviceAccounts[].email)" \ --filter="serviceAccounts.email=your-service-account@email.com AND name~\bwp"

I’m using filters to look for a specific service account, and any instance starting with ‘wp.’ \b means begins with.

Filed Under: Cloud Tagged With: gcp, instances, list, serviceaccount

GCP Disks Attach To An Instance

September 15, 2020

Here’s how to display a list the disks attached to an instance.

gcloud compute instances describe instance-name \
--project project-id \
--zone us-central1-c \
--format='yaml(disks[].source)'

gcloud compute instances describe instance-name \ --project project-id \ --zone us-central1-c \ --format='yaml(disks[].source)'

Filed Under: Cloud Tagged With: compute, describe, disks, gcp, instances, list, yaml

GCP Instances By Service Account

April 14, 2020

Here’s how to get a list of GCP instances using a specific service account.

gcloud compute instances list \
--filter="serviceAccounts.email=service-account@domain.com" \
--project project-id

gcloud compute instances list \ --filter="serviceAccounts.email=service-account@domain.com" \ --project project-id

To display all instances and their service accounts in JSON format.

gcloud compute instances list \
--format="json(name,serviceAccounts[].email)" \
--project your-project-id

gcloud compute instances list \ --format="json(name,serviceAccounts[].email)" \ --project your-project-id

Display in YAML which is also the Default.

gcloud compute instances list \
--format="default(name,serviceAccounts[].email)" \
--project your-project-id

gcloud compute instances list \ --format="default(name,serviceAccounts[].email)" \ --project your-project-id

Filed Under: Cloud Tagged With: compute, gcp, instances, list, service account

AWS Register Instances with Load Balancer

February 19, 2020

Here’s the AWS CLI to register instances to a load balancer.

aws elb register-instances-with-load-balancer \
--load-balancer-name my-load-balancer \
--instances i-xxxxxxxxxxx i-xxxxxxxxxxx i-xxxxxxxxxxx

aws elb register-instances-with-load-balancer \ --load-balancer-name my-load-balancer \ --instances i-xxxxxxxxxxx i-xxxxxxxxxxx i-xxxxxxxxxxx

Filed Under: Cloud Tagged With: aws, cli, instances, load balancer, register

  • Go to page 1
  • Go to page 2
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023