配置kubectl命令访问azure上的远程kubernetes集群 [英] Configure kubectl command to access remote kubernetes cluster on azure

查看:37
本文介绍了配置kubectl命令访问azure上的远程kubernetes集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 azure 上运行的 kubernetes 集群.从本地 kubectl 命令访问集群的方式是什么.我提到了这里,但在 kubernetes 主节点上没有 kube 配置文件.此外,kubectl config 视图导致

I have a kubernetes cluster running on azure. What is the way to access the cluster from local kubectl command. I referred to here but on the kubernetes master node there is no kube config file. Also, kubectl config view results in

apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

推荐答案

找到了一种无需通过 ssh 连接到集群中的一个节点即可访问远程 kubernetes 集群的方法.您需要编辑 ~/.kube/config 文件如下:

Found a way to access remote kubernetes cluster without ssh'ing to one of the nodes in cluster. You need to edit ~/.kube/config file as below :

apiVersion: v1 
clusters:    
- cluster:
    server: http://<master-ip>:<port>
  name: test 
contexts:
- context:
    cluster: test
    user: test
  name: test

然后通过执行来设置上下文:

Then set context by executing:

kubectl config use-context test

在此之后,您应该能够与集群进行交互.

After this you should be able to interact with the cluster.

注意:要添加认证和密钥,请使用以下链接:http://kubernetes.io/docs/user-guide/kubeconfig-file/

Note : To add certification and key use following link : http://kubernetes.io/docs/user-guide/kubeconfig-file/

或者,您也可以尝试以下命令

Alternately, you can also try following command

kubectl config set-cluster test-cluster --server=http://<master-ip>:<port> --api-version=v1
kubectl config use-context test-cluster

这篇关于配置kubectl命令访问azure上的远程kubernetes集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆