您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
本篇内容主要讲解“Kubernetes1.14.1的开发指南”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Kubernetes1.14.1的开发指南”吧!
从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 Map<String,Object> objMap = 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<Object>) objMap.get(kind)); } }
到此,相信大家对“Kubernetes1.14.1的开发指南”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。