|NO.Z.00186|——————————|CloudNative|——|KuberNetes&配置管理.V17|——|configmap.secret热更新.v03|k8s.v1.19不可变secret和configmap|
一、k8s1.19不可变的secret和configmap
### --- immutable
~~~ 在k8s1.18版本之后引入了一个immutable这种机制:
~~~ 这个参数在设置configmap和secret的时候把它设置为不可变的。
### --- 为什么会引入这种机制呢?
~~~ 容器挂载了configmap或者secret到本地,若是容器加载了这个功能,
~~~ 若是更改了configmap或者secret,它就会把这个内容更新到本地,
~~~ 本地监听到这个文件的变化,它就会重载这个配置。
~~~ 若是这个配置更改错了,会影响这个pod的使用。
~~~ 所以k8s1.18版本之后引入了immutable可以吧configmap或者secret设置成不可变的。
~~~ 到1.19之后就到了bat版本了(就是公测版本),就可以直接使用它了。
二、创建一个immutable类型的configmap.pod
### --- 创建一个immutable的pod
[root@k8s-master01 ~]# kubectl create cm test-immutable --from-file=/etc/kubernetes/admin.kubeconfig
configmap/test-immutable created
### --- edit一下这个configmap文件,因为我们还没有设置禁止修改,所以可以修改成功
[root@k8s-master01 ~]# kubectl edit cm test-immutable
configmap/test-immutable edited // 说明是可以去更改的
### --- 若是把immutable参数该加上,它是不可以被修改的
[root@k8s-master01 ~]# kubectl edit cm test-immutable
immutable: true // 文件末尾加上配置参数
configmap/test-immutable edited
### --- 再次更改configmap文件查看结果
[root@k8s-master01 ~]# kubectl edit cm test-immutable // 再次变价configmap文件,会显示提示信息;这个文件是不可以去更改的。
# configmaps "test-immutable" was not valid:
# * data: Forbidden: field is immutable when `immutable` is set
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
浙公网安备 33010602011771号