说明:coredns主要是Kubernetes中对域名和ip解析,可以作为内网的dns解析服务器。在日常工作中原来初始化使用k8s的时候,coredns 版本较低,在安全性以及性能等问题上会有一定瑕疵。因此做使用了K8S集群一定时间后,需要对一些K8S组件进行升级。
本文章将介绍下如何升级K8S的coredns 组件。
coredns 备份
mkdir coredns && cd coredns
kubectl get cm -n kube-system coredns -oyaml > coredns-configmap.yaml
kubectl get deploy -n kube-system coredns -oyaml > coredns-deployment-controllers.yaml
kubectl get clusterrole system:coredns -oyaml > coredns-clusterrole.yaml
kubectl get clusterrolebinding system:coredns -oyaml > coredns-clusterrolebinding.yaml
上述步骤说明:
- 创建用于存放coredns 旧版本(即当前在运行的版本)备份目录并进入
- 导出coredns 的configmap 文件
- 导出coredns 的deployment控制器文件
- 导出coredns 的clusterrole. (ClusterRole是一组权限的集合,但与Role不同的是,ClusterRole可以在包括所有NameSpce和集群级别的资源或非资源类型进行鉴权。可以理解为:k8s rabac鉴权)
- 导出coredns 的clusterrolebinding (rolebinding 是用来把一个角色绑定到一个目标对象上可以理解为:k8s rabac授权)
下载最新coredns 组件
git clone https://github.com/coredns/deployment.git
升级coredns 组件
cd deployment/kubernetes/
./deploy.sh -s | kubectl apply -f -
执行结果如下
[root@k8s-master kubernetes]# ./deploy.sh -s | kubectl apply -f -
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
serviceaccount/coredns configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
clusterrole.rbac.authorization.k8s.io/system:coredns configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
clusterrolebinding.rbac.authorization.k8s.io/system:coredns configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
configmap/coredns configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
deployment.apps/coredns configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
service/kube-dns configured
[root@k8s-master kubernetes]#
检查升级结果
[root@k8s-master kubernetes]# kubectl -n kube-system get pod coredns-65d4dbcc75-hcvdc -o yaml |grep image
f:image: {}
f:imagePullPolicy: {}
image: coredns/coredns:1.9.1
imagePullPolicy: IfNotPresent
image: coredns/coredns:1.9.1
imageID: docker-pullable://coredns/coredns@sha256:d5a7db9ab4cb3efc22a08707385c54c328db3df32841d6c4a8ae78f102f1f49a
[root@k8s-master kubernetes]#