Questa pagina mostra come richiedere tempi di esecuzione estesi per i pod prima che vengano
rimossi da Google Kubernetes Engine (GKE).
Informazioni sull'eliminazione dei pod avviata da GKE
L'espulsione dei pod è una parte normale dell'esecuzione dei carichi di lavoro su Kubernetes.
GKE espelle i carichi di lavoro durante gli eventi pianificati, come gli upgrade automatici dei nodi e la riduzione della scalabilità automatica, per garantire che i nodi siano aggiornati e ottimizzati per un utilizzo efficiente delle risorse. Per impostazione predefinita,
GKE invia un segnale di terminazione al container non appena si verifica l'evento, dopodiché il container ha un periodo di tolleranza per terminare prima che Kubernetes espella il pod. Per gli upgrade automatici dei nodi, il periodo di tolleranza
può durare fino a un'ora. Per gli eventi di riduzione, il periodo di tolleranza può durare fino a
10 minuti.
Kubernetes dispone di funzionalità integrate che i container possono utilizzare per gestire correttamente
le espulsioni, ad esempio
PodDisruptionBudgets
e periodi di
terminazione controllata.
Tuttavia, alcuni carichi di lavoro, come le code batch o i server di giochi multiplayer, devono
essere eseguiti per un periodo di tempo più lungo prima di essere rimossi. Il periodo di tolleranza predefinito
concesso da GKE durante le espulsioni
avviate da GKE potrebbe non essere sufficiente per questi carichi di lavoro. In queste situazioni, puoi
dire ad Autopilot di evitare di eliminare carichi di lavoro specifici per un massimo di 7 giorni.
Casi d'uso
Alcune situazioni in cui potresti voler indicare a GKE di evitare
l'espulsione dei workload includono:
Gestisci server di gioco multiplayer che espellerebbero i giocatori dalle loro sessioni se i server terminassero in anticipo.
Esegui software di audioconferenza o videoconferenza che interromperebbero le riunioni in corso se i server venissero chiusi.
Esegui attività che richiedono tempo per essere completate e l'interruzione anticipata causerebbe
la perdita del lavoro in corso.
Esegui un servizio stateful meno tollerante alle interruzioni e vuoi
ridurre al minimo la frequenza con cui si verificano interruzioni.
Prezzi
Puoi richiedere tempi di esecuzione estesi per i tuoi Pod senza costi aggiuntivi.
Tuttavia, considera le seguenti modifiche comportamentali che potrebbero influire sui tuoi
prezzi:
I cluster Autopilot applicano valori minimi più elevati per le richieste di risorse dei pod di lunga durata. I cluster Autopilot
ti addebitano le richieste di risorse dei pod in esecuzione. Non ti viene addebitato alcun costo per l'overhead di sistema o per la capacità del nodo inutilizzata.
L'utilizzo di pod di durata estesa potrebbe aumentare il numero di nodi nel cluster, il che potrebbe influire sull'utilizzo e sulla scalabilità degli indirizzi IP. Se hai
DaemonSet che vengono eseguiti su ogni nodo, nel cluster ci saranno più DaemonSet,
Se vuoi utilizzare Google Cloud CLI per questa attività,
installala e poi
inizializza
gcloud CLI. Se hai già installato gcloud CLI, scarica l'ultima versione
eseguendo gcloud components update.
Assicurati di avere un
cluster Autopilot
che esegue la versione 1.27 o successive.
Limitazioni
Non puoi richiedere tempi di esecuzione estesi per i tuoi Spot Pod.
I tempi di pull delle immagini vengono conteggiati durante il calcolo del tempo di esecuzione esteso.
In ogni cluster puoi avere un massimo di 50 carichi di lavoro di lunga durata (con richieste di CPU diverse). Ciò significa che fino a 50 diversi set di valori di richiesta CPU, dopo aver superato i controlli di incrementi, proporzioni e minimi delle risorse di Autopilot, possono avere una durata estesa in ogni cluster.
Non puoi utilizzare l'affinità tra pod di Kubernetes nei pod di durata estesa.
Quando possibile, GKE inserisce ogni pod con tempo di esecuzione esteso sul
proprio nodo. Questo comportamento garantisce che i nodi possano essere fare lo scale down se sono
sottoutilizzati.
Per richiedere un tempo di esecuzione esteso per un pod, imposta l'annotazione Kubernetes
cluster-autoscaler.kubernetes.io/safe-to-evict su false nella
specifica del pod.
Salva il seguente manifest come extended-deployment.yaml:
I pod continuano a essere eseguiti per almeno 7 giorni prima che possa verificarsi uno scale down o un upgrade automatico dei nodi.
Considerazioni e consigli
Quando utilizzi questa funzionalità, tieni presente quanto segue:
I pod di lunga durata non sono protetti dall'espulsione basata sulla priorità. Se utilizzi Kubernetes PriorityClasses, valuta i seguenti metodi per ridurre al minimo la probabilità di espulsione basata sulla priorità:
Assicurati che i pod di lunga durata utilizzino PriorityClass con la priorità più alta, in modo che gli altri pod utente non vengano eliminati.
I pod di sistema vengono eseguiti con la priorità più alta e saranno sempre in grado di rimuovere
i pod di lunga durata. Per ridurre al minimo la probabilità che ciò accada,
GKE pianifica i pod di sistema sul nodo prima di pianificare il pod di durata estesa.
I pod di durata estesa possono comunque essere eliminati in anticipo nelle seguenti
situazioni:
Espulsione per fare spazio ai pod utente con priorità più alta (utilizzando una PriorityClass
più alta)
Rimozione per fare spazio ai componenti di sistema Kubernetes
Eventi avviati dall'utente, ad esempio lo svuotamento di un nodo
Puoi utilizzare l'annotazione cluster-autoscaler.kubernetes.io/safe-to-evict nei
cluster standard, ma il risultato non è lo stesso. I pod vengono eseguiti a tempo indeterminato
anche se si verifica un evento di scale down, impedendo l'eliminazione dei nodi sottoutilizzati
e facendo sì che tu continui a pagare per questi nodi. I pod non sono protetti
dalle espulsioni causate dagli upgrade automatici dei nodi.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-01 UTC."],[],[],null,["# Extend the run time of Autopilot Pods\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview)\n\n*** ** * ** ***\n\nThis page shows you how to request extended run times for Pods before they're\nevicted by Google Kubernetes Engine (GKE).\n\nAbout GKE-initiated Pod eviction\n--------------------------------\n\nPod evictions are a normal part of running workloads on Kubernetes.\nGKE evicts workloads during scheduled events, such as automatic\nnode upgrades and autoscaling scale-downs, to ensure that your nodes are\nup-to-date and optimized for efficient resource usage. By default,\nGKE sends a termination signal to the container as soon as the\nevent occurs, after which the container has a grace period to terminate before\nKubernetes evicts the Pod. For automatic node upgrades, the grace period\ncan be up to one hour. For scale-down events, the grace period can be up to\n10 minutes.\n\nKubernetes has built-in features that containers can use to gracefully handle\nevictions, such as\n[PodDisruptionBudgets](https://kubernetes.io/docs/tasks/run-application/configure-pdb/)\nand [graceful termination\nperiods](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination/).\nHowever, some workloads, such as batch queues or multiplayer game servers, need\nto run for a longer period of time before being evicted. The default grace\nperiod that GKE grants during GKE-initiated\nevictions might not be enough for these workloads. In these situations, you can\ntell Autopilot to avoid evicting specific workloads for up to 7 days.\n\n### Use cases\n\nSome situations in which you might want to tell GKE to avoid\nevicting workloads include the following:\n\n- You run multiplayer game servers that would kick players out of their sessions if the servers terminated early.\n- You run audio or video conferencing software that would disrupt in-progress meetings if the servers terminated.\n- You run tasks that need time to complete, and early termination would cause a loss of in-progress work.\n- You run a stateful service that is less tolerant to disruption and you want to minimize how often disruptions occur.\n\nPricing\n-------\n\nYou can request extended run times for your Pods at no additional charge.\nHowever, consider the following behavioral changes that might impact your\npricing:\n\n- Autopilot clusters enforce [higher minimum values](/kubernetes-engine/docs/concepts/autopilot-resource-requests#workload-separation) for the resource requests of extended duration Pods. Autopilot clusters charge you for the resource requests of your running Pods. You're not charged for system overhead or for unused node capacity.\n- Using extended duration Pods might increase the number of nodes in your cluster, which might affect IP address usage and scalability. If you have DaemonSets that run on every node, this results in more DaemonSets in the cluster,\n\nFor pricing details, see\n[Autopilot pricing](/kubernetes-engine/pricing#autopilot_mode).\n\nBefore you begin\n----------------\n\nBefore you start, make sure that you have performed the following tasks:\n\n- Enable the Google Kubernetes Engine API.\n[Enable Google Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com)\n- If you want to use the Google Cloud CLI for this task, [install](/sdk/docs/install) and then [initialize](/sdk/docs/initializing) the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running `gcloud components update`. **Note:** For existing gcloud CLI installations, make sure to set the `compute/region` [property](/sdk/docs/properties#setting_properties). If you use primarily zonal clusters, set the `compute/zone` instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: `One of [--zone, --region] must be supplied: Please specify location`. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.\n\n\u003c!-- --\u003e\n\n- Ensure that you have an [Autopilot cluster](/kubernetes-engine/docs/how-to/creating-an-autopilot-cluster) running version 1.27 or later.\n\n### Limitations\n\n- You can't request extended run times for your Spot Pods.\n- Image pull times are counted when calculating the extended run time.\n- You can have a maximum of 50 extended duration workloads (with different CPU requests) in each cluster. This means that up to 50 different sets of CPU request values, after passing Autopilot resource minimums, ratios, and increment size checks, can have extended duration in each cluster.\n- You can't use Kubernetes inter-Pod affinity in extended duration Pods.\n- Whenever possible, GKE places each extended run time Pod on its own node. This behavior ensures that nodes can scale down if they're under-utilized.\n- You can't request extended run times for Pods that target [custom compute classes](/kubernetes-engine/docs/concepts/about-custom-compute-classes).\n\nRequest extended run time\n-------------------------\n\nTo request extended run time for a Pod, set the Kubernetes\n`cluster-autoscaler.kubernetes.io/safe-to-evict` annotation to `false` in the\nPod specification.\n\n1. Save the following manifest as `extended-deployment.yaml`:\n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: extended-pods\n labels:\n duration: extended\n spec:\n selector:\n matchLabels:\n duration: extended\n template:\n metadata:\n annotations:\n cluster-autoscaler.kubernetes.io/safe-to-evict: \"false\"\n labels:\n duration: extended\n spec:\n containers:\n - name: example-container\n image: registry.k8s.io/pause\n resources:\n requests:\n cpu: 200m\n\n2. Create the Deployment:\n\n kubectl create -f extended-deployment.yaml\n\nThe Pods continue to run for at least 7 days before a scale-down or a node\nauto-upgrade can occur.\n\nConsiderations and recommendations\n----------------------------------\n\nWhen you use this functionality, consider the following:\n\n- Extended duration Pods aren't protected from priority-based eviction. If you use [Kubernetes PriorityClasses](/kubernetes-engine/docs/how-to/capacity-provisioning), consider the following methods to minimize the probability of priority-based eviction:\n - Ensure that your extended duration Pods use the highest priority PriorityClass, so that other user Pods don't evict your extended duration Pods.\n - Use [workload separation](/kubernetes-engine/docs/how-to/workload-separation) to run extended duration Pods separately from other Pods.\n- System Pods run with the highest priority and will always be able to evict extended duration Pods. To minimize the probability of this, GKE schedules system Pods on the node before scheduling the extended duration Pod.\n- Extended duration Pods can still be evicted early in the following situations:\n - Eviction to make space for higher-priority user Pods (using a higher PriorityClass)\n - Eviction to make space for Kubernetes system components\n - [kubelet out-of-memory eviction](https://kubernetes.io/docs/concepts/scheduling-eviction/node-pressure-eviction/) if the Pod uses more memory than it requested (OOMKill)\n - Compute Engine VM maintenance events. [Accelerator-optimized machine types](/compute/docs/accelerator-optimized-machines) are more likely to be affected by these events because those machines don't support [live migration](/compute/docs/instances/live-migration-process).\n - Node auto-repairs\n - User-initiated events such as draining a node\n- You can use the `cluster-autoscaler.kubernetes.io/safe-to-evict` annotation in Standard clusters, but the result is not the same. Pods run indefinitely even if a scale-down event occurs, preventing deletion of underutilized nodes and resulting in you continuing to pay for those nodes. Pods also aren't protected from evictions caused by node auto-upgrades.\n\nWhat's next\n-----------\n\n- [Use PriorityClasses to provision spare capacity in Autopilot for\n rapid Pod scaling](/kubernetes-engine/docs/how-to/capacity-provisioning)"]]