解决方法:
1、$ vi /etc/kubernetes/apiserver
2、找到这一行
"KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota",去掉ServiceAccount,保存退出。
3、重新启动kube-apiserver服务即可
   systemctl restart kube-apiserver
4、# 执行 显示正常
   kubectl get pods

此时执行kubectl get pods, no resources found问题得以解决

 

问题描述

通过kubectl describe pod可以查看报错:

Error:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
link failure The last packet sent successfully to the server was 0 milliseconds
ago. The driver has not received any packets from the server.
相关资源rc、pod、service、ep都创建成功,但是myweb的pods无法访问到mysql提供的数据库服务。

# kubectl get all
NAME       DESIRED   CURRENT   READY     AGE
rc/mysql   1         1         1         4h
rc/myweb   1         1         1         2h

NAME             CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
svc/kubernetes   10.254.0.1      <none>        443/TCP          5d
svc/mysql        10.254.67.31    <none>        3306/TCP         4h
svc/myweb        10.254.62.177   <nodes>       8080:30001/TCP   2h

NAME             READY     STATUS    RESTARTS   AGE
po/mysql-vc9x6   1/1       Running   0          4h
po/myweb-6k7s3   1/1       Running   0          2h
# kubectl get ep
NAME         ENDPOINTS            AGE
kubernetes   192.168.1.171:6443   5d
mysql        172.17.0.4:3306      4h
myweb        172.17.0.2:8080      2h

分析

查看源代码
既然无法建立连接,那先看下是如何建立连接的。登录到myweb的docker容器里面,查看index.jsp文件,主要内容如下:
java.sql.Connection conn=null; java.lang.String strConn; java.sql.Statement
stmt=null; java.sql.ResultSet rs=null;
Class.forName("com.mysql.jdbc.Driver").newInstance(); try{
Class.forName("com.mysql.jdbc.Driver"); String
ip=System.getenv("MYSQL_SERVICE_HOST"); String
port=System.getenv("MYSQL_SERVICE_PORT"); ip=(ip==null)?"localhost":ip;
port=(port==null)?"3306":port; System.out.println("Connecting to database...");
System.out.println("jdbc:mysql://"+ip+":"+port+"?useUnicode=true&characterEncoding=UTF-8");
conn =
java.sql.DriverManager.getConnection("jdbc:mysql://"+ip+":"+port+"?useUnicode=true&characterEncoding=UTF-8",
"root","123456"); stmt = conn.createStatement(); }catch(Exception ex){ ... }
* 就是用jsp创建了一个连接,连接的地址通过ENV方式注入。即在myweb-rc.yaml中配置的MYSQL_SERVICE_HOST和
MYSQL_SERVICE_PORT环境变量指定。
登陆myweb应用查看这两个环境变量是否有问题: [root@localhost ~]# kubectl exec -ti myweb-cp4gm --
/bin/bash root@myweb-cp4gm:/usr/local/tomcat# echo $MYSQL_SERVICE_HOST
10.254.15.45 root@myweb-cp4gm:/usr/local/tomcat# echo $MYSQL_SERVICE_PORT 3306
可以看出环境变量也是没有问题的。

<>解决方法

考虑到可能是mysql版本的问题,修改mysql版本为5.7,并且设置来直接使用本地镜像。
apiVersion : v1 kind : ReplicationController metadata : name : mysql spec :
replicas : 1 selector : app : mysql template : metadata : labels : app : mysql
spec : containers : - name : mysql image : mysql:5.7 imagePullPolicy:
IfNotPresent ports : - containerPort : 3306 env : - name : MYSQL_ROOT_PASSWORD
value : "123456"

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信