简体   繁体   English

如何在不运行 Invoke 命令的情况下访问 azure k8s 集群?

[英]How to access azure k8s cluster without run Invoke Command?

I have an AKS cluster and it's private.我有一个 AKS 集群,它是私有的。 I want to access it from my local and i added necessary commands for kubeconfig.我想从本地访问它,并为 kubeconfig 添加了必要的命令。 Now, i can list pods with invoke command.现在,我可以使用 invoke 命令列出 pod。 But i want to access directly like kubectl get pods command.但是我想像 kubectl get pods 命令一样直接访问。 (i dont want do alias) (我不想做别名)

az aks command invoke \
  --resource-group rg-network-spokes \
  --name aks_dev_cluster \
  --command "kubectl get pods -A"

If your aks cluster is private, it means its controle plane is not exposed on internet and therefore you can not use kubectl to interact with the API without being into the same vnet as your cluster如果你的 aks 集群是私有的,这意味着它的控制平面没有暴露在互联网上,因此你不能使用 kubectl 与 API 交互,除非进入与你的集群相同的 vnet

在此处输入图像描述

You have a few options to do so, such as:您有几个选择可以这样做,例如:

  • Create a VM in the same VNET as your cluster and install kubectl client在与集群相同的 VNET 中创建 VM 并安装 kubectl 客户端
  • Create a VPN to connect your computer on the aks's network创建一个 VPN 以将您的计算机连接到 aks 的网络

If you are starting with Azure, I would suggest going with the first option as setting up a VPN can be a bit more tedious.如果您从 Azure 开始,我建议您选择第一个选项,因为设置 VPN 可能会更繁琐一些。

You can download the kubeconfig file in this path "/home/.kube/config" and now you are good to go.您可以在此路径“/home/.kube/config”中下载 kubeconfig 文件,现在一切顺利。

Or, Use Kubernetes Lens to manage from a UI.或者,使用 Kubernetes Lens 从 UI 进行管理。

  1. Your AKS cluster is private you must be accessing it via VPN right?你的 AKS 集群是私有的,你一定是通过 VPN 访问它吧? You can connect to VPN to access the cluster over private network.您可以连接到 VPN 以通过专用网络访问集群。 You can download the kubeconfig via this command.您可以通过此命令下载 kubeconfig。

Pre-req Azure Cli must be installed.必须先安装Azure Cli

az aks get-credentials --resource-group my-rg --name my-aks --file my-aks-kubeconfig-ss

It will generate a kubeconfig for you with name my-aks-kubeconfig-ss.它将为您生成一个名为 my-aks-kubeconfig-ss 的 kubeconfig。 You can copy this config and paste inside.kube/ folder or your choice.您可以复制此配置并粘贴到 .kube/ 文件夹或您的选择中。 You can access AKS cluster from Lens via UI mode.您可以通过 UI 模式从 Lens 访问 AKS 群集。

  1. Second option is to use lens .第二种选择是使用lens

Install lens.安装镜头。 After installation lens press ctrl + shift + A and a windows will open asking for kubeconfig.安装 lens 后按 ctrl + shift + A 将打开一个窗口询问 kubeconfig。 Copy the content from my-aks-kubeconfig-ss and paste it here.从 my-aks-kubeconfig-ss 复制内容并将其粘贴到此处。 Bingo your cluster is added inside Lens. Bingo 你的集群被添加到 Lens 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM