The article describes how to connect to a specific pod in Azure Kubernetes Service (AKS) cluster using PowerShell.
To connect to a specific pod in Azure Kubernetes Service (AKS), consider the following steps:
- Install the Azure Az PowerShell module as described here:
https://learn.microsoft.com/en-us/powershell/azure/new-azureps-module-az
- Run Windows PowerShell as Administrator.
- Execute the az login command.
You should get prompted to authorize a connection to Azure using your browser.
- Use Azure Portal to locate the resource (Kubernetes service) you are connecting to.
You might need to change your identity to access certain directories, see
https://learn.microsoft.com/en-us/azure/devtest/offer/how-to-change-directory-tenants-visual-studio-azure
- Click Connect, then use PowerShell to execute the suggested commands. For example:
az account set --subscription <subscription_id>
az aks get-credentials --resource-group <resource_group_name> --name <aks_name>
This is an important step as it sets the current Azure Resource Group for all subsequent commands.
- Use PowerShell command:
kubectl get deployments --all-namespaces=true
to list all deployments and find the necessary namespace.
- Identify the pod name using the namespace and label, e.g.
kubectl get pods -l app.kubernetes.io/name=cm -namespace <namespace>
To start a PowerShell session in the context of a specific pod use:
kubectl exec -it <pod_name> -namespace <namespace> -- powershell