brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 25. 2022

172. GCP 커스템VPC, CLI로 만들기(2/4)



구글은 서브넷을 리전 단위로 만들수 있다.

다른 CSP와 다른 점이다.

서브넷을 글러벌하게 만들수 있다.

파이어월 룰도 만들어보자

VM Intstance도 만들어보자.

실습을 해보자

리전에 여러 서브넷을  만들고, 여러 서버를 만들어 보자.

자동 서브넷과  Custom 서브넷을 만들어 보자



<1> Cloud shell 사용

<2> 콘솔에서 Custom mode VPC  로 관리 네트워크를  만들어 보기

<3> CLI로 Private subnet 만들어보기

<4> 콘솔로 관리네트워크를 위한 Firewall 만들기

<5> CLI로 private subnet firewall만들기

<6> 콘솔로 Mgmt와 private subnet에  VM 만들기

<7> CLI로  private sunnet에   VM 만들기



<1> Cloud shell 사용


1

인증 확인

gcloud auth list


2

gcloud config list project




<2> 콘솔에서 Custom mode VPC  로 관리 네트워크를  만들어 보기


1

VPC Netowrk > VPC networks > Create VPC Network

mgmt-gcp-vpc



2

mgmt-gcp-us-pub1





<3> CLI로 Private subnet 만들어보기


1

privatenet 이라는 네트워크를 만들자 

gcloud compute networks create privatenet --subnet-mode=custom


2

 privatesubnet-us  라고 서브넷을 만들어 보자

gcloud compute networks subnets create privatesubnet-us --network=privatenet --region=us-central1 --range=172.16.0.0/24

Created [https://www.googleapis.com/compute/v1/projects/


$ gcloud compute firewall-rules create <FIREWALL_NAME> --network privatenet --allow tcp,udp,icmp --source-ranges <IP_RANGE>


$ gcloud compute firewall-rules create <FIREWALL_NAME> --network privatenet --allow tcp:22,tcp:3389,icmp



3

gcloud compute networks subnets create privatesubnet-eu --network=privatenet --region=europe-west4 --range=172.20.0.0/20

Created [https://www.googleapis.com/compute/v1/projects/




4

네트워크 확인


gcloud compute networks list



topasvga0802@cloudshell:~ (seismic-catbird-358207)$ gcloud compute networks list


NAME: default

SUBNET_MODE: AUTO

BGP_ROUTING_MODE: REGIONAL

IPV4_RANGE:

GATEWAY_IPV4:


NAME: privatenet

SUBNET_MODE: CUSTOM

BGP_ROUTING_MODE: REGIONAL

IPV4_RANGE:

GATEWAY_IPV4:


NAME: tetgame-gcp-dev-vpc

SUBNET_MODE: CUSTOM

BGP_ROUTING_MODE: REGIONAL

IPV4_RANGE:

GATEWAY_IPV4:




<4> 콘솔로 관리네트워크를 위한 Firewall 만들기


1

콘솔

VPC Network > Firewall >  Create Filrewall Rule >


2

managementnet-allow-icmp-ssh-rdp


3

Targets

All instances in the network


4

Source IPv4 ranges

0.0.0.0/0


5

Specified protocols and ports

22, 3389

icmp




<5> CLI로 private subnet firewall만들기


gcloud compute firewall-rules create privatenet-allow-icmp-ssh-rdp --direction=INGRESS --priority=1000 --network=privatenet --action=ALLOW --rules=icmp,tcp:22,tcp:3389 --source-ranges=0.0.0.0/0





<6> 콘솔로 Mgmt와 private subnet에  VM 만들기


1

Compute Engine > VM instances >  CREATE INSTANCE  >


managementnet-gcp-us-vm

us-central1


2

네트워크 변경

Network

managementnet  로 변경한다.

Subnet은 같이 변경 된다.

생성


// 공인 IP도 자동 할당 된다.




<7> CLI로  private sunnet에   VM 만들기



1

gcloud compute instances create privatenet-us-vm --zone=us-central1-f --machine-type=n1-standard-1 --subnet=privatesubnet-us


AME: privatenet-us-vm

ZONE: us-central1-f

MACHINE_TYPE: n1-standard-1

PREEMPTIBLE:

INTERNAL_IP: 172.16.0.2

EXTERNAL_IP: 34.72.241.114

STATUS: RUNNING



2

전체 VM 인스턴스 확인하기 - 불필요한 인스턴스는 삭제


gcloud compute instances list --sort-by=ZONE





다음 자료


https://brunch.co.kr/@topasvga/2386






https://brunch.co.kr/@topasvga/1829



https://brunch.co.kr/@topasvga/1835



https://brunch.co.kr/@topasvga/2388



감사합니다.


매거진의 이전글 171. GCP IAM (1/4)

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari