K8S 升級

v1.13.0 --> v1.14.2

K8S 升級可以跨小版本,但是不能跨大版本升級,只能一個大版本一個大版本的升級
v1.13.0 --> v1.14.2 正確
v1.13.0 --> v1.17.0 錯誤




1 升級 kubeadm (所有節點都執行kubeadm升級)
# 查看當前集羣版本
[root@test1 ~]# kubectl get nodes
NAME    STATUS   ROLES    AGE   VERSION
test1   Ready    master   11d   v1.13.0
test2   Ready    <none>   10d   v1.13.0
test3   Ready    <none>   10d   v1.13.0
test4   Ready    <none>   10d   v1.13.0
[root@test1 ~]#

# 查看當前 k8s 版本
[root@test1 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:02:01Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
[root@test1 ~]#

# 查看倉庫集羣版本
[root@test1 ~]# yum list --showduplicates kubeadm --disableexcludes=kubernetes
[root@test1 ~]#

# 升級kubeadm版本及查看集羣是否滿足升級需求
[root@test1 ~]# yum install -y kubeadm-1.14.2
[root@test1 ~]#

# 查看升級後的 kubeadm 版本
[root@test1 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:51:21Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
[root@test1 ~]#

2 檢查集羣是否可升級
# 查看集羣是否可以升級,升級後各組件的版本信息
[root@test1 ~]# kubeadm upgrade plan 1.14.2
"[preflight] Running pre-flight checks.
[upgrade] Making sure the cluster is healthy:
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.13.0
[upgrade/versions] kubeadm version: v1.14.2

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   CURRENT       AVAILABLE
Kubelet     4 x v1.13.0   1.14.2

Upgrade to the latest version in the v1.13 series:

# 注意,這裏是將要替換的 鏡像版本
COMPONENT            CURRENT   AVAILABLE
API Server           v1.13.0   1.14.2
Controller Manager   v1.13.0   1.14.2
Scheduler            v1.13.0   1.14.2
Kube Proxy           v1.13.0   1.14.2
CoreDNS              1.2.6     1.3.1
Etcd                 3.2.24    3.3.10

You can now apply the upgrade by executing the following command:

        kubeadm upgrade apply 1.14.2

_____________________________________________________________________

[root@test1 ~]#

3 根據 上面給出的提示信息,下載相應的鏡像
cat > download_image.sh << eric
#!/bin/bash
# 定義鏡像集合數組
images=(
    kube-apiserver:v1.14.2
    kube-controller-manager:v1.14.2
    kube-scheduler:v1.14.2
    kube-proxy:v1.14.2
    pause:3.1
    etcd:3.3.10
    coredns:1.3.1
)
# 循環從 registry.cn-hangzhou.aliyuncs.com 中下載鏡像

echo '+----------------------------------------------------------------+'
for img in \${images[@]};
do
    # 從國內源下載鏡像
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/\$img
    # 改變鏡像名稱
    docker tag  registry.cn-hangzhou.aliyuncs.com/google_containers/\$img k8s.gcr.io/\$img
    # 刪除源始鏡像
    docker rmi  registry.cn-hangzhou.aliyuncs.com/google_containers/\$img
    #
    echo '+----------------------------------------------------------------+'
    echo ''
done

# 下載網絡插件
# 官網地址:https://quay.io/repository/coreos/flannel?tag=latest&tab=tags
docker pull quay.io/coreos/flannel:v0.10.0-amd64

eric

# 執行腳本 下載鏡像
[root@test1 ~]# ./download_image.sh
4 升級 k8s Server

[root@test1 ~]# kubeadm upgrade apply 1.14.2 -y

...... 此處省略

[upgrade/successful] SUCCESS! Your cluster was upgraded to "v1.14.2". Enjoy!

[upgrade/kubelet] Now that your control plane is upgraded, please proceed with upgrading your kubelets if you haven't already done so.
[root@test1 ~]#


5 升級 kubeadm、kubelet、kubectl (所有node節點)
yum install -y kubeadm-1.14.2 kubelet-1.14.2 kubectl-1.14.2
# 重新加載
systemctl daemon-reload && systemctl restart kubelet
升級**所有node節點**的相關鏡像
cat > download_image.sh << eric
#!/bin/bash
# 定義鏡像集合數組
images=(
    kube-proxy:v1.14.2
    pause:3.1
)
# 循環從 registry.cn-hangzhou.aliyuncs.com 中下載鏡像

echo '+----------------------------------------------------------------+'
for img in \${images[@]};
do
    # 從國內源下載鏡像
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/\$img
    # 改變鏡像名稱
    docker tag  registry.cn-hangzhou.aliyuncs.com/google_containers/\$img k8s.gcr.io/\$img
    # 刪除源始鏡像
    docker rmi  registry.cn-hangzhou.aliyuncs.com/google_containers/\$img
    #
    echo '+----------------------------------------------------------------+'
    echo ''
done

# 下載網絡插件
# 官網地址:https://quay.io/repository/coreos/flannel?tag=latest&tab=tags
docker pull quay.io/coreos/flannel:v0.10.0-amd64

eric

# 執行腳本 下載鏡像
[root@test1 ~]# ./download_image.sh

查看升級後的集羣
[root@test1 ~]# kubectl get nodes
NAME    STATUS     ROLES    AGE   VERSION
test1   Ready      master   11d   v1.14.2
test2   Ready      <none>   10d   v1.14.2
test3   Ready      <none>   10d   v1.14.2
test4   Ready      <none>   10d   v1.14.2
[root@test1 ~]#
[root@test1 ~]#
[root@test1 ~]#
[root@test1 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:14:56Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
[root@test1 ~]#



常見問題
# 查看當前 k8s 版本
[root@test1 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T20:56:12Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
[root@test1 ~]#
[root@test1 ~]#
# 檢查當前 版本的 k8s 是否可以升級到 指定的版本 (1.17.0)
[root@test1 ~]# kubeadm upgrade plan 1.17.0
[preflight] Running pre-flight checks.
[upgrade] Making sure the cluster is healthy:
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.13.0
[upgrade/versions] kubeadm version: v1.13.0
[upgrade/versions] WARNING: No recommended etcd for requested Kubernetes version (1.17.0)

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   CURRENT       AVAILABLE
Kubelet     4 x v1.13.0   1.17.0

Upgrade to the latest version in the v1.13 series:

COMPONENT            CURRENT   AVAILABLE
API Server           v1.13.0   1.17.0
Controller Manager   v1.13.0   1.17.0
Scheduler            v1.13.0   1.17.0
Kube Proxy           v1.13.0   1.17.0
CoreDNS              1.2.6     1.2.6
Etcd                 3.2.24    N/A

You can now apply the upgrade by executing the following command:

        kubeadm upgrade apply 1.17.0

Note: Before you can perform this upgrade, you have to update kubeadm to 1.17.0.

_____________________________________________________________________

[root@test1 ~]#
[root@test1 ~]#
# 根據提示,進行升級
[root@test1 ~]# kubeadm upgrade apply 1.17.0[preflight] Running pre-flight checks.
[upgrade] Making sure the cluster is healthy:
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[upgrade/apply] Respecting the --cri-socket flag that is set with higher priority than the config file.
[upgrade/version] You have chosen to change the cluster version to "v1.17.0"
[upgrade/versions] Cluster version: v1.13.0
[upgrade/versions] kubeadm version: v1.13.0
[upgrade/version] FATAL: the --version argument is invalid due to these fatal errors:

        # -升級到“ v1.17.0”的指定版本太高; kubeadm一次只能升級1個次要版本
        - Specified version to upgrade to "v1.17.0" is too high; kubeadm can upgrade only 1 minor version at a time

        # -升級到“ v1.17.0”的指定版本至少比kubeadm次要版本(17> 13)高一個次要版本。不支持這種升級
        - Specified version to upgrade to "v1.17.0" is at least one minor release higher than the kubeadm minor release (17 > 13). Such an upgrade is not supported

Please fix the misalignments highlighted above and try upgrading again
[root@test1 ~]#



kubelet 版本突然升級到最高
[root@test1 ~]# kubectl get nodes
NAME    STATUS     ROLES    AGE   VERSION
test1   NotReady   master   11d   v1.18.2
test2   Ready      <none>   10d   v1.14.2
test3   Ready      <none>   10d   v1.14.2
test4   Ready      <none>   10d   v1.14.2
[root@test1 ~]#

# 刪除原 kubelet
[root@test1 ~]# yum remove -y kubelet
[root@test1 ~]#
[root@test1 ~]#
# 重新安裝
[root@test1 ~]# yum install -y kubelet-1.14.2 kubeadm-1.14.2 kubectl-1.14.2
[root@test1 ~]#
[root@test1 ~]#
# 重新啓動
[root@test1 ~]# systemctl start kubelet && systemctl status kubelet && systemctl enable kubelet


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章