问题描述

使用CentOS7的 yum 包管理器安装了 Kubernetes 集群,使用 kubectl 创建服务成功后,执行 kubectl get pods,发现AGE虽然在不断增加,但状态始终不变

本文内容

  • 分析问题原因
  • 给出直接解决此问题的方式 (不完美)
  • 给出其他方案

且听我娓娓道来~

问题分析与解决

kubectl 提供了 describe 子命令来输出指定的一个/多个资源的详细信息。

执行 kubectl describe pod mytomcat-9lcq5,查看问题 Pod 的状态信息,输出如下:

  1. [root@kube-master app]# kubectl describe pod mytomcat-9lcq5
  2. Name: mytomcat-9lcq5
  3. Namespace: default
  4. Node: kube-node-2/192.168.87.145
  5. Start Time: Fri, 17 Apr 2020 15:53:50 +0800
  6. Labels: app=mytomcat
  7. Status: Pending
  8. IP:
  9. Controllers: ReplicationController/mytomcat
  10. Containers:
  11. mytomcat:
  12. Container ID:
  13. Image: tomcat:9-jre8-alpine
  14. Image ID:
  15. Port: 8080/TCP
  16. State: Waiting
  17. Reason: ContainerCreating
  18. Ready: False
  19. Restart Count: 0
  20. Volume Mounts: <none>
  21. Environment Variables: <none>
  22. Conditions:
  23. Type Status
  24. Initialized True
  25. Ready False
  26. PodScheduled True
  27. No volumes.
  28. QoS Class: BestEffort
  29. Tolerations: <none>
  30. Events:
  31. FirstSeen LastSeen Count From SubObjectPath Type Reason Message
  32. --------- -------- ----- ---- ------------- -------- ------ -------
  33. 5m 5m 1 {default-scheduler } Normal Scheduled Successfully assigned mytomcat-9lcq5 to kube-node-2
  34. 4m 4m 1 {kubelet kube-node-2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (Get https://registry.access.redhat.com/v1/_ping: net/http: TLS handshake timeout)"
  35. 3m 3m 1 {kubelet kube-node-2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (Network timed out while trying to connect to https://registry.access.redhat.com/v1/repositories/rhel7/pod-infrastructure/images. You may want to check your internet connection or if you are behind a proxy.)"
  36. 2m 2m 1 {kubelet kube-node-2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (Error: image rhel7/pod-infrastructure:latest not found)"
  37. 3m 1m 3 {kubelet kube-node-2} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""

通过查看最下方的输出信息,Successfully assigned mytomcat-9lcq5 to kube-node-2 说明这个 Pod 分配到 kube-node-2 这个主机上了,然后在这个主机上创建 Pod 失败,

原因是 image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.

通过以上信息,我们了解到通过红帽自家的 docker 仓库 pull 镜像,需要使用 CA 证书进行认证,才能 pull 成功

docker的证书在 /etc/docker/certs.d 目录下,根据上边的错误提示域名是 registry.access.redhat.com,证书在这个目录中

经过 ll 命令查看,发现 /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt 是一个软链接(软链接是什么?),指向到 /etc/rhsm/ca/redhat-uep.pem

熟悉软连接的我们知道,处于红色闪烁状态的目标是不存在,需要生成 /etc/rhsm/ca/redhat-uep.pem 证书文件

生成证书:

  1. # openssl s_client -showcerts -servername registry.access.redhat.com -connect registry.access.redhat.com:443 </dev/null 2>/dev/null | openssl x509 -text > /etc/rhsm/ca/redhat-uep.pem

生成证书命令执行有时会出现 unable to load certificate 139930742028176:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:707:Expecting: TRUSTED CERTIFICATE 问题,重新执行就好

命令执行完毕后,查看软链接指向的证书文件:

  1. [root@kube-node-2 registry.access.redhat.com]# ll /etc/rhsm/ca/redhat-uep.pem
  2. -rw-r--r-- 1 root root 9233 Apr 17 16:55 /etc/rhsm/ca/redhat-uep.pem

证书文件已经存在,我们去 k8s 管理节点 kube-master 主机删除刚才的 Pods,等待 Pod 重新创建成功 (第二个节点因为网络问题没有拉成功镜像……)

至此完成 Pod 的创建

但是还有存在些问题的,当前国内网络环境访问外边的网络偶尔会有问题,导致创建 Pod 失败,通过 describe 描述还是同样的信息提示,但是查看证书文件却存在且有内容

原因分析与其他方案

k8s 管理节点分配创建 Pod 到执行节点,到达执行节点后,拉取红帽 docker 仓库的 Pod基础镜像 pod-infrastructure:latest,由于其仓库使用 https 需要验证证书,证书不存在导致失败

另外就是因为拉取的镜像是红帽 docker 仓库中的,在国内网络环境下握手失败,无法下载镜像

所以问题就成了 如何解决 k8s pod-infrastructure 镜像拉取失败,这里给出一个方案,步骤如下:

  • 拉取 docker 官方仓库其他人上传的 pod-infrastructure 镜像,docker pull tianyebj/pod-infrastructure

  • 添加tag标签,改为私有仓库地址,如:docker tag tianyebj/pod-infrastructure 10.2.7.70:5000/dev/pod-infrastructure

  • push镜像到私有仓库,如:docker push 10.2.7.70:5000/dev/pod-infrastructure

  • 修改所有 worker 节点的 /etc/kubernetes/kubelet,修改 registry.access.redhat.com/rhel7/pod-infrastructure 为刚才设置的 tag 标签

    1. sed -i "s#registry.access.redhat.com/rhel7/pod-infrastructure#<私有仓库pod-infrastructure镜像tag>#" /etc/kubernetes/kubelet

  • 重启所有 worker 节点的 kubelet,systemctl restart kubelet,即可

注意事项:

  • 上传的镜像要设为公开镜像,否则 kubelet 自己没权限拉镜像的,另外也可以去 ssh 登录 worker 节点登录仓库,执行docker pull <私有仓库pod-infrastructure镜像tag>

最后的效果:

参考

https://github.com/CentOS/sig-atomic-buildscripts/issues/329

https://cloud.tencent.com/developer/article/1156329

本文采用 CC BY 4.0 协议进行授权,转载请标注作者署名及来源。

https://www.cnblogs.com/hellxz/p/k8s-pod-always-container-creating-status-problem.html

CentOS 7 yum安装 k8s 创建Pod一直处于ContainerCreating状态 问题解决的更多相关文章

  1. 使用k8s创建容器一直处于ContainerCreating状态

    容器报错信息为(两种): FailedSynError syncing pod, skipping: failed to {kubelet 127.0.0.1} Warning FailedSync ...

  2. 使用kubernetes创建容器一直处于ContainerCreating状态的原因查找与解决

    运行容器的时候,发现一直处于ContainerCreating状态,悲了个催,刚入手就遇到了点麻烦,下面来讲讲如何查找问题及解决的 运行容器命令: [root@master- ~]# kubectl ...

  3. k8s删除pod一直处于terminating状态

    我这里的pod是与nfs有关,nfs挂载有问题导致pod有问题,执行完删除命令以后看到pod一直处于terminating的状态. 这种情况下可以使用强制删除命令: kubectl delete po ...

  4. yum安装k8s集群

    k8s的安装有多种方式,如yum安装,kubeadm安装,二进制安装等.本文是入门系列,只是为了快速了解k8s的原理和工作过程,对k8s有一个快速的了解,这里直接采用yum安装 的1.5.2为案例进行 ...

  5. centOS下yum安装配置samba

     centOS下yum安装配置samba 2010-03-29 15:46:00 标签:samba yum centOS 安装 休闲 注意:本文的原则是只将文件共享应用于内网服务器,并让将要被共享的目 ...

  6. Linux Centos 使用 yum 安装java

    centos 使用 yum 安装java 首先,在你的服务器上运行一下更新. yum update 然后,在您的系统上搜索,任何版本的已安装的JDK组件. rpm -qa | grep -E '^op ...

  7. kubernetes创建yaml,pod服务一直处于 ContainerCreating状态的原因查找与解决

    最近刚刚入手研究kubernetes,运行容器的时候,发现一直处于ContainerCreating状态,悲了个催,刚入手就遇到了点麻烦,下面来讲讲如何查找问题及解决的 运行容器命令: kubectl ...

  8. [转载]centos下yum安装samba及配置

    centos下yum安装samba及配置 在我们使用 Windows 作为客户机的时候,通常有文件.打印共享的需求.作为Windows 网络功能之一,通常可以在 Windows 客户机之间通过Wind ...

  9. centos'的yum安装php的memcache扩展

    centos'的yum安装php的memcache扩展 博客分类: linux   让php能使用memcached服务的扩展有两种:memcache 和 memcached 1. 先安装libmem ...

随机推荐

  1. pytorch RNN层api的几个参数说明

    classtorch.nn.RNN(*args, **kwargs) input_size – The number of expected features in the input x hidde ...

  2. 使用vue构建一个可视化大数据平台

    使用vue全家桶以及v-charts和datav实现一个github可视化大数据界面展示,没有设计搞的原因,只能忽略设计编写一下界面, 用户只需要登录的时候填写自己github用户名.就可以看到数据展 ...

  3. BeanShell调用自己写的jar包进行MD5加密

    1.在eclipse中新建一个java工程,工程名随意. 2.在工程中添加一个package,package名为md5,在package下添加一个class,class名为mymd5. package ...

  4. org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout 和 RocketmqRemoting closeChannel: close the connection to remote address[] result: true

    org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout ...

  5. AspNetCore3.1_Secutiry源码解析_8_Authorization_授权框架

    目录 AspNetCore3.1_Secutiry源码解析_1_目录 AspNetCore3.1_Secutiry源码解析_2_Authentication_核心流程 AspNetCore3.1_Se ...

  6. .NET的资源并不限于.resx文件(二)

    ResourceManager在默认的情况下只能提供对内嵌于程序集的.resources资源文件的存取. 为了实现对独立二进制.resources资源文件的支持,我们自定义了BinaryResoruc ...

  7. 目标检测 | RetinaNet:Focal Loss for Dense Object Detection

    论文分析了one-stage网络训练存在的类别不平衡问题,提出能根据loss大小自动调节权重的focal loss,使得模型的训练更专注于困难样本.同时,基于FPN设计了RetinaNet,在精度和速 ...

  8. 扫描工具-Arachni

    ./arachni_console          #进入命令行模式 ./arachni_web               #启用web服务,进入web操作模式 [属于web 应用] http:/ ...

  9. 题解 P1278 【单词游戏】

    前言 首先,看到这道题目,我首先想到的是暴搜,通过\(vector\)来搞,代码也是很短的. 这里用了一个类似于分治的思想 把一个大问题转化为小问题 先枚举第一个单词,之后把能拼接在它后面的单词都一个 ...

  10. nop 配置阿里cdn 联通4g 页面显示不全 查看源代码发现被截断

    开发中遇见特别诡异的问题, 项目使用nop框架,pavilion主题,之后配置阿里cdn,然后在联通4g的情况下苹果手机网页显示不完全,nop首页和产品详情页都是如此,排查过程: 1.阿里cdn设置了 ...