置kubectl命令以访问Azure上的远程kubernetes

置kubectl命令以访问Azure上的远程kubernetes

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

问题描述

我有一个在azure上运行的kubernetes集群.通过本地kubectl命令访问集群的方式是什么.我在此处进行了引用,但是在kubernetes主节点上没有kube配置文件.另外,kubectl config view的结果是

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: []

推荐答案

找到了一种访问远程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集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:43