类 KubeClientTams
- java.lang.Object
-
- net.wicp.tams.common.kubernetes.apiserver.KubeClientTams
-
public class KubeClientTams extends Object
- 作者:
- Andy.zhou
-
-
构造器概要
构造器 构造器 说明 KubeClientTams()通过Conf的配置得到clientKubeClientTams(io.fabric8.kubernetes.client.KubernetesClient client, io.kubernetes.client.openapi.ApiClient apiClient)KubeClientTams(String pathTypePath)配置文件路径得到clientKubeClientTams(String kubeconfigstr, String context)通过配置文件的内容和context得到client
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 net.wicp.tams.common.ResultbindAdminRoleForSa(String namespace, String bindname, String... sas)使用Secret类型是kubernetes.io/service-account-token,用于被serviceaccount引用。net.wicp.tams.common.ResultbindClusterAdminRoleForSa(String namespace, String bindname, String... sas)StringcallRestServiceToResult(boolean isLocalCluser, Integer port, String namespace, String serviceName, String relaUrl)调用服务的restfull接口,如果是非本地集群,那么要求被调用方安装curlnet.wicp.tams.common.http.HttpResultcallRestServiceToResult(Integer port, String namespace, String serviceName, String relaUrl, String... params)StringcallRestServiceToResultForExecGet(io.fabric8.kubernetes.api.model.Pod pod, Integer port, String namespace, String serviceName, String relaUrl, String... params)StringcallRestServiceToResultForExecPatch(io.fabric8.kubernetes.api.model.Pod pod, Integer port, String namespace, String serviceName, String relaUrl, String... params)InputStreamcopyFileFromPod(String namespace, String deploymentName, String podFilePath)复制文件从podBooleancopyFileToPod(String namespace, String deploymentName, String osFilepath, String podFilePath)复制文件到Podio.fabric8.kubernetes.api.model.GenericKubernetesResourcecreateCusObject(ICrdDef crdVesion, String namespace, InputStream fileInputStream)io.fabric8.kubernetes.api.model.GenericKubernetesResourcecreateCusObject(ICrdDef crdVesion, String version, String namespace, InputStream fileInputStream)net.wicp.tams.common.ResultcreateNamespace(String namespace)net.wicp.tams.common.ResultcreateOrUpdateImageRolling(String namespace, String imageValue, String rcPath)创建或更新RCvoidcreateRc(String namespace, FileInputStream fileInputStream)跟据文件创建RC TODO 测试voidcreateRc(String namespace, String filePath)voidcreateResourcequota(String namespace, int minCpu, int minMemory, int maxCpu, int maxMemory, int pods)创建命名空间配额voidcreateSvc(String namespace, FileInputStream fileInputStream)创建Service TODO 测试voidcreateSvc(String namespace, String filePath)booleandeleteCusObject(ICrdDef crdVesion, String namespace, String name)booleandeleteCusObject(ICrdDef crdVesion, String version, String namespace, String name)删除自定义的资源booleandelNamespace(String namespace)删除名称空间booleandelPodByLabel(String key, String value)booleandelPodByLabel(String namespace, String key, String value)booleandelPodByName(String podName)booleandelPodByName(String namespace, String podName)booleandelRc(String namespace, String rcName)voiddelResourcequota(String namespace)删除命名空间配额booleandelService(String serviceName)booleandelService(String namespace, String serviceName)booleandelSvc(String namespace, String svcName)删除svcProcessexecFlinkSqlClient(String namespace, String podname, String shellcmd)执行flink sql程序ProcessexecFlinkSqlClientTams(String namespace, String podname, String params, String initFilePath)执行tams定制的sqlclientProcessexecPod(String namespace, String podname)登陆pod(没有成功)Processexecshell(String namespace, String podname, String... cmdargs)voidexecShellToCallback(Process proc, net.wicp.tams.common.callback.IProcess callback, String... cmdargs)StringexecShellToResult(String namespace, String podname, boolean needError, String cmd)执行shell命令,并反回结果StringexecShellToResult(String namespace, String podname, String cmd)voidexecShellToSystemIO(String namespace, String podname, String... cmdargs)booleanexitNamespace(String namespace)io.fabric8.kubernetes.api.model.ServiceAccountfindCreateSa(String namespace, String saName)查找并创建SA,创建sa名称saName,绑定到集群角色cluster-adminio.fabric8.kubernetes.client.KubernetesClientgetClient()io.fabric8.kubernetes.api.model.OwnerReferencegetControllerOf(io.fabric8.kubernetes.api.model.HasMetadata md)得到资源的ownerio.fabric8.kubernetes.api.model.apps.DeploymentListgetDeploymentByLabel(String namespace, String label)io.fabric8.kubernetes.api.model.apps.DeploymentListgetDeploymentByLabel(String namespace, String label, String value)io.fabric8.kubernetes.api.model.apps.DeploymentgetDeploymentByLabelOne(String namespace, String label, String value)通过label查找惟一的deploymentio.fabric8.kubernetes.api.model.apps.DeploymentgetDeploymentByName(String namespace, String name)得到deploymentNameList<io.fabric8.kubernetes.api.model.batch.v1.Job>getJobListByIds(String namespace, Map<String,String> filtermap, String lable, String... ids)io.fabric8.kubernetes.api.model.NamespacegetNamespace(String namespace)io.fabric8.kubernetes.api.model.PodgetPodByDeployment(String namespace, String deploymentName, String... status)拿到deployment对应的某个podio.fabric8.kubernetes.api.model.PodgetPodByJob(String namespace, String jobName, String... status)io.fabric8.kubernetes.api.model.PodgetPodByService(String namespace, String serviceName)通过service拿到podList<io.fabric8.kubernetes.api.model.Pod>getPodListByDeployment(String namespace, String deploymentName, String... status)List<io.fabric8.kubernetes.api.model.Pod>getPodListByIds(String namespace, Map<String,String> filtermap, String lable, String... ids)查询pod,跟据过滤条件List<io.fabric8.kubernetes.api.model.Pod>getPodListByJob(String namespace, String jobName, String... status)List<io.fabric8.kubernetes.api.model.Pod>getPodListByService(String namespace, String serviceName)io.fabric8.kubernetes.api.model.ReplicationControllergetRC(String rcName)io.fabric8.kubernetes.api.model.ReplicationControllergetRC(String namespace, String rcName)通过名字得到RCio.fabric8.kubernetes.api.model.SecretgetSecretAccount(String namespace, String accountName)通过它可以拿到 data.ca.crt 和 data.token(base加密后的密文),通过 kubectl describe得到的token才是原文.io.fabric8.kubernetes.api.model.ServicegetService(String serviceName)io.fabric8.kubernetes.api.model.ServicegetService(String namespace, String serviceName)io.fabric8.kubernetes.api.model.ServiceListgetServices()io.fabric8.kubernetes.api.model.ServiceListgetServices(String namespace)io.fabric8.kubernetes.api.model.ServicegetSVC(String namespace, String rcName)得到serviceio.kubernetes.client.openapi.models.V1DeploymentinstallDeploymentByTemp(String namespace, String context, Map<String,Object> params)通过freemark模板和参数部署deploymentStringproKubeConfig(String clusterName, io.fabric8.kubernetes.api.model.Secret secret)生成kubeconfig文件,测试通过net.wicp.tams.common.ResultproKubeConfig(String clusterName, String namespace, String accountName, boolean isCluster)通过帐号创建配置文件List<org.apache.commons.lang3.tuple.Pair<String,PodPhase>>queryJobStatus(String namespace, Map<String,String> filtermap, String lable, String[] lableNames)List<org.apache.commons.lang3.tuple.Pair<String,PodPhase>>queryPodStatus(String namespace, Map<String,String> filtermap, String lable, String[] lableNames)voidscaleDeployment(String namespace, String deploymentName, int numberOfReplicas)更新副本List<io.fabric8.kubernetes.api.model.GenericKubernetesResource>selCusObject(ICrdDef crdVesion, String namespace, String name)List<io.fabric8.kubernetes.api.model.GenericKubernetesResource>selCusObject(ICrdDef crdVesion, String version, String namespace, String name)查询用户自定义的资源List<String>selPodNameByLabel(String namespace, Map<String,String> labelmap)通过label得到podList<String>selServiceByLabel(String namespace, Map<String,String> labelmap)通过label得到servicenet.wicp.tams.common.ResultupdateImageRolling(String namespace, String rcName, String imageValue)滚动更新image TODO 测试voidupdateRcImage(String namespace, String rcName, int containerIndex, String imageValue)更新容器的image TODO 测试InputStreamviewLog(io.fabric8.kubernetes.api.model.Pod pod)查看日志InputStreamviewLog(String namespace, String deploymentName)通过deploymentName随机查看其中一个pod的日志
-
-
-
构造器详细资料
-
KubeClientTams
public KubeClientTams()
通过Conf的配置得到client
-
KubeClientTams
public KubeClientTams(String kubeconfigstr, String context)
通过配置文件的内容和context得到client- 参数:
kubeconfigstr- kubeconfig内容context- 启用哪个context,传空则为当前context
-
KubeClientTams
public KubeClientTams(String pathTypePath)
配置文件路径得到client- 参数:
pathTypePath- 配置文件
-
KubeClientTams
public KubeClientTams(io.fabric8.kubernetes.client.KubernetesClient client, io.kubernetes.client.openapi.ApiClient apiClient)
-
-
方法详细资料
-
getClient
public io.fabric8.kubernetes.client.KubernetesClient getClient()
-
getNamespace
public io.fabric8.kubernetes.api.model.Namespace getNamespace(String namespace)
-
getServices
public io.fabric8.kubernetes.api.model.ServiceList getServices(String namespace)
-
getServices
public io.fabric8.kubernetes.api.model.ServiceList getServices()
-
getService
public io.fabric8.kubernetes.api.model.Service getService(String namespace, String serviceName)
-
createCusObject
public io.fabric8.kubernetes.api.model.GenericKubernetesResource createCusObject(ICrdDef crdVesion, String version, String namespace, InputStream fileInputStream)
-
createCusObject
public io.fabric8.kubernetes.api.model.GenericKubernetesResource createCusObject(ICrdDef crdVesion, String namespace, InputStream fileInputStream)
-
viewLog
public InputStream viewLog(io.fabric8.kubernetes.api.model.Pod pod)
查看日志- 参数:
pod-- 返回:
-
viewLog
public InputStream viewLog(String namespace, String deploymentName)
通过deploymentName随机查看其中一个pod的日志- 参数:
namespace-deploymentName-- 返回:
-
copyFileToPod
public Boolean copyFileToPod(String namespace, String deploymentName, String osFilepath, String podFilePath)
复制文件到Pod- 参数:
namespace-deploymentName-osFilepath-podFilePath-- 返回:
-
copyFileFromPod
public InputStream copyFileFromPod(String namespace, String deploymentName, String podFilePath)
复制文件从pod- 参数:
namespace-deploymentName-podFilePath-- 返回:
-
execFlinkSqlClient
public Process execFlinkSqlClient(String namespace, String podname, String shellcmd)
执行flink sql程序- 参数:
namespace-podname-- 返回:
-
execFlinkSqlClientTams
public Process execFlinkSqlClientTams(String namespace, String podname, String params, String initFilePath)
执行tams定制的sqlclient- 参数:
namespace-podname-params- 初始化文件的参数,如:tenantId:1,operate:2 表示租户为1,用户为2initFilePath- 初始化文件地址- 返回:
-
execPod
public Process execPod(String namespace, String podname)
登陆pod(没有成功)- 参数:
namespace-podname-- 返回:
-
execShellToSystemIO
public void execShellToSystemIO(String namespace, String podname, String... cmdargs)
-
execShellToResult
public String execShellToResult(String namespace, String podname, boolean needError, String cmd)
执行shell命令,并反回结果- 参数:
namespace- k8spodname- 容器名needError- 是否需要告警和错误信息cmd- 执行的命令- 返回:
-
callRestServiceToResult
public String callRestServiceToResult(boolean isLocalCluser, Integer port, String namespace, String serviceName, String relaUrl)
调用服务的restfull接口,如果是非本地集群,那么要求被调用方安装curl- 参数:
isLocalCluser- 是否本地k8s集群(用户方与被调用方在同一个集群),port- 端口,默认端口,本地集群是server的默认端口80,非本地就是port里面的服务默认端口8080namespace- 名称空间serviceName- 服务名relaUrl- 相对地址- 返回:
- null表示失败
-
callRestServiceToResult
public net.wicp.tams.common.http.HttpResult callRestServiceToResult(Integer port, String namespace, String serviceName, String relaUrl, String... params)
-
callRestServiceToResultForExecGet
public String callRestServiceToResultForExecGet(io.fabric8.kubernetes.api.model.Pod pod, Integer port, String namespace, String serviceName, String relaUrl, String... params)
-
callRestServiceToResultForExecPatch
public String callRestServiceToResultForExecPatch(io.fabric8.kubernetes.api.model.Pod pod, Integer port, String namespace, String serviceName, String relaUrl, String... params)
-
execShellToCallback
public void execShellToCallback(Process proc, net.wicp.tams.common.callback.IProcess callback, String... cmdargs)
-
deleteCusObject
public boolean deleteCusObject(ICrdDef crdVesion, String version, String namespace, String name)
删除自定义的资源- 参数:
crdVesion-version- 版本namespace-name-- 返回:
-
selCusObject
public List<io.fabric8.kubernetes.api.model.GenericKubernetesResource> selCusObject(ICrdDef crdVesion, String version, String namespace, String name)
查询用户自定义的资源- 参数:
crdVesion-version- 版本namespace-name-- 返回:
-
selCusObject
public List<io.fabric8.kubernetes.api.model.GenericKubernetesResource> selCusObject(ICrdDef crdVesion, String namespace, String name)
-
getService
public io.fabric8.kubernetes.api.model.Service getService(String serviceName)
-
getRC
public io.fabric8.kubernetes.api.model.ReplicationController getRC(String namespace, String rcName)
通过名字得到RC- 参数:
namespace-rcName-- 返回:
-
getRC
public io.fabric8.kubernetes.api.model.ReplicationController getRC(String rcName)
-
getSVC
public io.fabric8.kubernetes.api.model.Service getSVC(String namespace, String rcName)
得到service- 参数:
namespace-rcName-- 返回:
-
delService
public boolean delService(String serviceName)
-
createNamespace
public net.wicp.tams.common.Result createNamespace(String namespace)
-
exitNamespace
public boolean exitNamespace(String namespace)
-
delNamespace
public boolean delNamespace(String namespace)
删除名称空间- 参数:
namespace-- 返回:
- true:成功 false:没有此名称空间
-
delPodByName
public boolean delPodByName(String podName)
-
getPodByDeployment
public io.fabric8.kubernetes.api.model.Pod getPodByDeployment(String namespace, String deploymentName, String... status)
拿到deployment对应的某个pod- 参数:
namespace- 名称空间deploymentName-- 返回:
-
getPodListByDeployment
public List<io.fabric8.kubernetes.api.model.Pod> getPodListByDeployment(String namespace, String deploymentName, String... status)
-
getPodByJob
public io.fabric8.kubernetes.api.model.Pod getPodByJob(String namespace, String jobName, String... status)
-
getPodListByJob
public List<io.fabric8.kubernetes.api.model.Pod> getPodListByJob(String namespace, String jobName, String... status)
-
getPodByService
public io.fabric8.kubernetes.api.model.Pod getPodByService(String namespace, String serviceName)
通过service拿到pod- 参数:
namespace-serviceName-- 返回:
-
getPodListByService
public List<io.fabric8.kubernetes.api.model.Pod> getPodListByService(String namespace, String serviceName)
-
getPodListByIds
public List<io.fabric8.kubernetes.api.model.Pod> getPodListByIds(String namespace, Map<String,String> filtermap, String lable, String... ids)
查询pod,跟据过滤条件- 参数:
namespace-filtermap-lable-ids-- 返回:
-
getJobListByIds
public List<io.fabric8.kubernetes.api.model.batch.v1.Job> getJobListByIds(String namespace, Map<String,String> filtermap, String lable, String... ids)
- 参数:
namespace-filtermap-lable-ids-- 返回:
-
queryPodStatus
public List<org.apache.commons.lang3.tuple.Pair<String,PodPhase>> queryPodStatus(String namespace, Map<String,String> filtermap, String lable, String[] lableNames)
-
queryJobStatus
public List<org.apache.commons.lang3.tuple.Pair<String,PodPhase>> queryJobStatus(String namespace, Map<String,String> filtermap, String lable, String[] lableNames)
-
selPodNameByLabel
public List<String> selPodNameByLabel(String namespace, Map<String,String> labelmap)
通过label得到pod- 参数:
namespace-labelmap-- 返回:
-
selServiceByLabel
public List<String> selServiceByLabel(String namespace, Map<String,String> labelmap)
通过label得到service- 参数:
namespace-labelmap-- 返回:
-
createRc
public void createRc(String namespace, String filePath) throws net.wicp.tams.common.exception.ProjectException
- 抛出:
net.wicp.tams.common.exception.ProjectException
-
createRc
public void createRc(String namespace, FileInputStream fileInputStream) throws net.wicp.tams.common.exception.ProjectException
跟据文件创建RC TODO 测试- 参数:
fileInputStream- 输入流- 抛出:
net.wicp.tams.common.exception.ProjectException
-
createSvc
public void createSvc(String namespace, FileInputStream fileInputStream) throws net.wicp.tams.common.exception.ProjectException
创建Service TODO 测试- 参数:
namespace-fileInputStream-- 抛出:
net.wicp.tams.common.exception.ProjectException
-
createSvc
public void createSvc(String namespace, String filePath) throws net.wicp.tams.common.exception.ProjectException
- 抛出:
net.wicp.tams.common.exception.ProjectException
-
createResourcequota
public void createResourcequota(String namespace, int minCpu, int minMemory, int maxCpu, int maxMemory, int pods)
创建命名空间配额- 参数:
namespace-minCpu-minMemory-maxCpu-maxMemory-pods-
-
delResourcequota
public void delResourcequota(String namespace)
删除命名空间配额- 参数:
namespace-
-
updateRcImage
public void updateRcImage(String namespace, String rcName, int containerIndex, String imageValue)
更新容器的image TODO 测试- 参数:
namespace-rcName-containerIndex- 这个pod的第几个容器imageValue-
-
scaleDeployment
public void scaleDeployment(String namespace, String deploymentName, int numberOfReplicas) throws io.kubernetes.client.openapi.ApiException
更新副本- 参数:
namespace-deploymentName-numberOfReplicas-- 抛出:
io.kubernetes.client.openapi.ApiException
-
updateImageRolling
public net.wicp.tams.common.Result updateImageRolling(String namespace, String rcName, String imageValue)
滚动更新image TODO 测试- 参数:
namespace-rcName-imageValue-- 返回:
-
createOrUpdateImageRolling
public net.wicp.tams.common.Result createOrUpdateImageRolling(String namespace, String imageValue, String rcPath)
创建或更新RC- 参数:
namespace- 命名空间imageValue- image值rcPath- rc的文件路径- 返回:
- 创建或更新成功
-
getDeploymentByName
public io.fabric8.kubernetes.api.model.apps.Deployment getDeploymentByName(String namespace, String name)
得到deploymentName
-
getDeploymentByLabelOne
public io.fabric8.kubernetes.api.model.apps.Deployment getDeploymentByLabelOne(String namespace, String label, String value)
通过label查找惟一的deployment- 参数:
namespace-label-value-- 返回:
-
getDeploymentByLabel
public io.fabric8.kubernetes.api.model.apps.DeploymentList getDeploymentByLabel(String namespace, String label, String value)
-
getDeploymentByLabel
public io.fabric8.kubernetes.api.model.apps.DeploymentList getDeploymentByLabel(String namespace, String label)
-
installDeploymentByTemp
public io.kubernetes.client.openapi.models.V1Deployment installDeploymentByTemp(String namespace, String context, Map<String,Object> params)
通过freemark模板和参数部署deployment- 参数:
namespace-context-params-- 返回:
-
getControllerOf
public io.fabric8.kubernetes.api.model.OwnerReference getControllerOf(io.fabric8.kubernetes.api.model.HasMetadata md)
得到资源的owner- 参数:
md- 资源,如pod等- 返回:
- null表示没有owner
-
findCreateSa
public io.fabric8.kubernetes.api.model.ServiceAccount findCreateSa(String namespace, String saName)
查找并创建SA,创建sa名称saName,绑定到集群角色cluster-admin- 参数:
namespace-saName-- 返回:
-
bindAdminRoleForSa
public net.wicp.tams.common.Result bindAdminRoleForSa(String namespace, String bindname, String... sas)
使用Secret类型是kubernetes.io/service-account-token,用于被serviceaccount引用。serviceaccout 创建时 Kubernetes 会默认创建对应的 secret,即使删除也会重建。 查看:kubectl get RoleBinding- 参数:
namespace-bindname-sas-- 返回:
-
bindClusterAdminRoleForSa
public net.wicp.tams.common.Result bindClusterAdminRoleForSa(String namespace, String bindname, String... sas)
-
getSecretAccount
public io.fabric8.kubernetes.api.model.Secret getSecretAccount(String namespace, String accountName)
通过它可以拿到 data.ca.crt 和 data.token(base加密后的密文),通过 kubectl describe得到的token才是原文.- 参数:
namespace-accountName-- 返回:
-
proKubeConfig
public net.wicp.tams.common.Result proKubeConfig(String clusterName, String namespace, String accountName, boolean isCluster)
通过帐号创建配置文件- 参数:
namespace-accountName-isCluster- true:是集群管理员,false:名称空间管理员- 返回:
- RetObjs[0]为config的内容
-
-