- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
第
Java连接kubernates集群最优雅的两种方式
piler.source8/piler.source
piler.target8/piler.target
fabric.io.version6.10.0/fabric.io.version
/properties
dependencies
dependency
groupIdio.fabric8/groupId
artifactIdkubernetes-client/artifactId
version${fabric.io.version}/version
/dependency
/dependencies
目标:使用尽可能少的配置项来完成初始化工作,保证后续部署工作量最小
使用kubeconfig文件连接集群
可以获取集群的kubeconfig文件
环境变量配置
默认配置项:
KUBECONFIG=~/.kube/config
自定义配置:
KUBECONFIG=/opt/file/kubeconfig
importio.fabric8.kubernetes.api.model.Namespace;
importio.fabric8.kubernetes.api.model.NamespaceList;
importio.fabric8.kubernetes.client.KubernetesClient;
importio.fabric8.kubernetes.client.KubernetesClientBuilder;
publicclassK8sClientWithKubeConfig{
publicstaticvoidmAIn(String[]args){
KubernetesClientclient=newKubernetesClientBuilder().build();
System.out.println(client.getMasterUrl());
NamespaceListmyNs=spaces().list();
for(Namespacens:myNs.getItems()){
System.out.println(ns.getMetadata().getName());
client.close();
其中masterurl为kubeconfig文件中的server字段;
使用ServiceAccount连接集群
应用部署在k8s集群内,且可以创建ServiceAccount和进行授权等操作(RBAC)
apiVersion:v1
kind:ServiceAccount
metadata:
name:fmuser
apiVersion:rbac.authorization.k8s.io/v1
kind:ClusterRole
metadata:
name:fmuser-role
rules:
-apiGroups:[]
resources:[pods,namespaces]
verbs:[get,list,watch]
-apiGroups:[]
resources:[pods/log]
verbs:[get,list,watch]
-apiGroups:[]
resources:[pods]
verbs:[delete]
-apiGroups:[]
resources:[namespaces]
verbs:[get,list,watch]
apiVersion:rbac.authorization.k8s.io/v1
kind:ClusterRoleBinding
metadata:
name:fmuser-rolebinding
subjects:
-kind:ServiceAccount
name:fmuser
namespace:default
roleRef:
kind:ClusterRole
name:fmuser-role
apiGroup:rbac.authorization.k8s.io
资源授权根据实际使用情况设置即可,Role
您可能关注的文档
最近下载
- 少年中国说钢琴谱五线谱 完整版原版.pdf
- (2024年高考真题) 2024年新课标全国Ⅰ卷数学真题.docx VIP
- 小学六年级全册体育教案.doc VIP
- 2024年新华师大版数学七年级上册全册课件(新版教材).pptx
- 2025注安《安全生产法律法规》考前必背笔记.pdf VIP
- 2025年小学生软笔书法兴趣培养的研究[五篇] .pdf VIP
- 碳酸钠的性质与应用说课.pptx VIP
- 碳捕捉与封存(CCUS)在海洋工程领域的应用与挑战研究报告.docx
- 2023年月嫂资格证考试《母婴护理师、母婴保健师》知识题库(含答案).pdf VIP
- 航天飞机任务2007中文操作手册.pdf VIP
文档评论(0)