<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Google Kubernetes Engine - 東東 GCP 教學 - GCP 實戰講師</title>
	<atom:link href="https://dongdonggcp.com/category/google-kubernetes-engine/feed/" rel="self" type="application/rss+xml" />
	<link>https://dongdonggcp.com</link>
	<description>助你考取證照，轉職成功</description>
	<lastBuildDate>Sun, 20 Jul 2025 08:41:05 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://dongdonggcp.com/wp-content/uploads/2025/04/cropped-340838097_121391010914395_5443948698124160121_n-32x32.jpg</url>
	<title>Google Kubernetes Engine - 東東 GCP 教學 - GCP 實戰講師</title>
	<link>https://dongdonggcp.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">243235092</site>	<item>
		<title>Google Kubernetes Engine 是什麼？GKE 簡介與手把手操作教學</title>
		<link>https://dongdonggcp.com/2025/07/20/google-kubernetes-engine-tutorials/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-kubernetes-engine-tutorials</link>
					<comments>https://dongdonggcp.com/2025/07/20/google-kubernetes-engine-tutorials/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 20 Jul 2025 05:20:24 +0000</pubDate>
				<category><![CDATA[Google Kubernetes Engine]]></category>
		<category><![CDATA[CI/CD]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[GKE]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[容器]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=11119</guid>

					<description><![CDATA[<p>Google Kubernetes Eengine 是 Kubernetes 在 GCP 的雲端加值版本，可以讓你的 Kubernetes 在管理 Docker 容器應用程式的時候，更方便好用。</p>
<p>The post <a href="https://dongdonggcp.com/2025/07/20/google-kubernetes-engine-tutorials/">Google Kubernetes Engine 是什麼？GKE 簡介與手把手操作教學</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Google Kubernetes Eengine 是 Kubernetes 在 GCP 的雲端加值版本，可以讓你的 Kubernetes 在管理 Docker 容器應用程式的時候，更方便好用。</p>



<p>假如你本來就已經會使用容器技術，例如 Docker，可以使用虛擬機器或是 <a href="https://dongdonggcp.com/2025/07/20/cloud-run-tutorials/" target="_blank" rel="noopener" title="">Cloud Run</a> 來運作容器應用程式，但當我們的系統變得更加複雜時，我們可能需要更強大的工具來管理整個應用程式生態系統。</p>



<p>這時候就需要「容器編排」技術了。編排（Orchestration）這個詞來自音樂領域，就像指揮家需要協調管弦樂團中的各種樂器，讓他們在正確的時間演奏正確的音符，最終產生和諧的音樂一樣，容器編排就是自動化協調和管理複雜系統中多個容器元件的過程。它負責決定哪些容器應該在哪裡運行、如何分配資源、確保容器間的通訊，以及根據需求自動擴展或縮減容器數量。</p>



<h2 class="wp-block-heading">Kubernetes 簡介</h2>



<h3 class="wp-block-heading">為什麼需要 <a href="https://kubernetes.io/" target="_blank" rel="noopener" title="">Kubernetes</a>？</h3>



<p>想像一下，你正在經營一家大型的線上商店。最初，你可能只有一個簡單的網站容器在運行，這時 Cloud Run 就足夠了。但隨著業務成長，你的系統開始變得複雜：</p>



<ul class="wp-block-list">
<li>前端網站需要與後端 API 服務通訊</li>



<li>需要負載平衡來分配流量</li>



<li>某些服務需要定期備份和更新</li>



<li>不同的服務有不同的資源需求</li>



<li>需要監控各個環節的健康狀態</li>
</ul>



<p>這時候，單純使用多個獨立的容器服務就變得難以管理。你需要手動協調各個服務之間的通訊、處理故障恢復、管理各種設定檔和機密資訊等等。這就是 Kubernetes 要解決的問題。</p>



<figure class="wp-block-image aligncenter size-large"><img fetchpriority="high" decoding="async" width="1024" height="683" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-1-單個容器獨立管理因數量變多導致工作繁重-1024x683.jpg" alt="" class="wp-image-11120" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-1-單個容器獨立管理因數量變多導致工作繁重-1024x683.jpg 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-1-單個容器獨立管理因數量變多導致工作繁重-300x200.jpg 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-1-單個容器獨立管理因數量變多導致工作繁重-768x512.jpg 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-1-單個容器獨立管理因數量變多導致工作繁重.jpg 1440w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">單個容器獨立管理因數量變多導致工作繁重</figcaption></figure>



<p>Kubernetes（常簡稱為 K8s）是一個開源的容器編排平台，它就像是一個聰明的指揮家，能夠協調和管理大量的容器化應用程式。</p>



<h3 class="wp-block-heading">Kubernetes 的核心價值</h3>



<p>它的核心價值在於：</p>



<p>自動化部署和擴充：<br>根據負載自動增加或減少容器執行個體的數量。</p>



<p>服務發現 (Service Discovery) 和負載平衡：<br>服務發現機制讓服務能夠輕鬆找到彼此，並自動分配流量到健康的容器。</p>



<p>自我修復能力：<br>當某個容器發生故障，會自動重啟新的容器，確保系統的高可用性。</p>



<p>設定和機密資訊管理：<br>提供了統一的方式來管理應用程式的設定資訊和敏感資料。</p>



<p>滾動更新 (Rolling Update)：<br>能夠逐步替換舊版本的容器，確保服務不中斷。</p>



<h3 class="wp-block-heading">從單一容器到容器叢集</h3>



<p>如果說 Cloud Run 讓我們能夠輕鬆運行單一的容器化應用程式，那麼 Kubernetes 就是讓我們能夠管理整個容器化應用程式生態系統的平台。它將多個容器組織成一個協調運作的叢集 (Cluster) ，每個容器都有自己的角色和責任，但它們共同協作來提供完整的服務。</p>



<p>就像管理一個小型團隊發展到管理一個大型組織。在小團隊中，每個人可能身兼多職，溝通簡單直接。但在大型組織中，你需要明確的分工、標準化的流程、有效的溝通機制，以及能夠快速適應變化的管理體系。</p>



<h2 class="wp-block-heading">Google Kubernetes Engine (GKE) 簡介</h2>



<p>雖然 Kubernetes 非常強大，但設置和維護一個 Kubernetes 叢集本身就是一項複雜的任務。你需要處理主節點的高可用性、網路配置、安全性設定、監控和日誌收集等等。</p>



<p>你可以在地端，或使用 Compute Engine 的虛擬機器來架設 Kubernetes，但是整個過程非常繁瑣，架設完成還要處理各個節點之前的通訊，極為複雜且耗時，當你花了好幾搭建好環境，你都還沒處理到應用程式的部分。</p>



<p>這就是為什麼 Google 推出了 <a href="https://cloud.google.com/kubernetes-engine?hl=zh-TW" target="_blank" rel="noopener" title="">Google Kubernetes Engine</a>。</p>



<figure class="wp-block-image aligncenter size-large"><img decoding="async" width="1024" height="782" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-2-8-自建-Kubernetes-和使用-GKE-的比較-1024x782.png" alt="" class="wp-image-11121" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-2-8-自建-Kubernetes-和使用-GKE-的比較-1024x782.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-2-8-自建-Kubernetes-和使用-GKE-的比較-300x229.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-2-8-自建-Kubernetes-和使用-GKE-的比較-768x587.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-2-8-自建-Kubernetes-和使用-GKE-的比較.png 1169w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">在自建 Kubernetes 和直接使用 GKE 的建置過程差異</figcaption></figure>



<p>GKE 是 Google Cloud 提供的代管式 Kubernetes 服務。它讓你能夠善用 Kubernetes 的所有強大功能，同時 Google 會負責處理底層的基礎建設管理工作。代表你可以專注於開發和部署應用程式，而不需要擔心 Kubernetes Cluster 本身的維護。</p>



<h3 class="wp-block-heading">Kubernetes 的幾個核心物件</h3>



<p>在開始使用 GKE 之前，先來了解 Kubernetes 的幾個核心物件：</p>



<h3 class="wp-block-heading">Node：工作節點而非虛擬機器</h3>



<p>Node 是指叢集中的工作節點。為什麼不直接叫「虛擬機器」？因為 Node 是一個更抽象的概念：它可以是實體機器或虛擬機器。Kubernetes 把這些不同類型的運算資源統一稱為 Node，強調的是它們的「工作節點」角色，能夠運作容器，至於它們到底是怎樣的機器，其實並不重要。</p>



<h3 class="wp-block-heading">Pod：容器的最小單位</h3>



<p>Pod 是 Kubernetes 中部署和管理的最小單位。一個 Pod 通常包含一個容器，但也可以包含多個緊密相關的容器。這些容器共享網路和儲存資源，就像室友共享一個公寓一樣。Pod 的生命週期很短暫，隨時可能被創建或銷毀。</p>



<h3 class="wp-block-heading">Deployment：管理應用程式的生命週期</h3>



<p>Deployment 負責管理你的應用程式如何部署和更新。它告訴 Kubernetes：「我想要運行 3 個網站的副本」，然後 Deployment 會確保始終有 3 個健康的 Pod 在運行。如果某個 Pod 掛掉了，Deployment 會自動建立新的來替代。當你要更新應用程式時，Deployment 也會協調整個更新過程。</p>



<h3 class="wp-block-heading">Service：穩定的網路端點</h3>



<p>由於 Pod 會頻繁地建立和銷毀，它們的 IP 地址也會不斷變化。Service 就像是一個穩定的門牌號碼，為一組 Pod 提供固定的網路端點。無論後面的 Pod 如何變化，其他服務都可以通過 Service 找到它們，不需要你手動調整網路連結。</p>



<h3 class="wp-block-heading">Ingress：對外開放的大門</h3>



<p>Ingress 是叢集的對外入口，負責將外部的 HTTP/HTTPS 流量路由到叢集內的 Service。它就像是一個智慧的接待人員，根據 URL 路徑或網域將流量導向正確的服務。比如，當用戶訪問 api.example.com 時，Ingress 會將請求轉發給 API 服務；訪問 app.example.com 時，則轉發給前端應用程式。</p>



<p>整體的運作架構示意如下圖：</p>



<figure class="wp-block-image aligncenter size-large"><img decoding="async" width="1024" height="829" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-3-Kubernetes-核心物件-1024x829.png" alt="" class="wp-image-11122" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-3-Kubernetes-核心物件-1024x829.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-3-Kubernetes-核心物件-300x243.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-3-Kubernetes-核心物件-768x621.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-3-Kubernetes-核心物件.png 1142w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Kubernetes 核心物件架構</figcaption></figure>



<p>這些元件形成了一個完整的體系：Node 提供運算資源，Pod 在 Node 上運行你的應用程式，Deployment 管理 Pod 的生命週期，Service 為 Pod 提供穩定的網路訪問方式，而 Ingress 則負責將外部流量導入到正確的 Service。</p>



<p>就像一個運作良好的公司：Node 是辦公大樓，Pod 是員工工作的辦公室，Deployment 是人事部門負責人員配置，Service 是內部電話系統，而 Ingress 是前台接待處。</p>



<h2 class="wp-block-heading">建立你的第一個 GKE Cluster</h2>



<p>了解了 Kubernetes 的核心概念後，現在讓我們實際建立一個 GKE Cluster。GKE 提供了兩種主要的叢集模式，讓我們先來了解它們的差異。</p>



<h3 class="wp-block-heading">Standard 模式 vs Autopilot 模式</h3>



<p>GKE 提供兩種不同的 Cluster 運作模式，各有其適用場景：</p>



<p>Standard 模式（標準模式）</p>



<p>Standard 模式讓你擁有完整的控制權，就像擁有一輛可以自己調整引擎、變速箱的汽車。你需要自己管理節點（Node）的配置、擴展策略、安全性設定等等。這種模式適合有經驗的團隊，需要精細控制叢集行為，或是有特殊的硬體需求。</p>



<p>要注意的是，當你建立完 Cluster，它會幫你建立好節點，其實你還沒部署應用程式，代表這些節點資源已經開始隨著時間計費，這樣會浪費你的預算，你就可以選擇 Autopilot 模式。</p>



<p>Autopilot 模式（自動駕駛模式）</p>



<p>Autopilot 模式就像使用自動駕駛汽車，Google 會自動處理大部分的基礎設施管理工作。它會自動配置節點、處理安全性更新、優化資源使用，並且只針對你實際使用的 Pod 資源收費，所以讓你還沒部署 Pod 的時候，還沒建立任何 Node，就不會針對 Node 收取費用。</p>



<p>這種模式特別適合想要專注於應用程式開發，而不想花時間管理基礎設施的團隊。對於初學者和大多數應用場景，我們推薦使用 Autopilot 模式，因為它大幅簡化了叢集管理的複雜度。</p>



<h3 class="wp-block-heading">使用 GCP Console 來建立 GKE Autopilot Cluster</h3>



<p>讓我們透過 Google Cloud Console 來建立第一個 Autopilot Cluster，點擊「叢集」，再點「建立」：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="532" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-4-建立第一個-GKE-Cluster-1024x532.png" alt="" class="wp-image-11123" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-4-建立第一個-GKE-Cluster-1024x532.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-4-建立第一個-GKE-Cluster-300x156.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-4-建立第一個-GKE-Cluster-768x399.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-4-建立第一個-GKE-Cluster.png 1234w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">建立第一個 GKE Cluster</figcaption></figure>



<p>名稱我們保持預設，區域一樣選擇 asia-east1，然後在級別的部分選擇「標準級」，然後再點「下一個區段：機群註冊」：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="364" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別-1024x364.png" alt="" class="wp-image-11124" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別-1024x364.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別-300x107.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別-768x273.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別-1536x546.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-5-Cluster-命名、設定位置和級別.png 1884w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Cluster 命名、設定位置和級別</figcaption></figure>



<p>GKE 有個最新功能叫做 GKE Fleet Management，可以將不同 Google Cloud 專案中的GKE Cluster 地群組在一起，而且不只 GKE Cluster，也包含地端環境、其他雲端平台的 Cluster 都可以納入管理，這樣就能一次管理所有應用程式，簡化維運工作。</p>



<p>在這裡我們只有一個 Cluster，所以可略過這個功能，再點「下一個區段：網路連線」：</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="815" height="478" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-6-機群註冊可略過.png" alt="" class="wp-image-11125" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-6-機群註冊可略過.png 815w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-6-機群註冊可略過-300x176.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-6-機群註冊可略過-768x450.png 768w" sizes="(max-width: 815px) 100vw, 815px" /><figcaption class="wp-element-caption">機群註冊</figcaption></figure>



<p>在這裡保持預設即可，其中可以注意的是，最右邊有 Pod 和 Service 的 IP 範圍，代表 Kubernetes 會分配 IP 位址給它們使用，而在 GKE 環境下，就是會把 Subnet 的次要 IP 範圍自動分配給它們，我們不用額外設定。再點「下一個區段：進階設定」：<br></p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="354" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路-1024x354.png" alt="" class="wp-image-11126" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路-1024x354.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路-300x104.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路-768x266.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路-1536x531.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-7-Cluster-網路.png 1905w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">GKE Cluster 網路設定</figcaption></figure>



<p>在「目前發布版本」的下拉式選單中，我們選擇「一般（建議）」，然後再按下「建立」：&nbsp;<br></p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="481" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster--1024x481.png" alt="" class="wp-image-11127" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster--1024x481.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster--300x141.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster--768x361.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster--1536x722.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-8-選擇版本類型並建立-Cluster-.png 1868w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">選擇版本類型並建立 Cluster</figcaption></figure>



<p>接下來就等待&nbsp; Cluster 建立完成，在這裡大概需要等待 5～10 分鐘左右：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="500" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-9-等待-Cluster-建立完成-1024x500.png" alt="" class="wp-image-11128" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-9-等待-Cluster-建立完成-1024x500.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-9-等待-Cluster-建立完成-300x146.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-9-等待-Cluster-建立完成-768x375.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-9-等待-Cluster-建立完成.png 1092w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">等待 GKE Cluster 建立完成</figcaption></figure>



<p>這裡順便補充一下，大部分熟悉 Kubernertes 的工程師都偏好使用指令來建立和管理 GKE Cluster，我們也開啟 Cloud Shell 來建立第二個 Cluster 看看吧！</p>



<h3 class="wp-block-heading">使用 gcloud 指令建立 Autopilot Cluster</h3>



<p>gcloud container clusters create-auto autopilot-cluster-2&nbsp; &#8211;region=asia-east1 &nbsp; &nbsp; &#8211;release-channel=regular</p>



<p>執行完後，你會看到它在建立過程的相關訊息，包含 Cluster 名稱、版本、Cluster IP、機器類型、節點數量等等：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="317" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成-1024x317.png" alt="" class="wp-image-11129" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成-1024x317.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成-300x93.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成-768x238.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成-1536x475.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-10-使用指令建立-GKE-Cluster-完成.png 1882w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">使用指令建立 GKE Cluster 完成</figcaption></figure>



<h3 class="wp-block-heading">使用 gcloud 和 kubectl 指令操作 GKE Cluster </h3>



<p>我們回到建立好的 autopilot-cluster-1，我們可以用指令來查看它的相關資訊 (autopilot-cluster-2 如果沒用到可以先刪除)：</p>



<p>取得 Cluster 憑證以便使用 kubectl 工具</p>



<p>gcloud container clusters get-credentials autopilot-cluster-1&nbsp; &#8211;region=asia-east1</p>



<p>這個指令的作用就像是取得鑰匙，告訴 kubectl 叢集在哪裡，並且提供身分驗證資訊，來證明你有權限管理這個 Cluster 的憑證，然後把連線的設定儲存在本機電腦的 ~/.kube/config 檔案。</p>



<p>檢查叢集狀態</p>



<p>kubectl cluster-info</p>



<p>查看節點資訊</p>



<p>kubectl get nodes</p>



<p>檢查系統 Pod 狀態</p>



<p>kubectl get pods &#8211;all-namespaces</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="481" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊-1024x481.png" alt="" class="wp-image-11130" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊-1024x481.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊-300x141.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊-768x361.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊-1536x722.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-11-使用指令查看-Cluster-相關資訊.png 1870w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">使用 kubectl 指令查看 GKE Cluster 相關資訊</figcaption></figure>



<p>到這裡你可能會覺得奇怪，為什麼指令分成 gcloud 和 kubectl？</p>



<p>gcloud 是 Google Cloud 的管理工具，負責管理 Google Cloud 上的資源，包含建立或刪除 GKE 叢集、管理帳單、權限、API 啟用。</p>



<p>而 kubectl 是 Kubernetes 用來管理 Cluster 內部的應用程式。能夠部署應用程式到 Cluster、查看 Pod、Service 的狀態、管理設定檔和執行日常維護工作。</p>



<p>而且每次下達 kubectl 指令，並不會用參數指定要操作的 Cluster，當你專案內有多個 Cluster 的時候，它不會知道你要對誰操作，所以才必須要 get-credentials 這個指令，才能操作到正確的 Cluster，當然你也可以再執行一次 get-credentials，切換到另外一個 Cluster，再去執行管理動作。&nbsp;</p>



<h2 class="wp-block-heading">部署應用程式到 GKE Cluster</h2>



<h3 class="wp-block-heading">使用 GKE Deployment 物件部署容器映像檔到 Pod </h3>



<p>Cluster 建立完成，現在來部署應用程式到 Cluser，我們點擊「佈署」（雖然我覺得是「部署」）：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="498" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-12-部署應用程式-1024x498.png" alt="" class="wp-image-11131" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-12-部署應用程式-1024x498.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-12-部署應用程式-300x146.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-12-部署應用程式-768x373.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-12-部署應用程式.png 1152w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">部署應用程式到 GKE</figcaption></figure>



<p>這裡設定的部署作業就像上面提到的 deployment 物件，我們可以在這裡指定跟上個單元相同的容器映像檔，再按「下一步：公開（選用）」：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="562" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器-1024x562.png" alt="" class="wp-image-11132" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器-1024x562.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器-300x165.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器-768x421.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器-1536x842.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-13-設定部署的目的-Cluster-和容器.png 1909w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">設定部署的目的 Cluster 和容器</figcaption></figure>



<h3 class="wp-block-heading">部署 GKE Service 物件 （Network Load Balancer）</h3>



<p>做到這裡可以讓 Pod 部署完成，但是要注意這個設定還不會讓 Pod 直接對外，你必須在勾選「以新 Service 的形式公開 Deployment」 。</p>



<p>在這裡要注意，我們當初在建立容器映像檔的時候，我們讓容器本身對外開放 Port 8080，上面的 80 是指負載平衡器對外的 Port，但是當流量進來之後，要指定 8080 才能存取到容器上的網頁喔。&nbsp;</p>



<p>在服務類型保持預設的「負載平衡器」，它就會直接在 Google Cloud 上建立負載平衡器。 然後我們再按下建立。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="726" height="812" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-14-設定-Service.png" alt="" class="wp-image-11133" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-14-設定-Service.png 726w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-14-設定-Service-268x300.png 268w" sizes="(max-width: 726px) 100vw, 726px" /><figcaption class="wp-element-caption">設定 Service</figcaption></figure>



<p>接下來再等待幾分鐘會看到這個 Deployment 已經部署完成了，視窗可以再往下滑：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="681" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-15-看到-Deployment-部署完成-1024x681.png" alt="" class="wp-image-11134" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-15-看到-Deployment-部署完成-1024x681.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-15-看到-Deployment-部署完成-300x200.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-15-看到-Deployment-部署完成-768x511.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-15-看到-Deployment-部署完成.png 1360w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">看到 Deployment 部署完成</figcaption></figure>



<p>我們往下看到各種物件產生，包含一個 Deployment 物件，和三個 Pod 物件，都是在正常運作的狀態：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="533" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-16-往下看到各種物件產生-1024x533.png" alt="" class="wp-image-11135" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-16-往下看到各種物件產生-1024x533.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-16-往下看到各種物件產生-300x156.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-16-往下看到各種物件產生-768x400.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-16-往下看到各種物件產生.png 1159w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">往下看到各種物件產生</figcaption></figure>



<p>你可以再打開 Cloud Shell，下達各種相關的查詢指令 (記得要先 get-credentials) 喔！&nbsp;</p>



<p>查看目前部署的 Deployment</p>



<p>kubectl get deployments</p>



<p>查看目前部署的 Pod</p>



<p>kubectl get pods</p>



<p>查看目前部署的 Service&nbsp;</p>



<p>kubectl get services</p>



<p>你會看到它有產生一個外部 IP，是對外開放存取的。</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="350" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令-1024x350.png" alt="" class="wp-image-11136" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令-1024x350.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令-300x103.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令-768x263.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令-1536x525.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-17-輸入各項查詢指令.png 1866w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">輸入 kubectl 各項查詢指令</figcaption></figure>



<p>你可以打開瀏覽器輸入 https://[IP位址]，或是直接在 Web Console 上面點擊會看到網頁秀出來，不過在這裡要稍微等待一下，因為我們現在使用的是 Autopilot 模式，是連 Node 都還沒建立的情況，所以現在要先等它建立 Node，再部署 Deployment、Pod 和 Service。</p>



<p>過幾分鐘之後，我們看到它部署完成，也看到網頁出現了！</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="610" height="299" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-18-點擊服務連結看到網頁出現.png" alt="" class="wp-image-11137" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-18-點擊服務連結看到網頁出現.png 610w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-18-點擊服務連結看到網頁出現-300x147.png 300w" sizes="(max-width: 610px) 100vw, 610px" /><figcaption class="wp-element-caption">點擊服務連結看到網頁出現</figcaption></figure>



<p>另外我們也可以在負載平衡器頁面看到一個負載平衡器：</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="300" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-1024x300.png" alt="" class="wp-image-11138" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-1024x300.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-300x88.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-768x225.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-1536x450.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-19-也可以在負載平衡器頁面看到一個-TCP-負載平衡器-2048x600.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">也可以在負載平衡器頁面看到一個 TCP 負載平衡器</figcaption></figure>



<p>要注意它是 TCP 負載平衡器，它工作在網路的第 4 層（傳輸層），只能根據 IP 位址和 Port 來分配流量。無法根據 URL 路徑進行導向 (例如 /api 或 /admin)，也無法根據網域名稱進行路由。</p>



<p>如果我們想要更聰明的流量路由功能，就需要使用 Application Load Balancer (ALB)。ALB 工作在第 7 層（應用層），能夠處理 HTTP/HTTPS 通訊協定的內容，提供更豐富的路由功能。</p>



<p>但目前在 Google Cloud 的 Console 上沒有辦法直接建立 ALB，必須要使用指令和設定檔的方式，來建立 Ingress 物件。</p>



<h3 class="wp-block-heading">部署 GKE Ingress 物件 (Application Load Balancer)</h3>



<p>不過！現在要先刪除原有的 deployment-1-service (Load Balancer)，以免後續物件在建立時，會有衝突喔！</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="487" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--1024x487.png" alt="" class="wp-image-11139" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--1024x487.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--300x143.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--768x365.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--1536x731.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-20-刪除-deployment-1-service-Load-Balancer--2048x974.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">刪除&nbsp; deployment-1-service (Load Balancer)</figcaption></figure>



<p>刪除之後，我們再建立 2 個物件：</p>



<p>第一個物件：ClusterIP 類型的 Service</p>



<p>ClusterIP Service 是 Kubernetes 中最基本的 Service 類型，它只在 Cluster 內部提供一個穩定的 IP 位址和 DNS 名稱。雖然 ClusterIP Service 無法從 Cluster 外部直接訪問，但它為 Cluster 內部的通訊提供了完美的抽象層。</p>



<p>你可以把 ClusterIP Service 想像成公司內部的分機號碼系統。員工可以通過分機號碼找到彼此，但外部的人無法直接撥打分機號碼。</p>



<p>我們現在 Cloud Shell 的環境準備好一個設定檔 cluster-ip-service.yaml，內容如下：</p>



<pre class="wp-block-code"><code>apiVersion: v1
kind: Service
metadata:
  name: deployment-1-service
  labels:
    app: deployment-1
spec:
  type: ClusterIP 
  selector:
    app: deployment-1
    app.kubernetes.io/managed-by: cloud-console
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
</code></pre>



<p>接著來執行這個指令：</p>



<p>kubectl apply -f cluster-ip-service.yaml</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="131" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-1024x131.png" alt="" class="wp-image-11141" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-1024x131.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-300x39.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-768x99.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-1536x197.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-21-執行部署-ClusterIP-Service-物件-2048x263.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">執行部署 ClusterIP Service 物件</figcaption></figure>



<p>這裡說明一下指令和參數：</p>



<p>kubectl apply&nbsp;</p>



<p>這是 Kubernetes 的宣告式管理指令。它的意思是：「讓 Cluster 的實際狀態符合這個檔案中描述的期望狀態」。如果資源不存在，它會建立；如果已存在但設定有任何不同，它會更新。</p>



<p>-f 參數</p>



<p>代表 &#8220;file&#8221;，告訴 kubectl 從檔案中讀取設定。你也可以使用 -f 指定多個檔案，或是指定包含多個 YAML 檔的目錄。</p>



<p>YAML（YAML Ain&#8217;t Markup Language）</p>



<p>這是是一種人類易讀的資料序列化格式。在 Kubernetes 中，我們使用 YAML 檔來描述我們想要的資源狀態。</p>



<p>在 Kubernetes 的術語中，這些 YAML 檔被稱為 Manifest（資訊清單）。Manifest 是一份宣告式的文件，描述了 Kubernetes 資源的期望狀態。它不是告訴 Kubernetes「如何做」，而是告訴它「我想要什麼結果」，有點像在許願的感覺，而且它會使命必達的實現你的願望。</p>



<p>PS. 我以前不懂 Manifest 到底是什麼，但自從看了國外的吸引力法則或顯化法則，才知道 Manifest 就是顯化的意思，把你想要的現實呈現出來。</p>



<p>第二個物件：Ingress</p>



<p>Ingress 是真正負責處理外部流量並提供 ALB 功能的物件，它就像是建築物的智慧接待處，能夠根據 URL 路徑決定要導向哪個服務，也能根據網域名進行路由，把流量帶向目的服務。（感覺跟 Load Balancer 一模一樣）</p>



<p>設定檔 ingress-1.yaml 的內容如下：</p>



<pre class="wp-block-code"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-1
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "gce"
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: deployment-1-service
            port:
              number: 80
</code></pre>



<p>接著來執行這個指令：</p>



<p>kubectl apply -f ingress-1.yaml</p>



<p>你會看到它有一個警告訊息「 Warning: annotation &#8220;kubernetes.io/ingress.class&#8221; is deprecated, please use &#8216;spec.ingressClassName&#8217; instead」，是因為 Kubernetes 本身推薦使用新的 spec.ingressClassName，但 GKE 的官方文件卻說要用舊的註解方式。</p>



<p>在這裡以 GKE 的官方文件為主，不用理會該訊息。</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="168" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-1024x168.png" alt="" class="wp-image-11143" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-1024x168.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-300x49.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-768x126.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-1536x253.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-22-執行部署-Ingress-物件-2048x337.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">執行部署 GKE Ingress 物件</figcaption></figure>



<p>接下來需要等待至少 5~10 分鐘的時間，如果設定正確，就能夠在 Ingress 的地方看到一個前端的 IP，點擊之後就能看到網頁。</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="513" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-1024x513.png" alt="" class="wp-image-11144" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-1024x513.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-300x150.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-768x385.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-1536x769.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-23-Ingress-建立完成並看到網頁正常顯示-2048x1026.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Ingress 建立完成並看到網頁正常顯示</figcaption></figure>



<p>也能在負載平衡頁面看到 ALB，代表它能夠處理 HTTP/HTTPS 通訊協定的內容，提供更豐富的路由功能。</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="418" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB-1024x418.png" alt="" class="wp-image-11145" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB-1024x418.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB-300x122.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB-768x313.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB-1536x626.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-24-也能在負載平衡頁面看到-ALB.png 1864w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">也能在負載平衡頁面看到 ALB</figcaption></figure>



<p>恭喜你也把 GKE 的基本服務建立完成了，接下來還是要記得刪除相關服務喔！</p>



<h2 class="wp-block-heading">逐步刪除 GKE 物件</h2>



<h3 class="wp-block-heading">下 kubectl 指令刪除 GKE 物件</h3>



<p>你可以按照以下的順序刪除：</p>



<p>查詢 Ingress 名稱</p>



<p>kubectl get ingress</p>



<p>刪除 Ingress (執行後要等 3~5 分鐘刪除完畢)</p>



<p>kubectl delete ingress-1&nbsp;</p>



<p>查詢 Service 名稱</p>



<p>kubectl get service</p>



<p>刪除 Service&nbsp; (名稱為 kubernetes 的 Service 不用刪除)</p>



<p>kubectl delete service deployment-1-service</p>



<p>查詢 Deployment 名稱</p>



<p>kubectl get deployment</p>



<p>刪除 Deployment</p>



<p>kubectl delete deployment deployment-1</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="437" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件-1024x437.png" alt="" class="wp-image-11148" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件-1024x437.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件-300x128.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件-768x328.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件-1536x656.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-25-刪除-GKE-Cluster-上各個物件.png 1934w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">刪除 GKE Cluster 上各個物件</figcaption></figure>



<h3 class="wp-block-heading">直接刪除整個 GKE Cluster</h3>



<p>再用這個指令刪除整個 Cluster，其實你也可以跳過前面刪除物件的步驟，直接刪除 Cluster：</p>



<p>gcloud container clusters delete autopilot-cluster-1 &#8211;region asia-east1</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="230" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--1024x230.png" alt="" class="wp-image-11146" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--1024x230.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--300x68.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--768x173.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--1536x346.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-26-使用-gcloud-指令刪除-GKE-Cluster--2048x461.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">使用 gcloud 指令刪除 GKE Cluster</figcaption></figure>



<p>或是更簡單的方法，直接在 Web Console 上刪除整個 Cluster， Cluster 裡所有物件也都會跟著被刪除掉。</p>



<figure class="wp-block-image aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="572" src="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-1024x572.png" alt="" class="wp-image-11149" srcset="https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-1024x572.png 1024w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-300x167.png 300w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-768x429.png 768w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-1536x857.png 1536w, https://dongdonggcp.com/wp-content/uploads/2025/07/9-5-27-在-Web-Console-上刪除-GKE-Cluster-1-2048x1143.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">在 Web Console 上刪除 GKE Cluster</figcaption></figure>



<p>最後要跟各位提醒，Kubernetes 本身是一個博大精深的領域，本文礙於篇幅只能介紹到這裡，如果需要深入鑽研，建議各位再去尋找專門的書籍或文件來看。而且 Kubernetes 本身不斷在更新，GKE 也持續更新，所以現在看到可以運作的樣子，也許過不久後又會改變，所以還請大家持續追蹤 GCP 官方文件喔！</p>



<p>影片版教學如下：</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="ast-oembed-container " style="height: 100%;"><iframe title="[GKE 教學] 030 斷片也能學會，滑鼠點五下，建好 GKE ｜ Cluster、應用程式和負載平衡全部完成！！| 免費下載 GKE 簡報" width="1200" height="900" src="https://www.youtube.com/embed/VCXlIBm7qlo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>



<p></p><p>The post <a href="https://dongdonggcp.com/2025/07/20/google-kubernetes-engine-tutorials/">Google Kubernetes Engine 是什麼？GKE 簡介與手把手操作教學</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2025/07/20/google-kubernetes-engine-tutorials/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">11119</post-id>	</item>
		<item>
		<title>[GKE 教學] Config Connector 是什麼東東？如何使用？</title>
		<link>https://dongdonggcp.com/2024/12/02/gke-what-is-config-connector-and-how-to-use/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gke-what-is-config-connector-and-how-to-use</link>
					<comments>https://dongdonggcp.com/2024/12/02/gke-what-is-config-connector-and-how-to-use/#respond</comments>
		
		<dc:creator><![CDATA[東東]]></dc:creator>
		<pubDate>Mon, 02 Dec 2024 13:42:12 +0000</pubDate>
				<category><![CDATA[Google Kubernetes Engine]]></category>
		<category><![CDATA[Config Connector]]></category>
		<category><![CDATA[GitOps]]></category>
		<category><![CDATA[GKE]]></category>
		<category><![CDATA[K8s]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=8242</guid>

					<description><![CDATA[<p>Config Connector 是 G [&#8230;]</p>
<p>The post <a href="https://dongdonggcp.com/2024/12/02/gke-what-is-config-connector-and-how-to-use/">[GKE 教學] Config Connector 是什麼東東？如何使用？</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Config Connector  是 GCP 推出的一個重要工具，它可以讓我們用 Kubernetes 的方式來管理 Google Cloud 上的各種資源。</p>



<p>簡單來說，它就像是一個翻譯器，把 Google Cloud 的資源轉換成 Kubernetes 可以理解的格式。</p>



<p>在實際使用中，Config Connector 扮演著橋樑的角色。</p>



<p>當我們想要在Google Cloud上建立新的服務，比如說建立一個 Cloud Storage Bucket 或是設定一個負載平衡器，我們不需要去 GCP 的控制台點點按按，而是可以直接用 Kubernetes 的設定檔來描述我們想要的資源。</p>



<p>Config Connector會自動幫我們在Google Cloud上建立這些資源，並且持續確保它們的狀態符合我們的期望。</p>



<p>這個工具的強大之處在於它的自動化能力。</p>



<p>比如說，如果有人不小心在 GCP Console 上手動修改了某些設定，Config Connector 會自動發現這個變化，並把它改回到我們在設定文件中定義的狀態。這樣可以確保我們的環境始終保持一致性。</p>



<p>在安全性方面，Config Connector 完全整合了 Kubernetes 的權限管理系統。代表我們可以精確控制誰能夠管理哪些 GCP 的資源，而且所有的操作都有完整的稽核記錄。</p>



<p>使用 Config Connector 的時候，我們需要先在 Kubernetes Cluster 中安裝它，然後配置適當的權限。之後，我們就可以用 YAML 格式的設定檔來描述我們想要的Google Cloud資源。</p>



<p>這些配置文件可以存放在Git倉庫中，配合 CI/CD 流程實現自動化部署。</p>



<p>在實際工作中，Config Connector 特別適合需要經常建立和管理GCP 資源的團隊。</p>



<p>比如說開發團隊需要經常建立測試環境，或者維運團隊需要統一管理多個專案的資源，使用 Config Connector 都能大大提高工作效率。</p>



<p>當遇到問題時，我們可以通過查看 Config Connector 的 Log 來進行故障排除。它會清楚地告訴我們哪裡出了問題，比如權限不足或者資源設定有誤。這讓問題診斷和修復變得更加直接和簡單。</p>



<p>總的來說，Config Connector 是一個非常實用的工具，它讓 GCP 資源的管理變得更加自動化和規範化，特別適合已經在使用Kubernetes的團隊。它不僅簡化了日常運維工作，還能確保環境的一致性和可靠性。</p>



<p>要使用 Config Connector，先準備以下 YAML 檔案：</p>



<pre class="wp-block-code"><code>apiVersion: core.cnrm.cloud.google.com/v1beta1
kind: ConfigConnector
metadata:
  name: configconnector.core.cnrm.cloud.google.com
spec:
  mode: cluster
  googleServiceAccount: GSA_NAME@PROJECT_ID.iam.gserviceaccount.com</code></pre>



<p>當這個 YAML 被應用 (Apply) 到GKE後，它會在你的 Kubernetes Cluster 中設置 Config Connector，並且設定使用指定的 Google Service Account 來操作 GCP 資源。</p>



<p>例如我們想要建立一個 Bucket，可以準備以下的 YAML 檔：</p>



<pre class="wp-block-code"><code>apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
  name: my-bucket
spec:
  location: US-CENTRAL1
  uniformBucketLevelAccess: true</code></pre>



<p>當這個 YAML 被套用 Apply 到 GKE 後，流程是這樣的：</p>



<ol class="wp-block-list">
<li>GKE 中的 Config Connector 會讀取這個YAML檔</li>



<li>Config Connector 會解析這個檔案，了解到你想要創建一個Cloud Storage bucket</li>



<li>Config Connector 會使用它被配置的 Google Service Account的權限</li>



<li>通過 Google Cloud API 去創建實際的 Storage bucket</li>



<li>持續監控這個 bucket 的狀態，確保它符合 YAML 中描述的配置</li>
</ol>



<p>如果之後有人直接在 GCP 控制台修改了這個 bucket 的設定，Config Connector 會自動發現並改回 YAML 檔中定義的狀態。</p>



<p>這就是為什麼它特別適合用在 GitOps 的工作流程中，因為它能確保實際的 GCP 資源狀態始終與程式碼倉庫中的定義保持一致。</p>



<p></p><p>The post <a href="https://dongdonggcp.com/2024/12/02/gke-what-is-config-connector-and-how-to-use/">[GKE 教學] Config Connector 是什麼東東？如何使用？</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2024/12/02/gke-what-is-config-connector-and-how-to-use/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8242</post-id>	</item>
		<item>
		<title>[GKE 教學] Helm Charts 是什麼？什麼是 OCI 格式的 Charts？</title>
		<link>https://dongdonggcp.com/2024/12/02/gke-what-is-helm-charts-what-is-oci-charts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gke-what-is-helm-charts-what-is-oci-charts</link>
					<comments>https://dongdonggcp.com/2024/12/02/gke-what-is-helm-charts-what-is-oci-charts/#respond</comments>
		
		<dc:creator><![CDATA[東東]]></dc:creator>
		<pubDate>Mon, 02 Dec 2024 13:01:46 +0000</pubDate>
				<category><![CDATA[Google Kubernetes Engine]]></category>
		<category><![CDATA[GKE]]></category>
		<category><![CDATA[Helm]]></category>
		<category><![CDATA[Helm Charts]]></category>
		<category><![CDATA[OCI]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=8228</guid>

					<description><![CDATA[<p>Helm Charts 是 Kubern [&#8230;]</p>
<p>The post <a href="https://dongdonggcp.com/2024/12/02/gke-what-is-helm-charts-what-is-oci-charts/">[GKE 教學] Helm Charts 是什麼？什麼是 OCI 格式的 Charts？</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Helm Charts 是 Kubernetes 應用程式的打包格式，可以想像成是一個&#8221;食譜&#8221;，裡面包含了部署應用程式所需的所有 Kubernetes 資源定義。</p>



<p>主要包含：</p>



<ul class="wp-block-list">
<li>應用程式的 Kubernetes YAML 檔案（如 Deployment、Service、ConfigMap 等）</li>



<li>版本資訊</li>



<li>應用程式的配置選項</li>



<li>相依性設定</li>
</ul>



<p>舉例來說，如果要部署一個 WordPress 網站，一個 WordPress Chart 會包含：</p>



<pre class="wp-block-code"><code>wordpress/
  Chart.yaml          # Chart 的版本和資訊
  values.yaml         # 預設配置值
  templates/          # Kubernetes 資源模板
    deployment.yaml   # WordPress 的部署設定
    service.yaml      # 服務設定
    ingress.yaml      # 入口設定</code></pre>



<p></p>



<p>OCI（Open Container Initiative）原本是用來定義容器映像檔的標準格式，現在這個標準也被用來儲存 Helm Charts。</p>



<p>主要優點：</p>



<ul class="wp-block-list">
<li>可以和容器映像檔使用相同的儲存庫</li>



<li>有標準的版本控制</li>



<li>支援數位簽名，提高安全性</li>



<li>可以使用相同的存取控制機制</li>
</ul>



<p>比較傳統方式和 OCI 格式：</p>



<p>傳統 Chart 儲存：</p>



<pre class="wp-block-code"><code>helm repo add bitnami https://charts.bitnami.com/bitnami
helm install wordpress bitnami/wordpress</code></pre>



<p>OCI 格式儲存：</p>



<pre class="wp-block-code"><code>helm install wordpress oci://registry.example.com/charts/wordpress:1.0.0</code></pre>



<p>在 Google Cloud 的情境下，使用 Artifact Registry 儲存 OCI 格式的 Charts 特別有優勢：</p>



<ol class="wp-block-list">
<li>可以集中管理容器映像檔和 Charts</li>



<li>整合 Google Cloud 的存取控制</li>



<li>支援 VPC Service Controls 提高安全性</li>



<li>有完整的版本追蹤和稽核記錄</li>
</ol>



<p>那你可能會問 WordPress 不是一整包 php 程式檔嗎？它們存在哪裡？</p>



<p>Helm Charts 本身<strong>不包含</strong> WordPress 的 PHP 檔案。Charts 只包含了 Kubernetes 的部署設定檔。實際的 WordPress PHP 檔案是存在於<strong>容器映像檔</strong>（Container Image）中。</p>



<p>讓我用 WordPress 為例子來說明整個架構：</p>



<ol class="wp-block-list">
<li><strong>容器映像檔（Container Image）</strong>
<ul class="wp-block-list">
<li>包含 WordPress 的所有 PHP 檔案</li>



<li>包含 Apache/PHP 運行環境</li>



<li>通常存放在像 Docker Hub 這樣的容器登錄庫</li>



<li>例如：<code>wordpress:6.4.3</code></li>
</ul>
</li>



<li><strong>Helm Chart</strong>
<ul class="wp-block-list">
<li>只包含 Kubernetes 的設定檔</li>



<li>會在設定中<strong>引用</strong>上面的容器映像檔</li>



<li>例如在 <code>deployment.yaml</code> 中：</li>
</ul>
</li>
</ol>



<pre class="wp-block-code"><code>spec:
  containers:
  - name: wordpress
    image: wordpress:6.4.3   # 這裡引用包含實際 PHP 檔案的容器映像檔
    ports:
    - containerPort: 80</code></pre>



<p>所以完整的部署流程是：</p>



<ol class="wp-block-list">
<li>Kubernetes 讀取 Helm Chart 的設定</li>



<li>根據設定去下載指定的容器映像檔</li>



<li>將容器映像檔（包含 PHP 檔案）部署到 Kubernetes 集群中</li>
</ol>



<p>這種設計的好處是：</p>



<ul class="wp-block-list">
<li>關注點分離：部署設定（Chart）和應用程式程式碼（容器映像檔）可以分開管理</li>



<li>重用性：同一個容器映像檔可以用不同的 Chart 設定來部署</li>



<li>版本控制：程式碼和部署設定可以分別進行版本控制</li>
</ul>



<p></p><p>The post <a href="https://dongdonggcp.com/2024/12/02/gke-what-is-helm-charts-what-is-oci-charts/">[GKE 教學] Helm Charts 是什麼？什麼是 OCI 格式的 Charts？</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2024/12/02/gke-what-is-helm-charts-what-is-oci-charts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8228</post-id>	</item>
	</channel>
</rss>
