Kubernetes1.14.1的开发指南
本篇内容主要讲解“Kubernetes1.14.1的开发指南”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Kubernetes1.14.1的开发指南”吧!
成都创新互联主要从事成都网站设计、成都网站建设、外贸网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务相山,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
从yaml
生成对象
Yaml yaml = new Yaml(); ExtensionsV1beta1Deployment body = yaml.loadAs(new FileReader("deployment.yaml"), ExtensionsV1beta1Deployment.class); ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(); api.createNamespacedDeployment("default", body, "");
import io.kubernetes.client.ApiClient import io.kubernetes.client.apis.CoreV1Api import io.kubernetes.client.util.Config def setKubeApiClient() throws IOException, ApiException { StringReader reader = new StringReader(this.kubeConfig) ApiClient apiClient = Config.fromConfig(reader) Configuration.setDefaultApiClient(apiClient) this.api = new CoreV1Api() } Where kubeConfig is a yaml.
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import org.yaml.snakeyaml.Yaml; import io.kubernetes.client.ApiException; import io.kubernetes.client.models.ExtensionsV1beta1Deployment; import io.kubernetes.client.models.V1Namespace; import io.kubernetes.client.models.V1Service; public class Solution { private static final String yaml_file = "/home/karthik/Desktop/cloud/java/kubernetes/1.yaml"; static MapobjMap = new HashMap<>(); static Yaml yaml = new Yaml(); static { objMap.put("Deployment", ExtensionsV1beta1Deployment.class); objMap.put("Namespace",V1Namespace.class); objMap.put("Service", V1Service.class); //fill the hashmap } public static void main(String[] args) throws FileNotFoundException, ApiException { FileReader fr =new FileReader(yaml_file); InputStream input = new FileInputStream(new File(yaml_file)); Map map = (Map) yaml.load(input); ExtensionsV1beta1Deployment body = (ExtensionsV1beta1Deployment) convertyamlToObject(fr, (String) map.get("kind")); ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(); System.out.println(body); } public static Object convertyamlToObject(FileReader fr, String kind) { return yaml.loadAs(fr, (Class
到此,相信大家对“Kubernetes1.14.1的开发指南”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
网页标题:Kubernetes1.14.1的开发指南
浏览地址:http://cdiso.cn/article/gjsiop.html