GCP k8s 創建並啟用服務範例

紀錄google 雲端學習Lab的command

設定default region

1
gcloud config set compute/region us-east1

設定default zone

1
gcloud config set compute/zone us-east1-d

創建cluster

1
gcloud container clusters create --machine-type=e2-medium --zone=us-east1-d lab-cluster
  • output
    1
    2
    3
    4
    5
    6
    7
    8
    NAME: lab-cluster
    LOCATION: us-east1-d
    MASTER_VERSION: 1.22.8-gke.202
    MASTER_IP: 34.67.240.12
    MACHINE_TYPE: e2-medium
    NODE_VERSION: 1.22.8-gke.202
    NUM_NODES: 3
    STATUS: RUNNING

cluster授權

1
gcloud container clusters get-credentials lab-cluster
  • output
    1
    2
    Fetching cluster endpoint and auth data.
    kubeconfig entry generated for my-cluster.

deploy server to cluster

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

檢查服務

1
kubectl get service
  • output
    1
    2
    3
    NAME             TYPE            CLUSTER-IP      EXTERNAL-IP     PORT(S)           AGE
    hello-server loadBalancer 10.39.244.36 35.202.234.26 8080:31991/TCP 65s
    kubernetes ClusterIP 10.39.240.1 433/TCP 5m13s

刪除cluster

1
gcloud container clusters delete lab-cluster

GCP k8s 創建並啟用服務範例
https://shengshengyang.github.io/2023/12/09/gcp-k8s-create/
作者
Dean Yang
發布於
2023年12月9日
許可協議