istio - 是否可以使用 oc patch 命令修补“istio-sidecar-injector”ConfigMap?
问题描述
由于上游 istio 自动 sidecar 注入配置还将 sidecar 容器部署到 builder 和 deployer pod(对于 openshift .. 当您使用 S2I 时),我们必须修补 ConfigMap (istio-sidecar-injector) 并且没有 sidecar 的例外情况容器注入到 builder 和 deployer pod。
例如,我们必须在 ConfigMap 中手动添加以下异常。
apiVersion: v1
kind: ConfigMap
metadata:
name: istio-sidecar-injector
data:
config: |-
policy: enabled
neverInjectSelector:
- matchExpressions:
- {key: openshift.io/build.name, operator: Exists}
- matchExpressions:
- {key: openshift.io/deployer-pod-for.name, operator: Exists}
template: |-
initContainers:
问题:我正在尝试使用 shell 脚本自动执行此操作,并在以编程方式更新以下参数时面临挑战。
neverInjectSelector:
- matchExpressions:
- {key: openshift.io/build.name, operator: Exists}
- matchExpressions:
- {key: openshift.io/deployer-pod-for.name, operator: Exists}
是否可以使用 oc patch 命令在 configmap 下面进行更新
apiVersion: v1
kind: ConfigMap
metadata:
name: istio-sidecar-injector
data:
config: |-
policy: enabled
neverInjectSelector:
[ ]
至
apiVersion: v1
kind: ConfigMap
metadata:
name: istio-sidecar-injector
data:
config: |-
policy: enabled
neverInjectSelector:
- matchExpressions:
- {key: openshift.io/build.name, operator: Exists}
- matchExpressions:
- {key: openshift.io/deployer-pod-for.name, operator: Exists}
template: |-
initContainers:
解决方案
Not an oc patch command ... I think we can achieve the same by following below code which may not be elegant solution.
oc project istio-system #change to the project
oc export cm istio-sidecar-injector >> exception.yaml #export the existing cm
sed -i '8s/.*/ - matchExpressions:\n - {key: openshift.io\/build.name, operator: Exists}\n - matchExpressions:\n - {key: openshift.io\/deployer-pod-for.name, operator: Exists}/' exception.yaml
kubectl apply -f exception.yaml
推荐阅读
- elixir - Distillery 未替换 systemd 版本中的变量
- antlr4 - ANTLR4:规则“规则”包含一个闭包,其中至少有一个可以匹配空字符串的替代方案
- excel - 调用退出函数时出错 | 递归的
- sql - Hiveql - 如何在字符串中只保留数字和空格
- python - 迭代数据框中的列以运行/追加计算
- visual-studio - 在 Visual Studio 中 NuGet 强制更新依赖包
- ios - 未从 Main.Storyboard 加载翻译(英文)
- .net - 如何防止 Windows 窗体充当 GC 根
- javascript - JSON & Javascript - 动态 DOM 操作
- c++ - QPlainTextEdit / QTextCursor - 如何获取光标上方和下方的行,直到上方和下方为空行