java操作k8s api示例:通过java完成对kubenetes原生资源对象(pod、node、namespace、servcie、deployment)和自定义资源对象CRD的增删改查或事件监听

本文主要是介绍java操作k8s api示例:通过java完成对kubenetes原生资源对象(pod、node、namespace、servcie、deployment)和自定义资源对象CRD的增删改查或事件监听,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文目标

基于官方kubernetes-client/java类库,实现通过java完成对kubenetes原生资源对象(pod、node、namespace、servcie、deployment)和自定义资源对象(如:cluster)的增删改查或事件监听(watch)

k8s-client-java选型

目前通过java操作k8s,开源版本共有两个:

  • kubernetes-client/java
  • fabric8io/kubernetes-client

kubernetes-client/java和fabric8io/kubernetes-client对比

和官网API一致性社区活跃度代码生成
kubernetes-client/java根据k8s-openapi随之更新,一致性和更新频率高目前不活跃kubernetes-client/java提供了生成代码的通用跨语言工具,该工具托管在 kubernetes-client / gen存储库中
fabric8io/kubernetes-client一致性低,更新慢;其中不支持k8s1.8和1.13社区活跃,目前使用者多暂无

鉴于kubernetes-client/java和官网API一致性好,本文决定采用它

kubernetes-client/java的使用

REST API

API 资源使用REST模式。

kube-apiserver 支持同时提供 https(默认监听在 6443 端口)和 http API(默认监听在 127.0.0.1 的 8080 端口),其中 http API 是非安全接口,不做任何认证授权机制,不建议生产环境启用。两个接口提供的 REST API 格式相同

img

图片来自 OpenShift Blog

  1. GET /<资源名的复数格式>:获得某一类型的资源列表,例如GET /pods 返回一个Pod资源列表。
  2. POST /<资源名的复数格式>:创建一个资源,该资源来自用户提供的JSON对象。
  3. GET /<资源名复数格式>/<名字>:通过给出的名称(Name)获得单个资源,例如GET /pods/first 返回一个名称为“first”的Pod。
  4. DELETE /<资源名复数格式>/<名字>:通过给出的名字删除单个资源,删除选项(DeleteOptions)中可以指定的优雅删除(Grace Deletion)的时间(GracePeriodSeconds),该可选项表明了从服务端接收到删除请求到资源被删除的时间间隔(单位为秒)。
  5. PUT /<资源名复数格式>/<名字>:通过给出的资源名和客户端提供的JSON对象来更新或创建资源。
  6. PATCH /<资源名复数格式>/<名字>:选择修改资源详细指定的域。
  7. GET /watch/<资源名复数格式>:随时间变化,不断接收一连串的JSON对象,这些JSON对象记录了给定资源类别内所有资源对象的变化情况。
  8. GET /watch/<资源名复数格式>/:随时间变化,不断接收一连串的JSON对象,这些JSON对象记录了某个给定资源对象的变化情况。

REST API版本说明

为了在兼容旧版本的同时不断升级新的API,Kubernetes支持多种API版本,每种API版本都有不同的API路径,例如/api/v1或 /apis/extensions/v1beta1。

Alpha级别:

  • 包含alpha名称的版本(例如v1alpha1)。
  • 该软件可能包含错误。启用一个功能可能会导致bug。默认情况下,功能可能会被禁用。

Beta级别:

  • 包含beta名称的版本(例如v2beta3)。
  • 该软件经过很好的测试。启用功能被认为是安全的。默认情况下功能是开启的。
  • 大家使用过的Beta版本后,可以多给社区反馈,如果此版本在后续更新后将不会有太大变化。

Stable级别:

  • 该版本名称命名方式:vX这里X是一个整数。
  • Stable版本的功能特性,将出现在后续发布的软件版本中。

Alpha、Beta、RC、GA版本的区别

  • Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只有测试人员使用。
  • Beta:也是测试版,这个阶段的版本会一直加入新的功能。在Alpha版之后推出。
  • RC:(Release Candidate) 顾名思义么 ! 用在软件上就是候选版本。系统平台上就是发行候选版本。RC版不会再加入新的功能了,主要着重于除错。
  • GA:General Availability,正式发布的版本,在国外都是用GA来说明release版本的。

kubectl api-versions

查看 apiserver暴露的接口

kubectl api-versions

或者

curl -H’Authorization: Bearer token’ https://192.168.1.122:6443/apis –insecure

[root@fly]# kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.istio.io/v1alpha1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
config.istio.io/v1alpha2
events.k8s.io/v1beta1
extensions/v1beta1
networking.istio.io/v1alpha3
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
rbac.istio.io/v1alpha1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

REST API 实例:

https://10.10.124.199:6443/apis/apps/v1/deployment

  1. https : kube-apiserver 支持同时提供https(默认监听在 6443 端口)和 http API(默认监听在 127.0.0.1 的 8080 端口),由于http api 是不会经过认证授权的,在生产环境中,为了安全性考虑,推荐是不启用。
  2. 10.10.124.199 : 该ip地址为kubernetes master 地址,在集群为高可用设置的场景下,该ip地址为 vip 地址。
  3. apis :kubernetes在这一层级只有api 与 apis ,api只有初步核心资源,包含pod,node,namespace等基本资源
  4. apps : 为api group 名,api group 是kubernetes 对资源类型特性相近的整合。
  5. v1: 是作为api group version, 在新资源类型的加入到kubernetes,会经历版本变迁: v1alpha1–>v1alpha2–>….–>v1alphaN–>v1beta1–>v1beta2–>v1 。
  6. deployment : 是kubernetes 的资源名

API Object 整体划分图 (红星符号代表常用资源)

img

kubernetes-client/java客户端API接口识别

打开kubernetes-client/java,只要是以Api结尾,一般就是我们可以调用的Api接口

img

API接口识别

ApiClient初始化&认证

ApiClient client = new ClientBuilder().setBasePath("ApiServer地址").setVerifyingSsl(false).setAuthentication(new AccessTokenAuthentication("Token")).build();Configuration.setDefaultApiClient(client);

在生产环境,建议放在 程序启动前的初始化方法中

CRD资源增删改查

使用 CustomObjectsApi apiInstance = new CustomObjectsApi(); 操作

MethodHTTP requestDescription
createClusterCustomObjectPOST /apis/{group}/{version}/{plural}创建集群范围CRD资源对象
createNamespacedCustomObjectPOST /apis/{group}/{version}/namespaces/{namespace}/{plural}创建分区范围CRD资源对象
deleteClusterCustomObjectDELETE /apis/{group}/{version}/{plural}/{name}删除集群范围CRD资源对象
deleteNamespacedCustomObjectDELETE/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}删除分区范围CRD资源对象
getClusterCustomObjectGET /apis/{group}/{version}/{plural}/{name}获取集群范围CRD资源对象
getClusterCustomObjectScaleGET /apis/{group}/{version}/{plural}/{name}/scale获取集群范围CRD资源对象-scale
getClusterCustomObjectStatusGET /apis/{group}/{version}/{plural}/{name}/status获取集群范围CRD资源对象-状态
getNamespacedCustomObjectGET /apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}获取分区范围CRD资源对象
getNamespacedCustomObjectScaleGET/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/scale获取分区范围CRD资源对象-scale
getNamespacedCustomObjectStatusGET/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/status获取分区范围CRD资源对象-状态
listClusterCustomObjectGET /apis/{group}/{version}/{plural}集群范围CRD资源对象列表
listNamespacedCustomObjectGET /apis/{group}/{version}/namespaces/{namespace}/{plural}分区范围CRD资源对象列表
patchClusterCustomObjectPATCH /apis/{group}/{version}/{plural}/{name}更新集群范围CRD资源对象
patchClusterCustomObjectScalePATCH /apis/{group}/{version}/{plural}/{name}/scale更新集群范围CRD资源对象-scale
patchClusterCustomObjectStatusPATCH /apis/{group}/{version}/{plural}/{name}/status更新集群范围CRD资源对象-状态
patchNamespacedCustomObjectPATCH/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}更新分区范围CRD资源对象
patchNamespacedCustomObjectScalePATCH/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/scale更新分区范围CRD资源对象-scale
patchNamespacedCustomObjectStatusPATCH/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/status更新分区范围CRD资源对象-状态
replaceClusterCustomObjectPUT /apis/{group}/{version}/{plural}/{name}替换集群范围CRD资源对象
replaceClusterCustomObjectScalePUT /apis/{group}/{version}/{plural}/{name}/scale替换集群范围CRD资源对象-scale
replaceClusterCustomObjectStatusPUT /apis/{group}/{version}/{plural}/{name}/status替换集群范围CRD资源对象-状态
replaceNamespacedCustomObjectPUT /apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}替换分区范围CRD资源对象
replaceNamespacedCustomObjectScalePUT/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/scale替换分区范围CRD资源对象-scale
replaceNamespacedCustomObjectStatusPUT/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}/status替换分区范围CRD资源对象-状态

操作示例

简要描述:

集群列表接口

请求方式:
  • GET
请求URL:
  • /apis/{group}/{version}/{plural}
请求URL示例:
  • /apis/flycloud.cn/v1/clusters
请求java示例:
        CustomObjectsApi apiInstance = new CustomObjectsApi();String group = "flycloud.cn"; String version = "v1";String plural = "clusters";String pretty = "ture";try {Object result = apiInstance.listClusterCustomObject(group,version,plural,pretty,null,null,null,null);String listCluster = JSON.toJSONString(result);System.out.println(listCluster);} catch (ApiException e) {System.err.println("Exception when calling CustomObjectsApi#listClusterCustomObject");e.printStackTrace();}

返回结果:

 {"apiVersion": "flycloud.cn/v1","items": [{"apiVersion": "flycloud.cn/v1","kind": "Cluster","metadata": {"annotations": {"name": "top"},"creationTimestamp": "2019-08-12T07:03:23Z","generation": 1.0,"labels": {"template": "platform"},"name": "top","namespace": "cluster-top","resourceVersion": "277020","selfLink": "/apis/flycloud.cn/v1/namespaces/cluster-top/clusters/top","uid": "46528941-bccf-11e9-bfeb-005056bc7cff"},"spec": {"info": {"address": "192.168.103.60","harbor": {"address": "192.168.103.65","password": "123456","port": 443.0,"protocol": "https","user": "admin"},"jenkins": {"password": "admin","type": "jenkins","username": "admin"},"mysql": {"connectionProperties": "druid.stat.mergeSql=true druid.stat.slowSqlMillis=5000","driverClass": "com.mysql.jdbc.Driver","filters": "stat","initialSize": 0.0,"logAbandoned": true,"maxActive": 100.0,"maxOpenPreparedStatements": 50.0,"maxWait": 60000.0,"minIdle": 0.0,"minPoolSize": 2.0,"password": "123456","poolPreparedStatements": false,"removeAbandoned": true,"removeAbandonedTimeout": 900.0,"type": "api-mysql","username": "root"},"network": {"networkFlag": "calico","version": 1.0},"nfs": [{"capacity": "1","ip": "192.168.103.65","name": "nfs","path": "/nfs/top","type": "nfs"}],"port": 6443.0,"prometheusPort": 30003.0,"protocol": "https","redis": {"maxTotal": 500.0,"maxWaitMillis": 15000.0,"minIdle": 10.0,"password": "123456","testOnBorrow": true,"testWhileIdle": true,"timeBetweenEvictionRunsMillis": 600000.0,"type": "api-redis"}},"template": [{"namespace": "kube-system","serviceName": "heapster","servicePort": [{"port": 80.0,"protocol": "TCP","type": "check"}],"type": "heapster"}, {"namespace": "kube-system","serviceName": "influxdb","servicePort": [{"port": 80.0,"protocol": "TCP","type": "web"}, {"port": 8086.0,"protocol": "TCP","type": "api"}],"type": "influxdb"}, {"namespace": "kube-system","serviceName": "elasticsearch-logging-v1","servicePort": [{"port": 9200.0,"protocol": "TCP","type": "web"}, {"port": 9300.0,"protocol": "TCP","type": "api"}],"type": "es"}, {"namespace": "kube-system","serviceName": "oam-api-service","servicePort": [{"port": 8081.0,"protocol": "TCP","type": "api"}],"type": "oam-api"}, {"namespace": "kube-system","serviceName": "oam-task-service","type": "oma-task"}, {"namespace": "kube-system","serviceName": "webapi-service","servicePort": [{"port": 8080.0,"protocol": "TCP","type": "api"}],"type": "webapi"}, {"namespace": "kube-system","serviceName": "webpage-service","servicePort": [{"port": 8887.0,"protocol": "TCP","type": "web"}],"type": "webpage"}, {"namespace": "kube-system","serviceName": "terminal-service","servicePort": [{"port": 8888.0,"protocol": "TCP","type": "api"}],"type": "terminal"}, {"namespace": "kube-system","serviceName": "api-mysql-service","servicePort": [{"nodePort": 30306.0,"port": 3306.0,"protocol": "TCP","type": "api"}],"type": "api-mysql"}, {"namespace": "kube-system","serviceName": "api-redis-service","servicePort": [{"nodePort": 30379.0,"port": 6379.0,"protocol": "TCP","type": "api"}],"type": "api-redis"}, {"namespace": "kube-system","serviceName": "jenkins","servicePort": [{"nodePort": 30080.0,"port": 8080.0,"protocol": "TCP","type": "api"}],"type": "jenkins"}, {"namespace": "kube-system","serviceName": "nfs-controller","type": "nfs-controller"}, {"namespace": "kube-system","serviceName": "auto-scale","type": "auto-scale"}, {"namespace": "kube-system","serviceName": "node-up-down","type": "node-up-down"}, {"namespace": "kube-system","serviceName": "calico-node","type": "calico-node"}, {"namespace": "kube-system","serviceName": "calico-kube-controller","type": "calico-cotnroller"}, {"namespace": "kube-system","serviceName": "kube-apiserver","type": "kube-apiserver"}, {"namespace": "kube-system","serviceName": "kube-controller-manager","type": "kube-controller-manager"}, {"namespace": "kube-system","serviceName": "kube-scheduler","type": "kube-scheduler"}, {"namespace": "kube-system","serviceName": "kube-proxy","type": "kube-proxy"}, {"namespace": "kube-system","serviceName": "etcd","type": "etcd"}, {"namespace": "kube-system","serviceName": "cluster-controller","type": "cluster-controller"}, {"namespace": "kube-system","serviceName": "kube-dns","servicePort": [{"port": 53.0,"protocol": "TCP","type": "check"}, {"port": 53.0,"protocol": "UDP","type": "dns"}],"type": "kube-dns"}]},"status": {"conditions": [{"status": false,"type": "Ready"}]}}, {"apiVersion": "flycloud.cn/v1","kind": "Cluster","metadata": {"annotations": {"name": "test"},"creationTimestamp": "2019-09-13T15:54:57Z","generation": 1.0,"labels": {"template": "dev"},"name": "test","namespace": "flycloud","resourceVersion": "7687403","selfLink": "/apis/flycloud.cn/v1/namespaces/flycloud/clusters/test","uid": "d5bddb21-d63e-11e9-b5a7-005056bc7cff"},"spec": {"info": {"address": "192.168.103.60","domain": [],"external": [{"labels": {"lb": "nginx"},"maxPort": 35000.0,"minPort": 33000.0,"tcpConfig": "system-expose-nginx-config-tcp","topLb": "192.168.103.61","type": "nginx","udpConfig": "system-expose-nginx-config-udp"}],"harbor": {"address": "192.168.103.59","password": "Harbor12345","port": 443.0,"protocol": "https","user": "admin"},"network": {"networkFlag": "calico","version": "1"},"nfs": [{"capacity": "1","ip": "192.168.103.65","name": "nfs","path": "/nfs/top","type": "nfs"}],"port": 6443.0,"prometheusPort": 30003.0,"protocol": "https","storages": []},"template": [{"namespace": "kube-system","serviceName": "auto-scale","type": "auto-scale"}, {"namespace": "kube-system","serviceName": "calico-kube-controller","type": "calico-cotnroller"}, {"namespace": "kube-system","serviceName": "calico-node","type": "calico-node"}, {"namespace": "kube-system","serviceName": "default-http-backend","servicePort": [{"port": 80.0,"protocol": "TCP","type": "web"}],"type": "default-http-backend"}, {"namespace": "kube-system","serviceName": "elasticsearch-logging-v1","servicePort": [{"port": 9200.0,"protocol": "TCP","type": "web"}, {"port": 9300.0,"protocol": "TCP","type": "api"}],"type": "es"}, {"namespace": "kube-system","serviceName": "etcd","type": "etcd"}, {"namespace": "kube-system","serviceName": "heapster","servicePort": [{"port": 80.0,"protocol": "TCP","type": "check"}],"type": "heapster"}, {"namespace": "kube-system","serviceName": "influxdb","servicePort": [{"port": 80.0,"protocol": "TCP","type": "web"}, {"port": 8086.0,"protocol": "TCP","type": "api"}],"type": "influxdb"}, {"namespace": "kube-system","serviceName": "kube-apiserver","type": "kube-apiserver"}, {"namespace": "kube-system","serviceName": "kube-controller-manager","type": "kube-controller-manager"}, {"namespace": "kube-system","serviceName": "kube-dns","servicePort": [{"port": 54.0,"protocol": "TCP","type": "check"}, {"port": 53.0,"protocol": "UDP","type": "dns"}],"type": "kube-dns"}, {"namespace": "kube-system","serviceName": "kube-proxy","type": "kube-proxy"}, {"namespace": "kube-system","serviceName": "kube-scheduler","type": "kube-scheduler"}, {"namespace": "kube-system","serviceName": "nfs-controller","type": "nfs-controller"}, {"namespace": "kube-system","serviceName": "nginx-controller","servicePort": [{"port": 80.0,"protocol": "TCP","type": "web"}],"type": "nginx-controller"}, {"namespace": "kube-system","serviceName": "node-up-down","type": "node-up-down"}, {"namespace": "kube-system","serviceName": "oam-api-service","servicePort": [{"port": 8081.0,"protocol": "TCP","type": "api"}],"type": "oam-api"}, {"namespace": "kube-system","serviceName": "oam-task-service","type": "oma-task"}, {"namespace": "kube-system","serviceName": "terminal-service","servicePort": [{"port": 8888.0,"protocol": "TCP","type": "api"}],"type": "terminal"}]},"status": {"conditions": [{"status": true,"type": "Ready"}]}}],"kind": "ClusterList","metadata": {"continue": "","resourceVersion": "7758294","selfLink": "/apis/flycloud.cn/v1/clusters"}
}

Namespaces增删改查

使用 CoreV1Api apiInstance = new CoreV1Api(); 操作

MethodHTTP requestDescription
createNamespacePOST /api/v1/namespaces创建分区
deleteNamespaceDELETE/api/v1/namespaces/{name}删除分区
listNamespaceGET /api/v1/namespaces分区列表
patchNamespacePATCH/api/v1/namespaces/{name}更新分区内容
readNamespaceGET/api/v1/namespaces/{name}查询指定分区详情
replaceNamespacePUT/api/v1/namespaces/{name}替换分区内容

Node增删改查

使用 CoreV1Api apiInstance = new CoreV1Api(); 操作

MethodHTTP requestDescription
createNodePOST /api/v1/nodes创建节点
deleteCollectionNodeDELETE /api/v1/nodes删除多个节点
deleteNodeDELETE/api/v1/nodes/{name}删除节点
listNodeGET /api/v1/nodes节点列表
patchNodePATCH/api/v1/nodes/{name}更新节点
readNodeGET /api/v1/nodes/{name}查询指定节点
replaceNodePUT /api/v1/nodes/{name}替换指定节点内容
replaceNodeStatusPUT/api/v1/nodes/{name}/status修改节点状态

Pod增删改查

使用 CoreV1Api apiInstance = new CoreV1Api(); 操作

MethodHTTP requestDescription
createNamespacedPodPOST /api/v1/namespaces/{namespace}/pods创建pod
deleteCollectionNamespacedPodDELETE/api/v1/namespaces/{namespace}/pods删除多个pod
deleteNamespacedPodDELETE/api/v1/namespaces/{namespace}/pods/{name}删除pod
listNamespacedPodGET /api/v1/namespaces/{namespace}/podspod列表
patchNamespacedPodPATCH/api/v1/namespaces/{namespace}/pods/{name}更新pod
readNamespacedPodGET/api/v1/namespaces/{namespace}/pods/{name}查询指定pod
replaceNamespacedPodPUT/api/v1/namespaces/{namespace}/pods/{name}替换指定pod内容

优先级增删改查

MethodHTTP requestDescription
createPriorityClassPOST /apis/scheduling.k8s.io/v1beta1/priorityclasses创建优先级
deleteCollectionPriorityClassDELETE /apis/scheduling.k8s.io/v1beta1/priorityclasses删除多个优先级
deletePriorityClassDELETE /apis/scheduling.k8s.io/v1beta1/priorityclasses/{name}删除优先级
getAPIResourcesGET /apis/scheduling.k8s.io/v1beta1/获取可用资源
listPriorityClassGET /apis/scheduling.k8s.io/v1beta1/priorityclasses优先级列表
patchPriorityClassPATCH /apis/scheduling.k8s.io/v1beta1/priorityclasses/{name}修改优先级
readPriorityClassGET /apis/scheduling.k8s.io/v1beta1/priorityclasses/{name}查询指定优先级
replacePriorityClassPUT /apis/scheduling.k8s.io/v1beta1/priorityclasses/{name}替换优先级

Services增删改查

使用 CoreV1Api apiInstance = new CoreV1Api(); 操作

MethodHTTP requestDescription
createNamespacedServicePOST /api/v1/namespaces/{namespace}/services创建服务
deleteNamespacedServiceDELETE/api/v1/namespaces/{namespace}/services/{name}删除服务
listNamespacedServiceGET /api/v1/namespaces/{namespace}/services服务列表
patchNamespacedServicePATCH/api/v1/namespaces/{namespace}/services/{name}修改指定服务内容
readNamespacedServiceGET/api/v1/namespaces/{namespace}/services/{name}查询指定服务内容
replaceNamespacedServicePUT/api/v1/namespaces/{namespace}/services/{name}替换指定服务内容

操作示例

@Testpublic void CoreV1ApiTest(){CoreV1Api apiInstance = new CoreV1Api();String pretty = "true"; String _continue = "_continue_example"; String fieldSelector = "fieldSelector_example"; String labelSelector = "labelSelector_example"; Integer limit = 56; String resourceVersion = "resourceVersion_example"; Integer timeoutSeconds = 56; Boolean watch = true; try {// Namespace列表V1NamespaceList result = apiInstance.listNamespace(null,pretty,null,null,null,null,null,null,null);// Node列表// V1NodeList result = apiInstance.listNode(null,pretty,null,null,null,null,null,null,null);// Service列表// V1ServiceList result = apiInstance.listNamespacedService("kube-system", null, null, null, null, null, null, null, null, null);// Service 详情// /api/v1/namespaces/kube-system/services/webapi-service// V1Service result = apiInstance.readNamespacedService("flyapi-service", "kube-system", null, null, null);System.out.println(result);// JSONGson gson=new Gson();String s = gson.toJson(result);System.out.println(s);} catch (ApiException e) {System.err.println("Exception when calling CoreV1Api#listNode");e.printStackTrace();}}

Deployment增删改查

使用 ExtensionsV1beta1Api apiInstance = new ExtensionsV1beta1Api(); 操作

MethodHTTP requestDescription
createNamespacedDeploymentPOST /apis/extensions/v1beta1/namespaces/{namespace}/deployments创建应用
deleteCollectionNamespacedDeploymentDELETE/apis/extensions/v1beta1/namespaces/{namespace}/deployments删除多个应用
deleteNamespacedDeploymentDELETE/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}删除应用
listNamespacedDeploymentGET /apis/extensions/v1beta1/namespaces/{namespace}/deployments应用列表
patchNamespacedDeploymentPATCH/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}更新应用
readNamespacedDeploymentGET/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}查询指定应用
replaceNamespacedDeploymentPUT/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}替换指定应用内容

参考链接:

https://github.com/kubernetes-client/java/tree/master/kubernetes
https://k8smeetup.github.io/docs/reference/client-libraries

https://glory.blog.csdn.net/article/details/101345091

这篇关于java操作k8s api示例:通过java完成对kubenetes原生资源对象(pod、node、namespace、servcie、deployment)和自定义资源对象CRD的增删改查或事件监听的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/719414

相关文章

SpringBoot实现RSA+AES自动接口解密的实战指南

《SpringBoot实现RSA+AES自动接口解密的实战指南》在当今数据泄露频发的网络环境中,接口安全已成为开发者不可忽视的核心议题,RSA+AES混合加密方案因其安全性高、性能优越而被广泛采用,本... 目录一、项目依赖与环境准备1.1 Maven依赖配置1.2 密钥生成与配置二、加密工具类实现2.1

使用Python的requests库调用API接口的详细步骤

《使用Python的requests库调用API接口的详细步骤》使用Python的requests库调用API接口是开发中最常用的方式之一,它简化了HTTP请求的处理流程,以下是详细步骤和实战示例,涵... 目录一、准备工作:安装 requests 库二、基本调用流程(以 RESTful API 为例)1.

在Java中实现线程之间的数据共享的几种方式总结

《在Java中实现线程之间的数据共享的几种方式总结》在Java中实现线程间数据共享是并发编程的核心需求,但需要谨慎处理同步问题以避免竞态条件,本文通过代码示例给大家介绍了几种主要实现方式及其最佳实践,... 目录1. 共享变量与同步机制2. 轻量级通信机制3. 线程安全容器4. 线程局部变量(ThreadL

Go语言使用select监听多个channel的示例详解

《Go语言使用select监听多个channel的示例详解》本文将聚焦Go并发中的一个强力工具,select,这篇文章将通过实际案例学习如何优雅地监听多个Channel,实现多任务处理、超时控制和非阻... 目录一、前言:为什么要使用select二、实战目标三、案例代码:监听两个任务结果和超时四、运行示例五

分布式锁在Spring Boot应用中的实现过程

《分布式锁在SpringBoot应用中的实现过程》文章介绍在SpringBoot中通过自定义Lock注解、LockAspect切面和RedisLockUtils工具类实现分布式锁,确保多实例并发操作... 目录Lock注解LockASPect切面RedisLockUtils工具类总结在现代微服务架构中,分布

Java使用Thumbnailator库实现图片处理与压缩功能

《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

python panda库从基础到高级操作分析

《pythonpanda库从基础到高级操作分析》本文介绍了Pandas库的核心功能,包括处理结构化数据的Series和DataFrame数据结构,数据读取、清洗、分组聚合、合并、时间序列分析及大数据... 目录1. Pandas 概述2. 基本操作:数据读取与查看3. 索引操作:精准定位数据4. Group

Spring Boot集成/输出/日志级别控制/持久化开发实践

《SpringBoot集成/输出/日志级别控制/持久化开发实践》SpringBoot默认集成Logback,支持灵活日志级别配置(INFO/DEBUG等),输出包含时间戳、级别、类名等信息,并可通过... 目录一、日志概述1.1、Spring Boot日志简介1.2、日志框架与默认配置1.3、日志的核心作用

破茧 JDBC:MyBatis 在 Spring Boot 中的轻量实践指南

《破茧JDBC:MyBatis在SpringBoot中的轻量实践指南》MyBatis是持久层框架,简化JDBC开发,通过接口+XML/注解实现数据访问,动态代理生成实现类,支持增删改查及参数... 目录一、什么是 MyBATis二、 MyBatis 入门2.1、创建项目2.2、配置数据库连接字符串2.3、入

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编