I wonder how Kubernetes executes updates. Let's say that two entities perform an update at the same time. How will the configuration be applied? Is applying/deleting configuration and in general performing mutations over K8S API an atomic operation? Is it possible to perform a mutation based on a condition?
Let's take this simple ConfigMap for an example:
apiVersion: v1
kind: ConfigMap
metadata:
name: testmap
data:
foo: "1"
I'd like to update this configuration by setting foo: "2"
but only if the foo: "1"
exists in the ConfigMap. Such atomic features can be found in databases like MongoDB (e.g. findAndModify), Redis, etc. How can I achieve atomicity in K8S?
In Kubernetes you will need to communicate with kube-apiserver to view resources or make changes to them.
kube-apiserver
is usingetcd
as a place to store data required by Kubernetes.You can read on the official site of
etcd
:As you can read above,
etcd
has a guarantee to be consistent.More information about the operations on resources can be found in this blog post:
You can read there (blog post is quite lengthy but explanatory):
Additional resources:
I found similar case on Stackoverflow which is also dealing with similar question: