kubectl 命令行工具版本低于kubernetes版本导致操作异常问题记录

- 云计算

kubectl 管理 kubernetes 集群的时候,明明有权限并且客户端配置正常但是在执行部分命令时报错:Error from server (NotFound): the server could not find the requested resource 。最后排查下来发现是因为 kubectl 客户端版本和 server 版本不匹配导致的。


问题现象

执行部分命令正常

执行获取 ingress 资源列表时正常。

[root@imzcy ~]# kubectl get ingress
NAME         CLASS   HOSTS          ADDRESS        PORTS   AGE
ins01        nginx   zcy.local.cn   192.168.3.14   80      14m
[root@imzcy ~]#

执行部分命令报错

执行查看 ingress 资源详细信息时报错。

[root@imzcy ~]# kubectl describe ingress ins01
Error from server (NotFound): the server could not find the requested resource
[root@imzcy ~]#




可能原因

网上搜了下,一般说可能是权限问题、命名空间不一致、证书过期等等,还有就是可能 kubectl 客户端比 k8s 版本低,也会出现异常。

检查版本果然是,k8s 集群升级了 1.22版本,但是本地 kubectl 客户端没更新。

[root@imzcy ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.4", GitCommit:"c96aede7b5205121079932896c4ad89bb93260af", GitTreeState:"clean", BuildDate:"2020-06-17T11:41:22Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.5-tke.6", GitCommit:"ac739f92ddd42bfc71c25a1df9fb3c74e7470736", GitTreeState:"clean", BuildDate:"2022-11-03T07:44:04Z", GoVersion:"go1.16.14", Compiler:"gc", Platform:"linux/amd64"}
[root@imzcy ~]#




使用和server一样的client版本

更新kubectl后再次查看版本信息,可以看到客户端和服务端版本都为 1.22.5 了。

[root@imzcy ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.5-tke.6", GitCommit:"ac739f92ddd42bfc71c25a1df9fb3c74e7470736", GitTreeState:"clean", BuildDate:"2022-11-03T08:13:32Z", GoVersion:"go1.16.14", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.5-tke.6", GitCommit:"ac739f92ddd42bfc71c25a1df9fb3c74e7470736", GitTreeState:"clean", BuildDate:"2022-11-03T07:44:04Z", GoVersion:"go1.16.14", Compiler:"gc", Platform:"linux/amd64"}
[root@imzcy ~]#

再次执行查看 ingress 资源详细信息命令,正常获取到了。

[root@imzcy ~]# kubectl describe ingress ins01
Name:             ins01
Namespace:        default
Address:          192.168.3.14
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host          Path  Backends
  ----          ----  --------
  zcy.local.cn
                /   svc-nginx:80 (192.168.2.116:80)
Annotations:    <none>
Events:
  Type    Reason  Age                From                      Message
  ----    ------  ----               ----                      -------
  Normal  Sync    21m (x2 over 22m)  nginx-ingress-controller  Scheduled for sync
[root@imzcy ~]#