在邊緣計算情境中,原生的DaemonSet升級模型無法滿足某些特定的需求,例如,由於雲邊網路中斷,節點NotReady而導致的DaemonSet滾動升級被阻塞,或者需要根據實際邊緣環境的狀態在邊緣節點上直接觸發應用的升級,而不由雲端驅動(例如新能源汽車的OTA升級)。此時,可以通過配置擴充的DaemonSet升級模型AdvancedRollingUpdate和OTA以解決雲邊網路中斷導致的升級阻塞以及OTA升級問題。
前提條件
適用於v1.26.3-aliyun.1及以上版本的ACK Edge叢集。
升級模型說明
AdvancedRollingUpdate升級模型
該升級模型解決雲邊網路斷鏈時,由於節點狀態NotReady而導致的DaemonSet升級阻塞問題。在升級過程中,它會忽略NotReady狀態的節點,優先完成狀態為Ready的節點上的Pod升級。同時,當節點狀態從NotReady轉變為Ready時,它會自動完成該節點上DaemonSet Pod的升級。
OTA升級模型
該升級模型允許直接在邊緣節點上通過調用REST API來檢查Pod是否可以更新,以及觸發Pod的升級操作。
配置說明
apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
apps.openyurt.io/update-strategy: AdvancedRollingUpdate
apps.openyurt.io/max-unavailable: 30%
spec:
updateStrategy:
type: OnDelete參數 | 說明 |
apps.openyurt.io/update-strategy | 啟用擴充升級模型,支援AdvancedRollingUpdate或OTA。 |
apps.openyurt.io/max-unavailable | 此配置僅在 |
spec.updateStrategy.type | 必須設定為 |
使用方式
AdvancedRollingUpdate升級模型
以下範例程式碼為AdvancedRollingUpdate升級樣本,在樣本中建立了一個名為nginx-daemonset的DaemonSet,使用AdvancedRollingUpdate升級模型,並且在滾動升級過程中最多允許30%的Pod不可用。
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-daemonset
annotations:
apps.openyurt.io/update-strategy: AdvancedRollingUpdate
apps.openyurt.io/max-unavailable: 30%
spec:
selector:
matchLabels:
app: nginx
updateStrategy:
type: OnDelete
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.19.4
EOFOTA升級模型
OTA升級介面
邊緣節點上的edge-hub組件提供了與OTA升級相關的REST APIs。
GET /pods通過此介面可以擷取節點上的Pod資訊。可以通過
Pod.status.conditions中的PodNeedUpgrade來檢查Pod是否可以更新。POST /openyurt.io/v1/namespaces/{ns}/pods/{podname}/imagepull此介面允許使用者觸發特定的DaemonSet Pod的鏡像拉取。路徑參數
{ns}和{podname}分別代表 Pod 的命名空間和名稱。一些Pod鏡像體積較大、啟動時間長,可通過這個API進行預拉取,加速啟動時間。鏡像拉取的介面僅支援叢集為1.32-aliyun.1及以上的版本。
POST /openyurt.io/v1/namespaces/{ns}/pods/{podname}/upgrade通過此介面允許觸發特定的DaemonSet Pod的更新。路徑參數
{ns}和{podname}分別代表Pod的命名空間和名稱。請根據實際需求對指定的Pod執行升級操作。
OTA升級使用樣本
建立一個名為
nginx-daemonset的DaemonSet,使用OTA升級模型,當DaemonSet的鏡像更新後,節點上的Pod並不會自動更新,請在邊緣節點上通過REST API來檢查和觸發Pod的升級。cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: DaemonSet metadata: name: nginx-daemonset annotations: apps.openyurt.io/update-strategy: OTA spec: selector: matchLabels: app: nginx updateStrategy: type: OnDelete template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.19.4 EOFOTA升級用例
登入邊緣節點,查看節點上的所有Pod是否有升級需求。
curl http://127.0.0.1:10267/pods若輸出結果中
default/nginx-daemonset-bwzss pod.Status.Conditions的PodNeedUpgrade=true,表明對應的Pod需要升級。(可選)預拉取鏡像。
curl -X POST http://127.0.0.1:10267/openyurt.io/v1/namespaces/default/pods/nginx-daemonset-bwzss/imagepull預期輸出:
Image pre-pull requested for pod default/nginx-daemonset-bwzss對該Pod進行升級並更新DaemonSet配置。
curl -X POST http://127.0.0.1:10267/openyurt.io/v1/namespaces/default/pods/nginx-daemonset-bwzss/upgrade預期輸出:
Start updating pod default/nginx-daemonset-bwzss
相關文檔
如需確認Pod運行狀態,請參見管理容器組(Pod)。