当前,我们正在使用以下命令在Openshift中更新configmap设置(此后,我们将重新启动Pod,以使设置生效):
oc apply -f configmap.yml
我的问题是:
该命令将删除现有的configmap并将其替换为该文件的内容,还是仅从文件中导入设置,而保持其他任何设置不变?
基本上,如果实时配置映射包含设置
mytest: true
且新文件不包含参数mytest
,该参数是否保留在Openshift的实时配置映射中,或者由于导入文件中未列出该参数而将其删除? 最佳答案
我已经转载了您的案例,并在使用具有不同configmap设置的新yaml之后,新版本开始了。因此,OpenShift不是合并configmap,而是在替换。
让我们一起走下去...
kind: ConfigMap
apiVersion: v1
metadata:
name: example-config
data:
mytest0: "HELLO"
mytest1: "STACK"
mytest2: "COMMUNITY"
mytest3: "!!!"
oc apply -f configmap_lab.yaml
如我们所见,我们按预期包含了所有内容:
$ oc get configmap/example-config -o yaml
apiVersion: v1
data:
mytest0: HELLO
mytest1: STACK
mytest2: COMMUNITY
mytest3: '!!!'
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"mytest0":"HELLO","mytest1":"STACK","mytest2":"COMMUNITY","mytest3":"!!!"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"example-config","namespace":"myproject"}}
creationTimestamp: 2020-01-09T10:42:11Z
name: example-config
namespace: myproject
resourceVersion: "7987774"
selfLink: /api/v1/namespaces/myproject/configmaps/example-config
uid: b148dbef-32cc-11ea-9339-525400d653ae
现在,让我们在此之上部署一个新的Yaml:
kind: ConfigMap
apiVersion: v1
metadata:
name: example-config
data:
mytest0: "THANKS"
mytest1: "STACK"
newmytest0: "COMMUNITY"
newmytest1: "!!!"
在这里,我们要更改值,删除2并添加2个参数。让我们检查一下OC将如何处理:
oc apply -f configmap_lab_new.yaml
$ oc get configmap/example-config -o yaml
apiVersion: v1
data:
mytest0: THANKS
mytest1: STACK
newmytest0: COMMUNITY
newmytest1: '!!!'
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"mytest0":"THANKS","mytest1":"STACK","newmytest0":"COMMUNITY","newmytest1":"!!!"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"example-config","namespace":"myproject"}}
creationTimestamp: 2020-01-09T10:42:11Z
name: example-config
namespace: myproject
resourceVersion: "7988585"
selfLink: /api/v1/namespaces/myproject/configmaps/example-config
uid: b148dbef-32cc-11ea-9339-525400d653ae
我们注意到,所有更改都被接受并且处于 Activity 状态。
尽管如果您想以更可控的方式进行操作,则可能需要使用
oc patch
。 Doc here。关于kubernetes - Openshift “oc apply”是覆盖整个配置还是仅覆盖所包含的参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59653001/