Showing posts with label GCP. Show all posts
Showing posts with label GCP. Show all posts

Friday, March 12, 2021

Setting Up HTTP(S) Load Balancer in GCP

Disclaimer: This is note from my self learning in GCP and may not be correct or complete. Qwiklabs https://google.qwiklabs.com/focuses/10258?parent=catalog

 

In general these are the steps:

  • Create an instance template.
  • Create a target pool.
  • Create a managed instance group.
  • Create a firewall rule to allow traffic (80/tcp).
  • Create a health check.
  • Create a backend service, and attach the managed instance group.
  • Create a URL map, and target the HTTP proxy to route requests to your URL map.
  • Create a forwarding rule.
#create startup.sh script
cat << EOF > startup.sh
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
EOF




#create instance template
gcloud compute instance-templates create nginx-template \
   --metadata-from-file startup-script=startup.sh

#create a target pool
gcloud compute target-pools create nginx-pool 

#create a managed instance group
gcloud compute instance-groups managed create nginx-group \
   --template=nginx-template --size=2 --target-pool nginx-pool

#Create a firewall rule to allow traffic (80/tcp)
gcloud compute firewall-rules create www-firewall \
  --allow tcp:80

#Create a forwarding rule
gcloud compute forwarding-rules create nginx-fwd-rule \
        --ports=80 \
        --target-pool nginx-pool

gcloud compute forwarding-rules list

#Create a health check
gcloud compute http-health-checks create basic-check

gcloud compute instance-groups managed set-named-ports nginx-group --named-ports http:80

#Create a backend service, and attach the managed instance group
gcloud compute backend-services create web-backend-service \
        --protocol=HTTP \
        --port-name=http \
        --http-health-checks=basic-check \
        --global

gcloud compute backend-services add-backend web-backend-service \
        --instance-group=nginx-group \
        --instance-group-zone=us-east1-b \
        --global

#Create a URL map, and target the HTTP proxy to route requests to your URL map
gcloud compute url-maps create web-map-http \
        --default-service web-backend-service

gcloud compute target-http-proxies create http-lb-proxy \
        --url-map web-map-http

gcloud compute forwarding-rules create http-content-rule \
--global --target-http-proxy http-lb-proxy --ports 80


Deploying Kubernetes in GCP

 This is note of my self learning in GCP via Qwiklabs https://google.qwiklabs.com/focuses/10258?parent=catalog


#change zone

gcloud config set compute/zone us-east1-b


#to create a cluster (this step takes few minutes to complete)

gcloud container clusters create nucleus-cluster




#authentication

gcloud container clusters get-credentials nucleus-cluster



#deployment

kubectl create deployment nucleus-server --image=gcr.io/google-samples/hello-app:1.0


#service

kubectl expose deployment nucleus-server --type=LoadBalancer --port 8080


Tuesday, March 9, 2021

VPC Peering in AWS and GCP



The steps to do VPC peering in AWS and GCP are quite similar. You need to have these info:

In AWS

  • Account ID
  • Source and Target VPC ID
  • Permission
In GCP
  • Project ID
  • Source and Target VPC name
  • Permission

The below steps assume that the VPC peering are done on 2 different accounts (on AWS) or projects (on GCP) and both source and target VPC have been created prior.

How to do VPC peering in AWS:
You'll do configure the VPC peering in the source account first then followed with target account with similar steps.

1. Login to the source account.
2. Go to VPC > Peering Connections > Create Peering Connections.


3. Fill up the required information and click "Create Peering Connection" button. You'll see the review page. If the information is correct, proceed with the creation. 
4. You'll see your newly created peering status is "Pending Acceptance". Now login to the target account to accept the peering.
5. In the target account, go to VPC > Peering Connections. 
6. You'll see there's pending peering connection request. Choose on that entry and click button "Actions" > Accept Request.
7. The status should turn Active now.

*You may need to update the route table and security group entries if it's necessary.


How to do VPC peering in GCP:
You'll configure the VPC peering in the source project first then move on to the target project with the similar steps. 

  1. Go to the first/source project
  2. Go to VPC Networking > VPC Network Peering
  3. Click "Create Connection" > Continue
  4. Fill up the info and click button Create



You'll see the status is "Inactive" as you need to do the same steps on Target project.




You'll see the status is "Active" now.


You can confirm the peering by running this command in Cloud Shell:

gcloud compute routes list --project <target_project_id>

You should see entry with name starts with "peering-route" in the result.