一、问题背景

  1. 当前Cluster K8s Version: v1.17.4
  2. 需要升级到K8s Version:v1.19.3
  3. 在升级过程中,有个Pod卡在ContainerCreating状态
api-9flnb                             0/1     ContainerCreating   0          4d19h
api-bb8th 1/1 Running 0 4d20h
api-zwtpp 1/1 Running 0 4d20h

二、问题分析

  1. Describe该Pod状态,提示hostPath type check failed: /var/run/docker.sock is not a file

    Events:
    Type Reason Age From Message
    ---- ------ ---- ---- -------
    Warning FailedMount 11m (x3543 over 4d18h) kubelet (combined from similar events): Unable to attach or mount volumes: unmounted volumes=[docker-socket], unattached volumes=[xxxx-service-account-token-rjqz7 nginx-certs host-timezone docker-socket helm-home etc-pki kubernetes-root-ca-file root-ca-file bcmt-home etcd-client-certs]: timed out waiting for the condition
    Warning FailedMount 2m39s (x2889 over 4d19h) kubelet MountVolume.SetUp failed for volume "docker-socket" : hostPath type check failed: /var/run/docker.sock is not a file
  2. 查看该Pod中volume "docker-socket"的声明,Path是/var/run/docker.sock,HostPathType是File
    Volumes:
    etcd-client-certs:
    Type: Secret (a volume populated by a Secret)
    SecretName: etcd-client-certs
    Optional: false
    nginx-certs:
    Type: HostPath (bare host directory volume)
    Path: /opt/bcmt/config/bcmt-api/certs
    HostPathType: Directory
    docker-socket:
    Type: HostPath (bare host directory volume)
    Path: /var/run/docker.sock
    HostPathType: File
  3. 查看K8s从v1.17.4到v1.19.3关于Type检测方面的相关代码变化

首先,报错的代码函数是checkTypeInternal(),在文件host_path.go定义,会判断HostPathType和实际Type是否一致,否则报错。

func checkTypeInternal(ftc hostPathTypeChecker, pathType *v1.HostPathType) error {
switch *pathType {
case v1.HostPathDirectoryOrCreate:
if !ftc.Exists() {
return ftc.MakeDir()
}
fallthrough
case v1.HostPathDirectory:
if !ftc.IsDir() {
return fmt.Errorf("hostPath type check failed: %s is not a directory", ftc.GetPath())
}
case v1.HostPathFileOrCreate:
if !ftc.Exists() {
return ftc.MakeFile()
}
fallthrough
case v1.HostPathFile:
if !ftc.IsFile() {
return fmt.Errorf("hostPath type check failed: %s is not a file", ftc.GetPath())
}
case v1.HostPathSocket:
if !ftc.IsSocket() {
return fmt.Errorf("hostPath type check failed: %s is not a socket file", ftc.GetPath())
}
case v1.HostPathCharDev:
if !ftc.IsChar() {
return fmt.Errorf("hostPath type check failed: %s is not a character device", ftc.GetPath())
}
case v1.HostPathBlockDev:
if !ftc.IsBlock() {
return fmt.Errorf("hostPath type check failed: %s is not a block device", ftc.GetPath())
}
default:
return fmt.Errorf("%s is an invalid volume type", *pathType)
} return nil
}

然后,结合我们pod的定义,HostPathType是File,但是实际Path文件/var/run/docker.sock应该是Socket,所以报错是正确的。疑问在于,为什么v1.17.4没有报错(亲测v1.18.x也不会报错),而到了v1.19.3才开始报错???

  • 检查checkTypeInternal函数代码有无改动,---> 结果是无改动
  • 检查入参hostPathTypeChecker传值是否有改动, --->发现有改动
    • v1.17.x和v1.18.x中,IsFile()定义如下
  • func (ftc *fileTypeChecker) IsFile() bool {
    if !ftc.Exists() {
    return false
    }
    return !ftc.IsDir()
    }
     
  • v1.19.x开始,IsFile()更新如下
func (ftc *fileTypeChecker) IsFile() bool {
if !ftc.Exists() {
return false
}
pathType, err := ftc.hu.GetFileType(ftc.path)
if err != nil {
return false
}
return string(pathType) == string(v1.HostPathFile)
}

三、问题结论

  1. K8s从v1.19.x修复了IsFile()函数检测功能不完备的Bug;
  2. 我们的Pod Mount Volume 文件.sock时指定HostPathType错误(应该是Socket, 不应该是File),但是在v1.19.x之前因为k8s的bug正好将错就错反而没有问题,等v1.19.x修复了该Bug就会出现Volume Mount失败的问题

四、解决方案:.sock文件的HostPathType要设置成Socket

Volumes:
docker-socket:
Type: HostPath (bare host directory volume)
Path: /var/run/docker.sock
HostPathType: Socket

k8s升级导致hostPath type check failed的更多相关文章

  1. Vue报错之"[Vue warn]: Invalid prop: type check failed for prop "jingzinum". Expected Number with value NaN, got String with value "fuNum"."

    一.报错截图 [Vue warn]: Invalid prop: type check failed for prop "jingzinum". Expected Number w ...

  2. Invalid prop: type check failed for prop "XXX". Expected String, got Object.

    项目是Vue的,基于elementUI的后台管理系统. Invalid prop: type check failed for prop "total". Expected Str ...

  3. vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte

    报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...

  4. vue type check failed for prop . Expected Number, got String

    代码是:fileNumLimit接收的类型是Number <vue-upload fileNumLimit='100'/> 改为 <vue-upload :fileNumLimit= ...

  5. Invalid prop: type check failed for prop "maxlength". Expected Number, got String.

    1.项目中,使用element-ui的input表单的maxlength属性报错 2.使用场景:       <el-input v-model="fname"  maxle ...

  6. vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". Expected String with value "0", got Number with value 0.

    vue.esm.js?efeb:628 [Vue warn]: Invalid prop: type check failed for prop "defaultActive". ...

  7. Vue报错 type check failed for prop “xxx“. Expected String with value “xx“,got Number with value ‘xx‘

    vue报错    [Vue warn]: Invalid prop: type check failed for prop "name". Expected String with ...

  8. Invalid prop: type check failed for prop "maxlength"

    Invalid prop: type check failed for prop "maxlength", element 框架时,因为想限制文本框的输入长度, maxlength ...

  9. [Vue warn]: Invalid prop: type check failed for prop "model". Expected Object, got String with value ""

    问题描述: [Vue warn]: Invalid prop: type check failed for prop "model". Expected Object, got S ...

  10. [VUE ERROR] Invalid prop: type check failed for prop "list". Expected Array, got Undefined

    错误原因: 子组件 props -> list 要求接收的数据类型是 Array, 然而实际接收到的是 Undefined. 子组件代码: props: { list: { type: Arra ...

随机推荐

  1. [超详细] [效能工具]Typora+PicGo+Github免费图床快速搭建,提升技术文档输出效率

    一.前言 在我们日常的学习和工作中,我们经常需要进行写作.尤其对于我们程序技术人员而言,工作中的技术方案文档或者接口文档等,都是经常需要用上的. 那么如果没有一个高效的工具,去帮助我们记录和创作,这将 ...

  2. centos7.6安装本地yum源

    centos7.6安装本地yum源 前言:文章内容可能会因环境不同而有所差异,所谓集思广益说不定灵感就来了呢; 文章初衷旨在交流学习.记录个人成长,如果能帮助到您,那就点个赞噢. 环境说明: 1.本实 ...

  3. 解决xcode每次编译都需要输入用户名和密码

    MacOS:11.1 Xcode:12.3 一.打开你的 钥匙串, 如果不知道  打开你的 spotlight搜索 工具 ,输入"钥匙串" 二.登录--->iPhone de ...

  4. 打包iOS App并上架到TestFlight测试

    开发者账号 首先需要注册一个开发者账号,不然什么都免谈.在手机Apple Developer上注册给钱就行了,个人开发者一年688元. 打包App App开发好后,就可以通过XCode打包.打包前选好 ...

  5. antd 3.x升4.x踩坑之路~

    我们是袋鼠云数栈 UED 团队,致力于打造优秀的一站式数据中台产品.我们始终保持工匠精神,探索前端道路,为社区积累并传播经验价值. 兼容性问题 第三方依赖兼容问题 React - 最低 v16.9,部 ...

  6. 【分析笔记】Linux 内核自旋锁的理解和使用原则

    自旋锁简单说明: 自旋锁主要解决在竞态并发下,保护执行时间很短的临界区.它只允许一个执行单位进入临界区,在该执行单位离开前,其它的执行单位将会在进入临界区前不停的循环等待(即所谓的自旋),直至该执行单 ...

  7. vue学习笔记(八)---- vue中的实例属性(wacth和computed的使用)

    一.watch属性的使用 1.传统方式实现双向数据改变监听事件(姓名拼接案例) <div id="app"> 姓: <input type="text& ...

  8. HOMER docker版本安装详细流程

    概述 HOMER是一款100%开源的针对SIP/VOIP/RTC的抓包工具和监控工具. HOMER是一款强大的.运营商级.可扩展的数据包和事件捕获系统,是基于HEP/EEP协议的VoIP/RTC监控应 ...

  9. Bootstrap的Modal与WebUploader联用的问题及办法

    问题描述:在使用Bootstrap的Modal的时候,在Modal中用了WebUploader插件,然后WebUploader的绑定按钮无法点击 在网上找了一些结果,觉得,他们的问题解决方案感觉都不够 ...

  10. Adobe GENP2019~2022 for Win 一键激活

    Adobe GENP2019~2022 for Win 一键激活 一.简介 GenP是一个由国外团队开发的Adobe Win全系列软件激活工具,专门在Win系统上激活所有Adobe软件的2019和20 ...