Java k8s 创建pod
Java k8s 利用YAML配置文件的形式创建pod,通过volumeMounts和volumes进行路径挂载public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {//获取客户端ApiClient client = Config.defaultClient(
·
Java k8s 利用YAML配置文件的形式创建pod,通过volumeMounts和volumes进行路径挂载
public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {
//获取客户端
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
//指定分类
Yaml.addModelMap("v1", "Pod", V1Pod.class);
//加载配置文件
File file = ResourceUtils.getFile("classpath:test-svc.yaml");
V1Pod v1Pod = (V1Pod) Yaml.load(file);
//打印格式
System.out.println(Yaml.dump(v1Pod));
//创建pod
CoreV1Api api = new CoreV1Api();
V1Pod v1Pod1 = api.createNamespacedPod("default", v1Pod, "false", null, null);
}
配置文件如下:
apiVersion: v1 #API版本
kind: Pod #类型
metadata:
name: xueweitest #节点名称
labels:
app: web
spec:
nodeName: server100 #指定运行节点,为了测测试添加
restartPolicy : Never #重启策略[Always | Never | OnFailure]
containers:
- args: #给容器传参
- --NO
- 20200728154957171
- --EType
- dynamic
- --MPath
- /home/model
image: 127.0.0.1:7005/xuewei/myImage:v1.0 #镜像名:TAG
name: xueweitest #容器名称
ports:
- containerPort: 80 #默认端口,没有设置80,否则启动失败
volumeMounts: #挂载镜像 容器内路径
- name: model
mountPath: /home/model
- name: dataset
mountPath: /home/dataset
volumes: #挂载镜像 本地路径
- name: model
hostPath:
path: /home/data/atp/evaluation/
- name: dataset
hostPath:
path: /home/data/atp/dataset/0b3b279a673b3f5706b9c2975e3ddf9a
更多推荐
已为社区贡献3条内容
所有评论(0)