Openshift 模板可以在多个项目上创建对象吗
Can Openshift templates create objects over multiple projects
如果我创建项目 'A' 并想从其中部署一个模板,在项目 'A' 和另一个项目 'B' 中创建对象,我将如何实现这一点。我尝试在模板中简单地指定项目 'B' 的命名空间,但出现错误
the namespace of the provided object does not match the namespace sent on the request
If an object definition’s metadata includes a fixed namespace field value, the field will be stripped out of the definition during template instantiation. If the namespace field contains a parameter reference, normal parameter substitution will be performed and the object will be created in whatever namespace the parameter substitution resolved the value to, assuming the user has permission to create objects in that namespace.
因此只需将所需的命名空间指定为模板的参数即可。可用示例:
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: xxx
parameters:
- name: ns1
value: test1
- name: ns2
value: test2
objects:
- apiVersion: v1
data:
key1: value1
kind: ConfigMap
metadata:
namespace: ${ns1}
name: cm1
- apiVersion: v1
data:
key2: value2
kind: ConfigMap
metadata:
namespace: ${ns2}
name: cm2
如果我创建项目 'A' 并想从其中部署一个模板,在项目 'A' 和另一个项目 'B' 中创建对象,我将如何实现这一点。我尝试在模板中简单地指定项目 'B' 的命名空间,但出现错误
the namespace of the provided object does not match the namespace sent on the request
If an object definition’s metadata includes a fixed namespace field value, the field will be stripped out of the definition during template instantiation. If the namespace field contains a parameter reference, normal parameter substitution will be performed and the object will be created in whatever namespace the parameter substitution resolved the value to, assuming the user has permission to create objects in that namespace.
因此只需将所需的命名空间指定为模板的参数即可。可用示例:
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: xxx
parameters:
- name: ns1
value: test1
- name: ns2
value: test2
objects:
- apiVersion: v1
data:
key1: value1
kind: ConfigMap
metadata:
namespace: ${ns1}
name: cm1
- apiVersion: v1
data:
key2: value2
kind: ConfigMap
metadata:
namespace: ${ns2}
name: cm2