Skip to content

Commit 40441b9

Browse files
Merge pull request #309700 from dcasati/patch-2
Update the Connect to AKS Private Cluster Using Azure Bastion
2 parents da31d35 + 4924bb8 commit 40441b9

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

articles/bastion/bastion-connect-to-aks-private-cluster.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,33 @@ To connect to your AKS private cluster:
4747

4848
1. Sign in to your Azure account using `az login` via CLI. If you have more than one subscription, you can view them using `az account list` and select the subscription containing your Bastion resource using:
4949

50-
```pwsh
50+
```bash
5151
az account set --subscription <subscription ID>
5252
```
5353

5454
1. Retrieve credentials to your AKS private cluster:
5555

56-
```pwsh
56+
```bash
5757
az aks get-credentials --admin --name <AKSClusterName> --resource-group <ResourceGroupName>
5858
```
5959

6060
1. Open the tunnel to your target AKS Cluster with either of the following commands:
6161

62-
```pwsh
62+
```bash
6363
az aks bastion --name <aksClusterName> --resource-group <aksClusterResourceGroup> --admin --bastion <bastionResourceId>
6464
```
6565

66-
Or:
66+
1. Change the new temporary KUBECONFIG to point to the new Bastion tunnel:
6767

68-
```pwsh
69-
az network bastion tunnel --name <BastionName> --resource-group <ResourceGroupName> --target-resource-id <AKSClusterID> --resource-port 443 --port <LocalMachinePort>
70-
```
68+
```bash
69+
export BASTION_PORT=$(ps aux | sed -n 's/.*--port \([0-9]*\).*/\1/p' | head -1)
70+
sed -i "s|server: https://.*|server: https://localhost:${BASTION_PORT}|" $KUBECONFIG
71+
```
7172

72-
1. If you're using the az network command, open a new command line to connect to the AKS cluster via the Bastion tunnel. Otherwise, you should be all set to interact with your AKS cluster.
73+
1. You are now you should be all set to interact with your AKS cluster:
7374

74-
```pwsh
75-
kubectl get pods --server=https://localhost:<LocalMachinePort>
75+
```bash
76+
kubectl get nodes
7677
```
7778

7879
## Next steps

0 commit comments

Comments
 (0)