![]() And presto - you can use these commands to switch context super quickly, even if your AKS cluster names are complex. I then did the same for some other clusters I wanted quick access to. This creates the alias with the name you specify for "YOUR_ALIAS", which then executes the command I specified above. alias YOUR_ALIAS=kubectl config use-context Here's what I'm doing to make my context-switching even easier. One of the major benefits is the easy use of an alias, that you can set up with a jiffy. One of my absolute favorites in my daily tool basket is cmder. Switch cluster using the kubectl config use-context command Switch cluster: kubectl config use-context This is the cluster that is currently selected and that my kubectl commands targets. You can see that the first one in my list is marked with the asterisk *. So here comes the simple context switch part. Kubectl command to list context with the local user of the system Using kubectl config get-contexts we'll be able to see all the clusters we've authenticated against, regardless what subscription they're in: kubectl config get-contexts ![]() This is the fun part, as I'm sure most readers are already familiar with the above commands to authenticate to the clusters. Targeting your cluster with config get-contexts and use-context Great, this ensures you've got access and that the kubectl commands will now target this cluster. Next step right after this, is to get the credentials from one of your clusters, which you can also do using the Azure CLI: Listing Azure Kubernetes Services available for the authenticated user az aks get-credentials -n -g This will give you a nice list of all your clusters in a table-like format: Great, we're authenticated with the CLI, now we need to list the clusters. List and Connect to an AKS cluster using the Azure CLI Authenticate to Azure CLIįirst, let's authenticate to the Azure CLI: az loginįollow the on-screen instructions in the popup-browser window and ensure you authenticate correctly to the subscription you want to target. If you're already handy with that, jump down to #3 below. This applies to either of those scenarios - you're not bound by the boundaries of any subscription here.įor many, I'm sure you'll recognize the first steps to authenticate and get credentials to your clusters. ![]() You have multiple AKS clusters running in the same, or separate Azure subscriptions. Create an alias in my favorite tool, cmder, for easier context-switchingĮfficiently manage multiple clusters in Azure Kubernetes Service.Get cluster contexts that your machine has access to.Get-credentials for an Azure Kubernetes Services cluster.Woohoo! Since it was a recurring question, I wanted to draft some tips over the weekend. The short answer is You don't need to do all of that every time. Last week I was discussing some questions over a coffee around containers in Azure in general, and one question that kept coming up was why you had to run az login, then az aks list and then az aks get-credentials every single time you want to switch between clusters that you've already authenticated with. ![]() If you - like me - sometimes manage multiple Azure Kubernetes Service clusters, then it will comes in handy to know how to conveniently context-switch between them in the same command line. □ TIP: Check out the guidance for building sustainable Azure workloads! □
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |