Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Esecuzione dei comandi della shell sul container
Per risolvere alcuni problemi, potresti dover accedere al contenitore per eseguire comandi direttamente sul contenitore stesso. Puoi accedere a un contenitore tramite una shell bash o PowerShell utilizzando il comando
kubectl exec.
Utilizza kubectl describe pods per trovare il nome del pod nel cluster a cui vuoi collegarti.
Nell'esempio seguente, il comando elenca il pod suitecrm-0.
kubectl describe pods | grep Name
Name: suitecrm-0
Esegui i comandi shell utilizzando uno dei seguenti metodi:
Usa kubectl exec per aprire una shell di comandi bash in cui puoi eseguire i comandi.
kubectl exec -it pod-name -- /bin/bash
L'esempio seguente recupera una shell per il pod suitecrm-0:
kubectl exec -it suitecrm-0 -- /bin/bash
Usa kubectl exec per eseguire direttamente i comandi.
[[["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-04 UTC."],[],[],null,["# Executing shell commands on your container\n==========================================\n\nTo troubleshoot some isses, you might have to access the container to execute commands directly\non the container itself. You can access a container through a `bash` shell or through PowerShell using the\n[`kubectl exec` command.](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#exec)\n| **Note:** In the examples below, for PowerShell replace `/bin/bash` with `cmd.exe`, `powershell.exe`, or `pwsh.exe` depending on your version.\n\n1. Use `kubectl describe pods` to find the name of the Pod in your cluster that you want to connect to.\n\n In the following example, the command lists the suitecrm-0 pod. \n\n ```\n kubectl describe pods | grep Name\n\n Name: suitecrm-0\n ```\n2. Execute shell commands using one of the following methods:\n - Use `kubectl exec` to open a bash command shell where you can execute commands. \n\n ```\n kubectl exec -it pod-name -- /bin/bash\n ```\n\n The following example gets a shell to the suitecrm-0 pod: \n\n ```\n kubectl exec -it suitecrm-0 -- /bin/bash\n ```\n - Use `kubectl exec` to execute commands directly. \n\n ```\n kubectl exec -it pod-name -- /bin/bash -c \"command(s)\"\n ```\n\n The following example lists the root directory of the suitecrm-0 pod: \n\n ```\n kubectl exec -it suitecrm-0 -- /bin/bash -c \"ls /\"\n ```\n\nFor more information, see the\n[Kubernetes documentation](https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/)."]]