|
| 1 | +--- |
| 2 | +title: Connect to Azure Operator Nexus Kubernetes cluster |
| 3 | +description: Learn how to connect to Azure Operator Nexus Kubernetes cluster for interacting, troubleshooting, and maintenance tasks |
| 4 | +author: dramasamy |
| 5 | +ms.author: dramasamy |
| 6 | +ms.service: azure-operator-nexus |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 08/17/2023 |
| 9 | +ms.custom: template-how-to-pattern |
| 10 | +--- |
| 11 | + |
| 12 | +# Connect to Azure Operator Nexus Kubernetes cluster |
| 13 | + |
| 14 | +This article provides instructions on how to connect to Azure Operator Nexus Kubernetes cluster and its nodes. It includes details on how to connect to the cluster from both Azure and on-premises environments, and how to do so when the ExpressRoute is in both connected and disconnected modes. |
| 15 | + |
| 16 | +In Azure, connected mode and disconnected mode refer to the state of an ExpressRoute circuit. [ExpressRoute](../expressroute/expressroute-introduction.md) is a service provided by Azure that enables organizations to establish a private, high-throughput connection between their on-premises infrastructure and Azure datacenters. |
| 17 | + |
| 18 | +* Connected Mode: In connected mode, the ExpressRoute circuit is fully operational and provides a private connection between your on-premises infrastructure and Azure services. This mode is ideal for scenarios where you need constant connectivity to Azure. |
| 19 | +* Disconnected Mode: In disconnected mode, the ExpressRoute circuit is partially or fully down and is unable to provide connectivity to Azure services. This mode is useful when you want to perform maintenance on the circuit or need to temporarily disconnect from Azure. |
| 20 | + |
| 21 | +> [!IMPORTANT] |
| 22 | +> While the ExpressRoute circuit is in disconnected mode, traffic will not be able to flow between your on-premises environment and Azure. Therefore, it is recommended to only use disconnected mode when necessary, and to monitor the circuit closely to ensure it is brought back to connected mode as soon as possible. |
| 23 | +
|
| 24 | +## Prerequisites |
| 25 | + |
| 26 | +* An Azure Operator Nexus Kubernetes cluster deployed in a resource group in your Azure subscription. |
| 27 | +* SSH private key for the cluster nodes. |
| 28 | +* If you're connecting in disconnected mode, you must have a jumpbox VM deployed in the same virtual network as the cluster nodes. |
| 29 | + |
| 30 | +## Connected mode access |
| 31 | + |
| 32 | +When operating in connected mode, it's possible to connect to the cluster's kube-api server using the `az connectedk8s proxy` CLI command. Also it's possible to SSH into the worker nodes for troubleshooting or maintenance tasks from Azure using the ExpressRoute circuit. |
| 33 | + |
| 34 | +### Azure Arc for Kubernetes |
| 35 | + |
| 36 | +[!INCLUDE [quickstart-cluster-connect](./includes/kubernetes-cluster/cluster-connect.md)] |
| 37 | + |
| 38 | +### Azure Arc for servers |
| 39 | + |
| 40 | +The `az ssh arc` command allows users to remotely access a cluster VM that has been connected to Azure Arc. This method is a secure way to SSH into the cluster node directly from the command line, while in connected mode. Once the cluster VM has been registered with Azure Arc, the `az ssh arc` command can be used to manage the machine remotely, making it a quick and efficient method for remote management. |
| 41 | + |
| 42 | +To use `az arc ssh`, users need to manually connect the cluster VMs to Arc by creating a service principal (SP) with the 'Azure Connected Machine Onboarding' role. For more detailed steps on how to connect an Azure Operator Nexus Kubernetes cluster node to Arc, refer to the [how to guide](./howto-monitor-naks-cluster.md#monitor-nexus-kubernetes-cluster--vm-layer). |
| 43 | + |
| 44 | +1. Set the required variables. |
| 45 | + |
| 46 | + ```bash |
| 47 | + RESOURCE_GROUP="myResourceGroup" |
| 48 | + CLUSTER_NAME="myNexusK8sCluster" |
| 49 | + SUBSCRIPTION_ID="<Subscription ID>" |
| 50 | + USER_NAME="azureuser" |
| 51 | + SSH_PRIVATE_KEY_FILE="<vm_ssh_id_rsa>" |
| 52 | + ``` |
| 53 | + |
| 54 | +2. Get the available cluster node names. |
| 55 | + |
| 56 | + ```azurecli |
| 57 | + az networkcloud kubernetescluster show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID -o json | jq '.nodes[].name' |
| 58 | + ``` |
| 59 | + |
| 60 | +3. Sample output: |
| 61 | + |
| 62 | + ```bash |
| 63 | + "mynexusk8scluster-0b32128d-agentpool1-md-7h9t4" |
| 64 | + "mynexusk8scluster-0b32128d-agentpool1-md-c6xbs" |
| 65 | + "mynexusk8scluster-0b32128d-control-plane-qq5jm" |
| 66 | + ``` |
| 67 | + |
| 68 | +4. Run the following command to SSH into the cluster node. |
| 69 | + |
| 70 | + ```azurecli |
| 71 | + az ssh arc --subscription $SUBSCRIPTION_ID \ |
| 72 | + --resource-group $RESOURCE_GROUP \ |
| 73 | + --name <VM Name> \ |
| 74 | + --local-user $USER_NAME \ |
| 75 | + --private-key-file $SSH_PRIVATE_KEY_FILE |
| 76 | + ``` |
| 77 | + |
| 78 | +### Direct access to cluster nodes |
| 79 | + |
| 80 | +Another option for securely connecting to an Azure Operator Nexus Kubernetes cluster node is to set up a direct access to the cluster's CNI network from Azure. Using this approach, you can SSH into the cluster nodes, also execute kubectl commands against the cluster using the `kubeconfig` file. Reach out to your network administrator to set up this direct connection from Azure to the cluster's CNI network. |
| 81 | + |
| 82 | +## Disconnected mode access |
| 83 | + |
| 84 | +When the ExpressRoute is in a disconnected mode, you can't access the cluster's kube-api server using the `az connectedk8s proxy` CLI command. Similarly, the `az ssh` CLI command doesn't work for accessing the worker nodes, which can be crucial for troubleshooting or maintenance tasks. |
| 85 | +
|
| 86 | +However, you can still ensure a secure and effective connection to your cluster. To do so, establish direct access to the cluster's CNI (Container Network Interface) from within your on-premises infrastructure. This direct access enables you to SSH into the cluster nodes, and lets you execute `kubectl` commands using the `kubeconfig` file. |
| 87 | + |
| 88 | +Reach out to your network administrator to set up this direct connection to the cluster's CNI network. |
| 89 | +
|
| 90 | +## IP address of the cluster nodes |
| 91 | +
|
| 92 | +Before you can connect to the cluster nodes, you need to find the IP address of the nodes. The IP address of the nodes can be found using the Azure portal or the Azure CLI. |
| 93 | +
|
| 94 | +### Use the Azure CLI |
| 95 | +
|
| 96 | +1. Set the RESOURCE_GROUP, CLUSTER_NAME, and SUBSCRIPTION_ID variables to match your environment. |
| 97 | +
|
| 98 | + ```bash |
| 99 | + RESOURCE_GROUP="myResourceGroup" |
| 100 | + CLUSTER_NAME="myNexusK8sCluster" |
| 101 | + SUBSCRIPTION_ID="<Subscription ID>" |
| 102 | + ``` |
| 103 | +
|
| 104 | +2. Execute the following command to get the IP address of the nodes. |
| 105 | +
|
| 106 | + ```azurecli |
| 107 | + az networkcloud kubernetescluster show --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID -o json | jq '.nodes[] | select(any(.networkAttachments[]; .networkAttachmentName == "defaultcni")) | {name: .name, ipv4Address: (.networkAttachments[] | select(.networkAttachmentName == "defaultcni").ipv4Address)}' |
| 108 | + ``` |
| 109 | +
|
| 110 | +3. Here's the sample output of the command. |
| 111 | + |
| 112 | + ```json |
| 113 | + { |
| 114 | + "name": "mynexusk8scluster-0b32128d-agentpool1-md-7h9t4", |
| 115 | + "ipv4Address": "10.5.54.47" |
| 116 | + } |
| 117 | + { |
| 118 | + "name": "mynexusk8scluster-0b32128d-agentpool1-md-c6xbs", |
| 119 | + "ipv4Address": "10.5.54.48" |
| 120 | + } |
| 121 | + { |
| 122 | + "name": "mynexusk8scluster-0b32128d-control-plane-qq5jm", |
| 123 | + "ipv4Address": "10.5.54.46" |
| 124 | + } |
| 125 | + ``` |
| 126 | + |
| 127 | +### Use the Azure portal |
| 128 | + |
| 129 | +To find the IP address of the VM for SSH, follow these steps: |
| 130 | + |
| 131 | +1. Go to the [Azure portal](https://portal.azure.com) and sign-in with your username and password. |
| 132 | +2. Type 'Kubernetes Cluster (Operator Nexus)' in the search box and select the 'Kubernetes Cluster' service from the list of results. |
| 133 | + |
| 134 | +:::image type="content" source="media/nexus-kubernetes/search-kubernetes-service.png" lightbox="media/nexus-kubernetes/search-kubernetes-service.png" alt-text="Screenshot of browsing Nexus Kubernetes service."::: |
| 135 | + |
| 136 | +3. Look for the specific 'Nexus Kubernetes cluster' resource you need to use the search. |
| 137 | + |
| 138 | +:::image type="content" source="media/nexus-kubernetes/search-kubernetes-cluster.png" lightbox="media/nexus-kubernetes/search-kubernetes-cluster.png" alt-text="Screenshot of browsing Nexus Kubernetes cluster."::: |
| 139 | + |
| 140 | +4. Once you've found the right resource by matching its name with the cluster name, Select the resource to go to the 'Kubernetes Cluster' home page. |
| 141 | +
|
| 142 | +:::image type="content" source="media/nexus-kubernetes/kubernetes-cluster-home.png" lightbox="media/nexus-kubernetes/kubernetes-cluster-home.png" alt-text="Screenshot of Nexus Kubernetes cluster home page."::: |
| 143 | +
|
| 144 | +5. Once you've found the right resource by matching its name with the cluster name, go to the 'Kubernetes Cluster Nodes' section in the left menu. |
| 145 | + |
| 146 | +:::image type="content" source="media/nexus-kubernetes/kubernetes-cluster-nodes.png" lightbox="media/nexus-kubernetes/kubernetes-cluster-nodes.png" alt-text="Screenshot of browsing Nexus Kubernetes cluster nodes."::: |
| 147 | + |
| 148 | +6. Select on the Kubernetes node name you're interested in to see its details. |
| 149 | +7. Check the 'Attached Networks' tab to find the IP address of the node's 'Layer 3 Network' that used as CNI network. |
| 150 | + |
| 151 | +:::image type="content" source="media/nexus-kubernetes/control-plane-network-attachment.png" lightbox="media/nexus-kubernetes/control-plane-network-attachment.png" alt-text="Screenshot of browsing Nexus Kubernetes cluster node networks."::: |
| 152 | + |
| 153 | +## Next steps |
| 154 | + |
| 155 | +Try out the following articles to learn more about Azure Operator Nexus Kubernetes cluster. |
| 156 | +- [Quickstart: Deploy an Azure Operator Nexus Kubernetes cluster using Bicep](./quickstarts-kubernetes-cluster-deployment-bicep.md) |
| 157 | +- [How to: Monitor Azure Operator Nexus Kubernetes cluster](./howto-monitor-naks-cluster.md) |
0 commit comments