Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Development Guide for Kubernetes1.14.1

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the Development Guide of Kubernetes1.14.1". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the "Kubernetes1.14.1 Development Guide"!

Generate objects from 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.ApiClientimport io.kubernetes.client.apis.CoreV1Apiimport 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 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) objMap.get (kind));}} so far, I believe you have a deeper understanding of the "Kubernetes1.14.1 Development Guide". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report