---
# System prepended metadata

title: GKE升級結點集區
tags: [GKE]

---


###### tags: `GKE` `k8s`


[參考資料](https://cloud.google.com/kubernetes-engine/docs/tutorials/migrating-node-pool?hl=zh-cn)

---

### 1. 封鎖現有節點池並將它們標記為無法安排

```
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=xpg-pool -o=name); do
  kubectl cordon "$node";
done
```


### 2. 排空現有節點池
(通過在分配的正常終止時間段（10 秒）內逐出 Pod，排空每個節點)

```
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool=xpg-pool -o=name); do
  kubectl drain --force --ignore-daemonsets --delete-emptydir-data --grace-period=10 "$node";
done

```
```
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool -o=name); do
  kubectl cordon "$node";
done
```
```
for node in $(kubectl get nodes -l cloud.google.com/gke-nodepool -o=name); do
  kubectl drain --force --ignore-daemonsets --delete-emptydir-data --grace-period=10 "$node";
done
```
