ネットワークで隔離されたネットワークを構成すること
14026 ワード
Google KubernetesエンジンとクラウドSQLの間の接続性を確保するために実装できるセキュリティパターンを紹介しました.この部分では、以下のGCPリソースを展開してネットワーク分離を実装します.
2サブネットをもつ VPC GKEのウェブサブネット. 1データサブネット. 雲のNATは、Webサブネットに接続されています. ファイアウォール規則は、認可されたネットワークだけへのサブネットへのアクセスを制限します.
![](https://s1.md5.ltd/image/057cb8c2c270bd2ac241dd3a46652cd3.png)
VPC
単純なVPCリソース ウェブサブネット.それは、我々のGoogle Kubernetesエンジン を主催しますデータサブネット.それはあなたのクラウドデータフロージョブ、クラウドコンポーザー環境などをホストすることができました.
クラウドナット
規則のGSQLノードへのアクセスを制限する規則. 規則的なネットワークだけへのネットワークアクセスを制限する規則. 地形ファイルを作成
地形ファイルを作成
VPCとサブネット
![](https://s1.md5.ltd/image/5bcefd8c07ed7e60526e21bec4180e4e.png)
クラウドナット
![](https://s1.md5.ltd/image/04399aa689db803cc066e6abfa092a34.png)
ファイアウォール
![](https://s1.md5.ltd/image/a569b812b8065c757cf119342979305f.png)
結論
2サブネットをもつ
It is recommended to group similar applications into fewer, more manageable and larger subnets.
![](https://s1.md5.ltd/image/057cb8c2c270bd2ac241dd3a46652cd3.png)
If you have multiples GKE clusters per environment, Google Cloud recommends to use Shared VPC to reduce management and topology complexity.
VPCVirtual Private Cloud
から始めましょう.
地形ファイルinfra/plan/vpc.tf
を作成します
resource "google_compute_network" "custom" {
name = "custom"
auto_create_subnetworks = "false"
routing_mode = "GLOBAL"
}
resource "google_compute_subnetwork" "web" {
name = "web"
ip_cidr_range = "10.10.10.0/24"
network = google_compute_network.custom.id
region = var.region
secondary_ip_range = [
{
range_name = "services"
ip_cidr_range = "10.10.11.0/24"
},
{
range_name = "pods"
ip_cidr_range = "10.1.0.0/20"
}
]
private_ip_google_access = true
}
resource "google_compute_subnetwork" "data" {
name = "data"
ip_cidr_range = "10.20.10.0/24"
network = google_compute_network.custom.id
region = var.region
private_ip_google_access = true
}
クラウドナット
GKEによってインターネットにアクセスするのに我々のウェブサブネットを許すために、我々は雲ナットをつくる必要があります.クラウド・ナットをクラウド・ルータを使ってサブネットと関連づける.
地形ファイルを作成
resource "google_compute_address" "web" {
name = "web"
region = var.region
}
resource "google_compute_router" "web" {
name = "web"
network = google_compute_network.custom.id
}
resource "google_compute_router_nat" "web" {
name = "web"
router = google_compute_router.web.name
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = [ google_compute_address.web.self_link ]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = google_compute_subnetwork.web.id
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
depends_on = [ google_compute_address.web ]
}
ファイアウォール
ファイアウォールを使用すると、VMインスタンス、ネットワークタグまたはサービスアカウントへの、およびインバウンドとアウトバウンドのネットワークトラフィックを制限できます.この場合、以下の規則を実装できます.
resource "google_compute_address" "web" {
name = "web"
region = var.region
}
resource "google_compute_router" "web" {
name = "web"
network = google_compute_network.custom.id
}
resource "google_compute_router_nat" "web" {
name = "web"
router = google_compute_router.web.name
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = [ google_compute_address.web.self_link ]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = google_compute_subnetwork.web.id
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
depends_on = [ google_compute_address.web ]
}
ファイアウォールを使用すると、VMインスタンス、ネットワークタグまたはサービスアカウントへの、およびインバウンドとアウトバウンドのネットワークトラフィックを制限できます.この場合、以下の規則を実装できます.
resource "google_compute_firewall" "mysql" {
name = "allow-only-gke-cluster"
network = google_compute_network.custom.name
allow {
protocol = "tcp"
ports = ["3306"]
}
priority = 1000
source_ranges = ["10.10.10.0/24"]
}
resource "google_compute_firewall" "web" {
name = "allow-only-authorized-networks"
network = google_compute_network.custom.name
allow {
protocol = "tcp"
}
priority = 1000
source_ranges = var.authorized_source_ranges
}
地形を整えましょう.地形ファイルを作成
variable "region" {
type = string
default = "europe-west1"
}
variable "authorized_source_ranges" {
type = list(string)
description = "Addresses or CIDR blocks which are allowed to connect to GKE API Server."
}
ファイルを追加するterraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.71.0"
}
}
}
ファイルを追加するprovider "google" {
region = "europe-west1"
}
とinfra/plan/nat.tf
terraform {
backend "gcs" {
}
}
さて、次の変数をエクスポートし、あなたのterraform状態を保存するためにバケツを作成します.export PROJECT_ID=<PROJECT_ID>
export REGION=<REGION>
export TERRAFORM_BUCKET_NAME=<BUCKET_NAME>
gcloud config set project ${PROJECT_ID}
gsutil mb -c standard -l ${REGION} gs://${TERRAFORM_BUCKET_NAME}
gsutil versioning set on gs://${TERRAFORM_BUCKET_NAME}
infra/plan/firewall.tf
を作成し、インフラストラクチャを展開します.authorized_source_ranges = ["<AUTHORIZED_NETWORK>"]
cd infra/plan
sed -i "s,<AUTHORIZED_NETWORK>,$AUTHORIZED_NETWORK,g" terraform.tfvars
terraform init \
-backend-config="bucket=${TERRAFORM_BUCKET_NAME}" \
-backend-config="prefix=state"
terraform apply
すべてのリソースが正しく作成されているか確認しましょうVPCとサブネット
![](https://s1.md5.ltd/image/5bcefd8c07ed7e60526e21bec4180e4e.png)
クラウドナット
![](https://s1.md5.ltd/image/04399aa689db803cc066e6abfa092a34.png)
ファイアウォール
![](https://s1.md5.ltd/image/a569b812b8065c757cf119342979305f.png)
結論
我々のネットワークは、現在我々のGCP資源を主催する準備ができています.で、我々はGKEのオートパイロットの設定に焦点を当てます.
Reference
この問題について(ネットワークで隔離されたネットワークを構成すること), 我々は、より多くの情報をここで見つけました
https://dev.to/stack-labs/configuring-an-isolated-network-in-google-cloud-5cib
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
Reference
この問題について(ネットワークで隔離されたネットワークを構成すること), 我々は、より多くの情報をここで見つけました https://dev.to/stack-labs/configuring-an-isolated-network-in-google-cloud-5cibテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol