查看 k8s版本

使用kubectl version 命令,输出的信息会显示client和server的版本信息,client代表kubectl版本信息,server代表的是master节点的k8s版本信息

kubectl version    kubelet --version       kube-apiserver --version  等

升级准备  1.23.1升级到1.23.5

下载升级包

 k8s_version=v1.23.5
wget https://dl.k8s.io/${k8s_version}/kubernetes.tar.gz
 wget https://dl.k8s.io/${k8s_version}/kubernetes-client-linux-amd64.tar.gz
 wget https://dl.k8s.io/${k8s_version}/kubernetes-server-linux-amd64.tar.gz
 wget https://dl.k8s.io/${k8s_version}/kubernetes-node-linux-amd64.tar.gz

解压

tar xf kubernetes-1.23.5-client-darwin-amd64.tar.gz -C /usr/local/src
tar xf kubernetes-1.23.5-node-linux-amd64.tar.gz -C /usr/local/src
tar xf kubernetes-1.23.5-server-linux-amd64.tar.gz -C /usr/local/src
tar xf kubernetes-1.23.5.tar.gz -C /usr/local/src

复制升级文件到安装位置

cd /usr/local/src/kubernetes/server/bin/    #/usr/local/src/ 该地址为刚才指定解压地址

修改负载均衡规则  在所有节点执行

vim /etc/kube-lb/conf/kube-lb.conf 

#注释掉你需要升级的 master节点 

如下图 

重启 lb

systemctl restart kube-lb.service 

停服务

master:
 systemctl  stop kube-apiserver kube-controller-manager  kube-scheduler  kube-proxy kubelet

反向拷贝文件

\cp  kube-apiserver kube-controller-manager  kube-scheduler kubelet kube-proxy kubectl /usr/local/bin

启动服务

systemctl  start kube-apiserver kube-controller-manager  kube-scheduler  kube-proxy kubelet

核实升级情况

[root@master1 bin]# kubectl get node
NAME           STATUS                     ROLES    AGE   VERSION
172.31.7.101   Ready,SchedulingDisabled   master   22h   v1.23.5
172.31.7.102   Ready,SchedulingDisabled   master   22h   v1.23.1
172.31.7.111   Ready                      node     22h   v1.23.1
由此master1升级完成

master2类似就不展开说明了

node升级

驱逐node节点 容器 到其他node节点

kubectl  drain 172.31.7.111 --force --ignore-daemonsets  --delete-emptydir-data

[root@master1 bin]# kubectl get node
NAME           STATUS                     ROLES    AGE   VERSION
172.31.7.101   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.102   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.111   Ready,SchedulingDisabled   node     23h   v1.23.1

停服务

systemctl stop kubelet kube-proxy.service

传升级文件

scp r kubelet kube-proxy 172.31.7.111:/usr/local/bin

启服务

systemctl start kubelet kube-proxy.service

查看升级结果

[root@master1 bin]# kubectl get node
NAME           STATUS                     ROLES    AGE   VERSION
172.31.7.101   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.102   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.111   Ready,SchedulingDisabled   node     23h   v1.23.5

调整调度策略为可以使用

[root@master1 bin]# kubectl uncordon 172.31.7.111
node/172.31.7.111 uncordoned

再次核实结果正常了
[root@master1 bin]# kubectl get node
NAME           STATUS                     ROLES    AGE   VERSION
172.31.7.101   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.102   Ready,SchedulingDisabled   master   23h   v1.23.5
172.31.7.111   Ready                      node     23h   v1.23.5

#实际生产中不止一个node 由于本次实验 机器配置有限 所以走的单node   注意刚被驱逐的node里面是没有任何容器的

其他node节点重复以上步骤

所有升级完成

添加节点

添加node节点

cd /etc/kubeasz

[root@master1 kubeasz]# ./ezctl --help
Usage: ezctl COMMAND [args]
-------------------------------------------------------------------------------------
Cluster setups:
    list                             to list all of the managed clusters
    checkout    <cluster>            to switch default kubeconfig of the cluster
    new         <cluster>            to start a new k8s deploy with name 'cluster'
    setup       <cluster>  <step>    to setup a cluster, also supporting a step-by-step way
    start       <cluster>            to start all of the k8s services stopped by 'ezctl stop'
    stop        <cluster>            to stop all of the k8s services temporarily
    upgrade     <cluster>            to upgrade the k8s cluster
    destroy     <cluster>            to destroy the k8s cluster
    backup      <cluster>            to backup the cluster state (etcd snapshot)
    restore     <cluster>            to restore the cluster state from backups
    start-aio                        to quickly setup an all-in-one cluster with 'default' settings

Cluster ops:
    add-etcd    <cluster>  <ip>      to add a etcd-node to the etcd cluster
    add-master  <cluster>  <ip>      to add a master node to the k8s cluster
    add-node    <cluster>  <ip>      to add a work node to the k8s cluster
    del-etcd    <cluster>  <ip>      to delete a etcd-node from the etcd cluster
    del-master  <cluster>  <ip>      to delete a master node from the k8s cluster
    del-node    <cluster>  <ip>      to delete a work node from the k8s cluster

Extra operation:
    kcfg-adm    <cluster>  <args>    to manage client kubeconfig of the k8s cluster

Use "ezctl help <command>" for more information about a given command.

例如添加node2节点

./ezctl  add-node   k8s-cluster1  172.31.7.112

删除mase2r节点

./ezctl  del-master  k8s-cluster1  172.31.7.102

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐