在以下情况下,我在../base/中定义了我的容器。
在这个/dev/目录中,我想启动 namespace dev中的所有部署和statefulsets。
问题是我还想在local-path-storage命名空间中运行local-path-storage CSI。 kustomize将覆盖它并在“dev”命名空间中创建它。
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: dev
bases:
- ../base
resources:
- local-path-storage.yaml
我如何才能撤消仅local-path-storage.yaml的 namespace 覆盖?
最佳答案
Kustomize中尚不存在此功能。有一个open issue可以解决这个问题,但是在撰写本文时还没有开放的PR。
最快的解决方案是删除namespace
中的dev/kustomize.yaml
设置,并手动设置dev
中所有资源中的 namespace 。
从我前面提到的问题中无耻地复制的另一种选择是创建一个转换器来解决此问题:
#!/usr/bin/env /usr/bin/python3
import sys
import yaml
with open(sys.argv[1], "r") as stream:
try:
data = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print("Error parsing NamespaceTransformer input", file=sys.stderr)
# See kubectl api-resources --namespaced=false
blacklist = [
"ComponentStatus",
"Namespace",
"Node",
"PersistentVolume",
"MutatingWebhookConfiguration",
"ValidatingWebhookConfiguration",
"CustomResourceDefinition",
"APIService",
"MeshPolicy",
"TokenReview",
"SelfSubjectAccessReview",
"SelfSubjectRulesReview",
"SubjectAccessReview",
"CertificateSigningRequest",
"ClusterIssuer",
"BGPConfiguration",
"ClusterInformation",
"FelixConfiguration",
"GlobalBGPConfig",
"GlobalFelixConfig",
"GlobalNetworkPolicy",
"GlobalNetworkSet",
"HostEndpoint",
"IPPool",
"PodSecurityPolicy",
"NodeMetrics",
"PodSecurityPolicy",
"ClusterRoleBinding",
"ClusterRole",
"ClusterRbacConfig",
"PriorityClass",
"StorageClass",
"VolumeAttachment",
]
try:
for yaml_input in yaml.safe_load_all(sys.stdin):
if yaml_input['kind'] not in blacklist:
if "namespace" not in yaml_input["metadata"]:
yaml_input["metadata"]["namespace"] = data["namespace"]
print("---")
print(yaml.dump(yaml_input, default_flow_style=False))
except yaml.YAMLError as exc:
print("Error parsing YAML input\n\n%s\n\n" % input, file=sys.stderr)
关于kubernetes - 如何重写 namespace ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58173823/