[kube-apiserver] How to upgrade etcd when upgrade api version in kube-apiserver ?

637 views
Skip to first unread message

batma...@gmail.com

unread,
Dec 21, 2021, 8:53:44 AM12/21/21
to Kubernetes developer/contributor discussion
Hi all,

We know kube-apiserver support upgrade api version. But how about old data? Detail as below:

1) kube-apiserver support upgrade api version. For example:
``` /xxx/api
apiVersion: v1
kind: xxx
spec:
name: "AAA"
```
upgrade to:
``` /xxx/api
apiVersion: v2
kind: xxx
spec:
name2: "BBB" # name change to name2
```

2) But if etcd has old data, how to upgrade old data in etcd? For example:
If I have already run v1 api in long time, etcd has these data:
```
/xxx/api
{"apiVersion": "v1", "kind": "xxx", "spec": {"name": "A1"}}
{"apiVersion": "v1", "kind": "xxx", "spec": {"name": "A2"}}
{"apiVersion": "v1", "kind": "xxx", "spec": {"name": "A3"}}
```
after upgrade, api v2 use name2 as key, so new api will write etcd like this:
```
/xxx/api
{"apiVersion": "v1", "kind": "xxx", "spec": {"name2": "B1"}}
```
But how about old data, I still need to use these old data, so I want data in etcd like this:
```
/xxx/api
{"apiVersion": "v1", "kind": "xxx", "spec": {"name2": "A1"}}
{"apiVersion": "v1", "kind": "xxx", "spec": {"name2": "A2"}}
{"apiVersion": "v1", "kind": "xxx", "spec": {"name2": "A3"}}
{"apiVersion": "v1", "kind": "xxx", "spec": {"name2": "B1"}} # this is new v2 api added
```

3) So does kube-apiserver support this function?
If it is, 1) where is the code? 2) how to do when upgrade, for example, need to write upgrade script?
If it is NOT, 1) why? 2) If I really need to upgrade api version to do these things like above, how to do? For example, how to write new yaml file?

Thank you ~

batma...@gmail.com

unread,
Dec 21, 2021, 9:16:44 AM12/21/21
to Kubernetes developer/contributor discussion
Will `kubectl convert` could do this?
If it could, how to write script or yaml file, to deal with this: "change name to name2"?

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages