Shell(ssh)到Azure AKS(Kubernetes)群集工作程序节点

Gre*_*icz 2 kubernetes azure-kubernetes azure-aks

我使用AKS在Azure中有一个Kubernetes集群,我想“登录”到其中一个节点。节点没有公共IP。

有没有办法做到这一点?

dbo*_*cet 5

长期以来,Azure文档的文章中都介绍了该过程:https : //docs.microsoft.com/zh-cn/azure/aks/ssh。它包含运行一个pod(用作中继以ssh进入节点),并且运行良好:

您可能在集群创建期间指定了ssh用户名和公用密钥。如果不是,则必须将节点配置为接受它们作为ssh凭据:

$ az vm user update \
  --resource-group MC_myResourceGroup_myAKSCluster_region \
  --name node-name \
  --username theusername \
  --ssh-key-value ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

查找节点名称:

az vm list --resource-group MC_myResourceGroup_myAKSCluster_region -o table
Run Code Online (Sandbox Code Playgroud)

完成后,在群集中运行一个带有SSH客户端的Pod,这是将用于SSH到节点的Pod:

kubectl run -it --rm my-ssh-pod --image=debian
# install ssh components, as their is none in the Debian image
apt-get update && apt-get install openssh-client -y
Run Code Online (Sandbox Code Playgroud)

在您的工作站上,获取刚刚创建的Pod的名称:

$ kubectl get pods
Run Code Online (Sandbox Code Playgroud)

将您的私钥添加到窗格中:

$ kubectl cp ~/.ssh/id_rsa pod-name:/id_rsa
Run Code Online (Sandbox Code Playgroud)

然后,在pod中,通过ssh连接到您的节点之一:

ssh -i /id_rsa theusername@10.240.0.4
Run Code Online (Sandbox Code Playgroud)

(要在您的工作站上找到节点IP):

az vm list-ip-addresses --resource-group MC_myAKSCluster_myAKSCluster_region -o table
Run Code Online (Sandbox Code Playgroud)