您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Kubernetes1.14.1的開發(fā)指南”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Kubernetes1.14.1的開發(fā)指南”吧!
從yaml
生成對(duì)象
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)); } }
到此,相信大家對(duì)“Kubernetes1.14.1的開發(fā)指南”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。