Try   HackMD

GCP 進階技術課1

vpc

  • subnet 不能跨 region,可以跨 zone
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • vpc 可以用來切割環境,ex: stage, prod

vpc 設定

自動子網路模式

  • 預設 CIDR /20,可擴成 /16
  • 有預設防火牆規則 tcp 22

default vpc

  • 39 region

custom vpc

  • 自己設定 CIDR

MTU(最大傳輸單元)

  • 網路層最大的封包上限
  • 預設 1460
  • MSS 固定? 以小的為主
  • cloud vpn, cloud interconnect
  • 兩個 VM 若 MTU 不同,可能會有網路問題,🈶️封包被丟棄風險
  • 最好是設 1500

secondary subset cidr range

primary secondary
node IP (必要存在) container ip
用一個 range(/24),可方便 node 裡面增長 Container 擴展 從 primary ip 分配出來
  • vpc 子網路不夠時,可以做擴展

shared vpc

  • 把一個專案(宿主 host project)的 vpc 分享給其他專案(service project)使用
  • 比較好管理,可以直接透過 host project 設定下面的 resource 的網路
  • host project
    • 也可以設在 folder 層級
    • 網路 foundation 層
    • cloud vpn
    • cloud routes
    • vpc firewall policies
  • service project
    • VM
    • load balancer
    • 下面層級的 service

優點:

  • cross-project commucation
  • 管理簡單、降低成本
  • host project 和 service project 是一對多的關係
  • 不同 network 是不同的計價,雖然都是同一個 vpc

Q&A:

  1. vpc subnet 切分可能是區分環境
  2. APP 跟 DB subnet 要區分嗎?
    放在一起但用防火牆控制,較好管理。
    目前智金也是,mlaas 底下都是同一個 subnet,因為可以透過: tag, sa, firewall 另外設定。

vpc peering (只需要流量費用,不用服務費用)

優點:

  • 同專案or不同專案 vpc network 都可以打 vpc peering
  • 主要是針對 vpc 之間,不同 vpc 之間是無法溝通的
  • 路由自動設定,但無法自動做跳轉

缺點:

  • vpc1 <-> vpc2 <-> vpc3,此時 1 3 不能互聯
  • vpc1 <-> vpc2 <-> vpc3,1 3 ip range 重複,就不能建 2 3 peering
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

實作

vpc 內的機器可自由連線

  • 於 vpc networks 操作 create
  • MTU 選 1500
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

shared vpc

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

創建 vm a & b

  • network 的地方記得選剛剛建立的 vpc
  • 選 E2 micro 可以最便宜!

connectivity test (測試 network 有沒有通)

  • 先將 network management API enable
  • 選 icmp 來測試
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    (也可以用 VM A ssh 進去 ping VM B 內部IP)

compute engine

收費

  • 用多少算多少,以分鐘計費
  • 暫時關機後,收費 disk, cpu 跟 static ip

機器類型:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

- E2: 成本優化
- N2 系列: 廣泛使用,成本效能佳
- T2D, T2A: 單一core 效能高
- CPU: H3, C2系列
- Memory: M系列
- Accelerate: A系列

VM life cycle

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

- reset 會把 memory 直接清除
- 但如果 vm 有問題,還是用 restart 比較好,可以重新做硬體配置

VM disk

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • 可以增大,不能縮小

  • 影響 IOPS

    • 機器類型 core數
    • vcpu 變化
    • 磁碟大小
  • disks and snapshot

    • 可以設立快照排程,預設保留 14 天

image

類別:

  • public images
    • 免費 image
    • 收費 按 core 收
  • custom images
    • 依照儲存資源收

snapshop

種類

  • 標準
  • 封存
  • 即時: 要快,所以不會備份到不同 region

注意

  • 一旦刪除就無法復原

特性

  • 差異備份,類似 wal 檔那樣
  • 使用 reference 的方式
  • 第二個快照會是第一個的變更
    image
  • 如果中間有快照被刪除,會把被刪除的快照存放到下一個快照中
    image

作法

  • 每小時標準快照一次

登入 VM 方式

SSH login

  1. ssh keys
  2. OS login (建議)
    用 linux account, cloud identity 綁定 MFA

實作

自動排程開關機VM

image

  • Instance schedule details:
    • 新增 add instance to schedule
    • 一旦建立就無法更動
    • 需跟 vm 同個 region
    • 記得 service account(是 gcp 建立的 sa) 必須要有 compute admin 權限

firewall

vpc firewall rules
attach rules to vms by:

  • tags
  • service account
  • 針對單一或全球的 vpc

default rule

  • priority 越小越優先
  1. ipv4
    • ingress 所有進來的都會被擋掉 deny
    • egress 所有出去的都會被允許 allow
  2. ipv6

policy
attach policy to vms by:

  • tags
  • service account
    可附加在多個 vpc 上
    高階會有費用
    可透過 domain(FQDN) 方式作為防火牆限制目標

firewall log

  • 不同防火牆規則需分別開啟
  • 會產生額外費用
  • 存在 cloud log 裏面,能設定 alert
  • 可用來驗證與分析防火牆規則

實作

限制 vm 不能造訪特地網域

  • create network policy > add rule
    image
  • Q&A
  1. 預設 egress 全通,哪個條件有寫,怎麼看得出來?
  2. 如果預設全通,這樣為麼 priority 可以寫這麼大,而不會不會被讀到?
    image

instance group

  • 非託管:讓多個 vm 放在同個 group,就可以做 load balance
  • 託管 MIG:透過建立好的template(yaml),限制將來要起的 vm 的 resource,達到快速起 vm auto-scaling,限制起在同or不同 zone or region
    auto-scaling 條件
  • cpu 使用率
  • load balancer capacity
  • monitoring metrics
  • queued workload
  • 做 health check (5s 一次),不健康就會拒絕 LB 傳來的流量

cloud SQL

特性

  • 全代管的服務
  • 支援 genAI
  • 遷移作業簡單:DMS
  • 支援 mysql, postgresql, sqlserver
  • 支援多個用戶端

資源上限

  • 64 TB
  • 60000 IOPS
  • 864 GB of RAM
  • scale out with read replicas

edition

  • enterprise
  • enterprise plus
  • 創建後就不能修改 edition

特性

  • cpu 一定是 1:8 不能動
  • 服務可使用內網連線(private service access),一旦啟用就不能關閉
  • 會另外起在 gcp 管理的 vpc 中,所以其實 gcp 會自動幫你建 vpc peering,才能連線

replicate

  • cascading replcas
    • 災難復原:可藉由推送備援資源 來推成 primary
    • 效能提升方式: 讀寫分離
    • 同 region -> 費用降低

高可用性 HA

  • zone A 壞掉的話,可以把 ip 指到 standby 的 zone B cloud SQL,減少停機時間
  • HA 費用變兩倍,看開幾個 HA XD

故障切換

image
image

maintenance
https://cloud.google.com/sql/docs/mysql/maintenance#how_maintenance_works

  • 3 months 維修一次,會有停機,但可以拒絕維修,最長是 90 天,但建議還是要維護!****
  • enterprise plus: 10s
  • enterprise: 60s > 明明都很短!!! XD
    image

    image

    image
  • static ip 會從 original vm 換成指到 updated vm,再把 original vm 刪掉!就是維護完成

實作

透過內部網路來存取 cloud sql

  • resource 至少選 4 core 才不會啟動太久!
  • connections 選 private ip
  • data protection: enable deletion 不要勾選
    image

    image

一整天下來還真的很累,需要療癒圖

image

好可愛唷!!!!!