多K8s集群切换中Kubectl客户端如何配置


这篇文章主要介绍了多K8s集群切换中Kubectl客户端如何配置,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。kubectl的配置文件位置kubectl配置文件的主要位置是$ HOME / .kube,默认情况下,我们有一个名为config的配置文件:[node1 ~]$ cd $HOME/.kube [node1 .kube]$ ls -lah total 4.0K drwxr-xr-x 1 root root 37 Mar 12 20:48 . dr-xr-x— 1 root root 19 Nov 29 11:46 .. drwxr-x— 3 root root 23 Mar 12 20:48 cache lrwxrwxrwx 1 root root 26 Nov 29 11:46 config -> /etc/kubernetes/admin.conf drwxr-x— 3 root root 4.0K Mar 12 20:48 http-cache多个配置文件和KUBECONFIG变量通过设置适当的KUBECONFIG shell变量,我们可以拥有多个配置文件。例如:export KUBECONFIG=$KUBECONFIG:/root/.kube/additional_config从kubectl检查配置我们可以检查当前的配置(由于我的Additional_config文件中没有任何内容,因此将为空-我们稍后将添加一些内容-这只是我的KUBECONFIG变量中的文件):[node1 ~]$ kubectl config view apiVersion: v1 clusters: [] contexts: [] current-context: “” kind: Config preferences: {} users: []或来自特定文件-让我们看看默认文件:[node1 ~]$ kubectl config –kubeconfig=.kube/config view apiVersion: v1 clusters:cluster: certificate-authority-data: DATA+OMITTED server: https://192.168.0.38:6443 name: kubernetes contexts:context: cluster: kubernetes user: kubernetes-admin name: kubernetes-admin@kubernetes current-context: kubernetes-admin@kubernetes kind: Config preferences: {} users:name: kubernetes-admin user: client-certificate-data: REDACTED client-key-data: REDACTED如果您未设置KUBECONFIG变量,则所有配置都将从$ HOME / .kube / config中获取kubectl配置中的对象kubectl在其配置文件中具有以下对象类型集群-有关K8s集群的信息-包含群集名称和连接参数users-有关您要连接到K8s集群的用户的信息上下文-集群/用户/命名空间的三倍从kubectl修改配置添加集群[node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-cluster dev –server=https://192.168.1.100 –certificate-authority=fake-ca Cluster “dev” set. [node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-cluster prod –server=https://10.1.1.100 –certificate-authority=fake-ca Cluster “prod” set.新增使用者[node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-credentials developer –client-certificate=fake-cert-file –client-key=fake-key-seefile User “developer” set. [node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-credentials prod_admin –client-certificate=fake-cert-file –client-key=fake-key-seefile User “prod_admin” set.添加上下文[node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-context simple_app_development –cluster=dev –namespace=simple_app_dev –user=developer Context “simple_app_development” created. [node1 ~]$ kubectl config –kubeconfig=.kube/additional_config set-context simple_app_production –cluster=prod –namespace=simple_app_prod –user=prod_admin Context “simple_app_production” created.从配置中删除集群/用户/上下文kubectl –kubeconfig=.kube/additional_config config unset users. kubectl –kubeconfig=.kube/additional_config config unset clusters. kubectl –kubeconfig=.kube/additional_config config unset contexts.样本配置[node1 ~]$ kubectl config –kubeconfig=.kube/additional_config view apiVersion: v1 clusters:cluster: certificate-authority: /root/fake-ca server: https://192.168.1.100 name: devcluster: certificate-authority: /root/fake-ca server: https://10.1.1.100 name: prod contexts:context: cluster: dev namespace: simple_app_dev user: developer name: simple_app_developmentcontext: cluster: prod namespace: simple_app_prod user: prod_admin name: simple_app_production current-context: “” kind: Config preferences: {} users:name: developer user: client-certificate: /root/fake-cert-file client-key: /root/fake-key-seefilename: prod_admin user: client-certificate: /root/fake-cert-file client-key: /root/fake-key-seefile改变环境要获取上下文列表(不需要–kubeconfig,因为我们已将extra_config添加到KUBECONFIG变量中):[node1 ~]$ kube开发云主机域名ctl config get-contexts CURRENT NAME CLUSTER AUTHINFO NAMESPACE simple_app_development dev developer simple_app_dev simple_app_production prod prod_admin simple_app_prod设置上下文:[node1 ~]$ kubectl config use-context simple_app_development Switched to context “simple_app_development”.获取当前上下文:[node1 ~]$ kubectl config current-context simple_app_development 感谢你能够认真阅读完这篇文章,希望小编分享的“多K8s集群切换中Kubectl客户端如何配置”这篇文章对大家有帮助,同时也希望大家多多支持开发云,关注开发云行业资讯频道,更多相关知识等着你来学习!

相关推荐: Salesforce怎么实现发邮件功能

今天小编给大家分享一下Salesforce怎么实现发邮件功能的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下开发云主机域名面我们一起来了解一下吧。 首先我们来捋一下思路,…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

Like (0)
Donate 微信扫一扫 微信扫一扫
Previous 05/28 17:57
Next 05/28 17:58

相关推荐