gpt4 book ai didi

kubernetes - 如何重写 namespace

转载 作者:行者123 更新时间:2023-12-02 11:29:43 24 4
gpt4 key购买 nike

在以下情况下,我在../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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com