如何使用 kubernetes 客户端部署 ConfigMap Api
How to deploy a ConfigMap using kubernetes client Api
我想要具体的configMap结构
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map-router1
labels:
name: nc1
data:
object.properties: |
address: "1"
port: ""
如何用
表示缩进
object.properties:
我们必须再开发这部分代码
Map<String, String> data = new HashMap<>();
data.put("address","");
//...
V1ConfigMap configMap= new V1ConfigMap();
configMap.apiVersion("v1");
configMap.kind("ConfigMap");
configMap.metadata(meta);
configMap.data(data);
我假设您使用的是 Java 客户端。
当您从文件创建 configmap 时,会出现 object.properties 缩进。示例:kubectl create configmap myapp-config --from-file=object.properties
.
From what I have researched Java 客户端似乎只支持 <string, string>
作为 data 的值。由于你的文件 object.properties 只有 UTF-8 字符,你可以试试:
data.put("object.properties","address: \"1\"\nport: \"\"")
或创建如下所示的文件并在 Java 中作为字符串打开:
address: "1"
port: ""
您也可以使用 binaryData 而不是 data
打开文件并将其作为二进制文件添加到 configmap
我想要具体的configMap结构
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map-router1
labels:
name: nc1
data:
object.properties: |
address: "1"
port: ""
如何用
表示缩进object.properties:
我们必须再开发这部分代码
Map<String, String> data = new HashMap<>();
data.put("address","");
//...
V1ConfigMap configMap= new V1ConfigMap();
configMap.apiVersion("v1");
configMap.kind("ConfigMap");
configMap.metadata(meta);
configMap.data(data);
我假设您使用的是 Java 客户端。
当您从文件创建 configmap 时,会出现 object.properties 缩进。示例:kubectl create configmap myapp-config --from-file=object.properties
.
From what I have researched Java 客户端似乎只支持 <string, string>
作为 data 的值。由于你的文件 object.properties 只有 UTF-8 字符,你可以试试:
data.put("object.properties","address: \"1\"\nport: \"\"")
或创建如下所示的文件并在 Java 中作为字符串打开:
address: "1"
port: ""
您也可以使用 binaryData 而不是 data
打开文件并将其作为二进制文件添加到 configmap