使用kubeadm升级kubernetes集群

kubeadm升级k8s集群(v1.15.3 to v1.16.0版)

Kubernetes在2019年9月18日发布了年度的第三个版本1.16,本篇文章介绍使用kubeadm升级现在有的集群到v1.16.0

Kubernetes 1.16版本的发布徽章

Kubernetes 1.16版本的发布徽章

查看k8s集群版本

查看当前的k8s版本

1
2
3
4
5
6
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 20d v1.15.3
k8s-node1 Ready <none> 20d v1.15.3
k8s-node2 Ready <none> 20d v1.15.3
k8s-node3 Ready <none> 20d v1.15.3
1
2
[[email protected] ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:11:18Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
1
2
3
4
5
6
[[email protected]master ~]# kubelet --version
Kubernetes v1.15.3


[[email protected]master ~]# systemctl status kubelet.service |grep Active
Active: active (running) since Fri 2019-08-30 07:26:33 EDT; 3 weeks 0 days ago
1
2
3
[[email protected] yum.repos.d]# kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:13:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

查看版本支持

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@k8s-master yum.repos.d]# yum list kubelet kubeadm kubectl
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
kubeadm.x86_64 1.15.3-0 @kubernetes
kubectl.x86_64 1.15.3-0 @kubernetes
kubelet.x86_64 1.15.3-0 @kubernetes
Available Packages
kubeadm.x86_64 1.16.0-0 kubernetes
kubectl.x86_64 1.16.0-0 kubernetes
kubelet.x86_64 1.16.0-0 kubernetes

升级kubelet kubeadm kubectl版本到1.16.0(每个节点都执行)

1
2
3
4
5
6
7
8
9
10
11
12
[[email protected] ~]# yum install -y kubelet kubeadm kubectl
# systemctl daemon-reload && systemctl restart kubelet && systemctl status kubelet


[[email protected] ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
[[email protected] ~]# kubelet --version
Kubernetes v1.16.0
[[email protected] ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:34:01Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

升级k8s集群

1
2
3
4
5
6
[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 21d v1.15.3
k8s-node1 Ready <none> 20d v1.15.3
k8s-node2 Ready <none> 20d v1.15.3
k8s-node3 Ready <none> 20d v1.15.3

升级集群

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[[email protected] ~]# kubeadm config print init-defaults > kubeadm1.16.yaml

[[email protected] ~]# cat kubeadm1.16.yaml
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 10.122.17.200
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
name: k8s-master
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.16.0
networking:
dnsDomain: cluster.local
podSubnet: 192.168.0.0/16
serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs

1
2
3
4
5
6
7
8
9
10
11
12
13
[[email protected] ~]# kubeadm upgrade apply --config kubeadm1.16.yaml


.......
.......
.......
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

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

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

1
2
3
4
[[email protected] ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[[email protected] ~]# yum clean all
[[email protected] ~]# yum install -y kubelet kubeadm kubectl

systemctl daemon-reload && systemctl restart kubelet && systemctl status kubelet



[[email protected] ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[[email protected] ~]# kubelet --version
Kubernetes v1.16.0
[[email protected] ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:34:01Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[[email protected] ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}



[[email protected] ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 21d v1.16.0
k8s-node1 Ready <none> 21d v1.16.0
k8s-node2 Ready <none> 21d v1.16.0
k8s-node3 Ready <none> 21d v1.16.0


[[email protected] ~]# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default curl-6bf6db5c4f-dqw9x 1/1 Running 2 20d
ingress-nginx nginx-ingress-controller-6956498fcf-jkzbs 1/1 Running 1 16d
kube-system calico-kube-controllers-65b8787765-hx9cr 1/1 Running 1 21d
kube-system calico-node-2rlsz 1/1 Running 1 21d
kube-system calico-node-5vz46 1/1 Running 1 21d
kube-system calico-node-6szsd 1/1 Running 1 21d
kube-system calico-node-s5nmr 1/1 Running 1 21d
kube-system calicoctl 1/1 Running 1 20d
kube-system coredns-58cc8c89f4-cnl45 1/1 Running 1 26m
kube-system coredns-58cc8c89f4-nj8hr 1/1 Running 1 9m4s
kube-system etcd-k8s-master 1/1 Running 0 6m35s
kube-system kube-apiserver-k8s-master 1/1 Running 0 6m30s
kube-system kube-controller-manager-k8s-master 1/1 Running 0 6m35s
kube-system kube-proxy-52mbf 1/1 Running 1 26m
kube-system kube-proxy-gf75r 1/1 Running 1 25m
kube-system kube-proxy-hbvjf 1/1 Running 1 26m
kube-system kube-proxy-zppdf 1/1 Running 1 26m
kube-system kube-scheduler-k8s-master 1/1 Running 0 6m31s
kube-system kubernetes-dashboard-5dc4c54b55-c7sv2 1/1 Running 1 20d


[[email protected] ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
curl-6bf6db5c4f-dqw9x 1/1 Running 2 20d

验证cordns

1
2
3
4
5
6
7
8
9
10
11
12
13
[[email protected] ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
curl-6bf6db5c4f-dqw9x 1/1 Running 2 20d
[[email protected] ~]# kubectl exec -it curl-6bf6db5c4f-dqw9x -- /bin/sh
/bin/sh: shopt: not found
[ [email protected]:/ ]$ nslookup kubernetes.default
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
[ [email protected]:/ ]$ exit
[[email protected] ~]#

未解决的问题

kubectl get cs显示为unknown
错误提示信息示例如下:

1
2
3
4
5
# kubectl get cs
NAME AGE
scheduler <unknown>
controller-manager <unknown>
etcd-0 <unknown>

这个问题似乎对集群没有太大的影响,暂未解决,后续愿意确认之后会继续更新,如果有大神知道如何解决,请指点。

参考链接

1、 https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-upgrade/
2、 http://www.sohu.com/a/342118551_198222
3、 https://www.linuxidc.com/Linux/2019-09/160728.htm