# How to Pull Images from Google Artifact Registry into RKE2 <style> .indent-title-1{ margin-left: 1em; } .indent-title-2{ margin-left: 2em; } .indent-title-3{ margin-left: 3em; } </style> ## 注意事項 :::danger 如果 RKE2 沒有被 Rancher 管理,則叢集中的每台節點都需要做設定,如果有則透過 Rancher 介面設定,否則容易造成設定檔混亂 ::: ## 1. 在 Google Cloud Platform 中設定 <font color=red>請在 Cloud shell 中執行,因為在 Cloud shell 執行可以少很多 Gcloud 的設定、Gcloud 的安裝、Project 的設定、個人帳號的驗證</font> <div class="indent-title-1"> ### 1.1. 創建 Google Service Account <div class="indent-title-2"> #### 1.1.1. 定義 Google Service Account name <div class="indent-title-2"> ```bash! SA_NAME='gsa-demo' ``` </div> #### 1.1.2. 創建 Google Service Account <div class="indent-title-2"> ```bash! gcloud iam service-accounts create ${SA_NAME} ``` </div> </div> ### 1.2. 產生 Google Service Account Key File <div class="indent-title-2"> ```bash! gcloud iam service-accounts keys create key.json \ --iam-account=${SA_NAME}@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com ``` > `GOOGLE_CLOUD_PROJECT` 這個變數 Cloud Shell 預設會有 </div> </div> ## 2. 在 RKE2 叢集設定 Private Registry :::danger 此範例只適用純手動建立的 RKE2 ::: <div class="indent-title-1"> ### 2.1. 連線至叢集節點 <div class="indent-title-2"> ```bash! ssh sudo_user@ip ``` </div> ### 2.2. 編輯 Private Registry 設定檔 <div class="indent-title-2"> #### 2.2.1. 定義變數 <div class="indent-title-2"> ```bash! DOMAIN_NAME='asia-east1-docker.pkg.dev' KEY_FILE=$(cat /PATH/TO/key.json | base64 -w 0) ``` </div> #### 2.2.2. 產生 Private Registry 設定檔 <div class="indent-title-2"> ```bash! cat <<EOF | sudo tee /etc/rancher/rke2/registries.yaml mirrors: "${DOMAIN_NAME}": endpoint: - "https://${DOMAIN_NAME}" configs: "${DOMAIN_NAME}": auth: username: _json_key_base64 password: '${KEY_FILE}' EOF ``` </div> ### 2.3. 驅逐節點的 Pod <div class="indent-title-2"> <font color=red>請在 RKE2 管理主機依序執行以下命令</font> #### 2.3.1. 定義節點名稱 <div class="indent-title-2"> ```bash! NODE='m1' ``` </div> #### 2.3.2. 設定節點不能被指派 Pod <div class="indent-title-2"> ```bash! kubectl cordon $NODE ``` </div> #### 2.3.2. 驅逐節點上的 Pod <div class="indent-title-2"> ```bash! kubectl drain $NODE --ignore-daemonsets --delete-emptydir-data ``` </div> </div> ### 2.4. 重啟 RKE2 服務 <div class="indent-title-2"> <font color=red>請回到設定的節點執行以下命令</font> <div class="indent-title-1"> 如果是 Control-plane/Server node 則執行以下命令 ```bash! sudo systemctl restart rke2-server ``` 如果是 Worker/Agent node 則執行以下命令 ```bash! sudo systemctl restart rke2-agent ``` </div> </div> ### 2.5. 將節點恢復為可指派 Pod <div class="indent-title-2"> <font color=red>請在 RKE2 管理主機依序執行以下命令</font> ```bash! kubectl uncordon $NODE ``` </div> ### 2.6. 重複以上 2.1. ~ 2.5. 的步驟,直到叢集中的每台節點都設定完畢 </div> </div> ## 3. 參考文章 - [[DOC] - Missing documentation on how to external repo via registries.yaml](https://github.com/rancher/rke2/discussions/6096#discussioncomment-11767013)