「Python」- module object is not callable

内容简介
处理TypeError: ‘module’ object is not callable错误。
问题描述
运行脚本产生TypeError: ‘module’ object is not callable错误。
问题原因
没有区分清除“模块名”与“类名”。模块名是模块名,类名是类名,二者是有所区别的。
在import时,导入的是类名,而不是模块名,应该是import <module_name>.<class_name>或者from <module_name> import <class_name>的形式,而单独引入模块(import <module_name>)是不可以的,模块不可以调用。
解决办法
修改导入语句,引入类名。
参考文献
TypeError: ‘module’ object is not callable[……]

READ MORE

「PyPy」- No module named xxx

内容简介
处理ImportError: No module named xxx错误。
问题描述
执行pypy wxwork-notify.py时产生如下错误:

Traceback (most recent call last):
File “wxwork-notify.py”, line 7, in <module>
import simplejson
ImportError: No module named simplejson

系统环境

操作系统:
Kali GNU/Linux Rolling

问题原因
在Python中,出现类似问题通常是由于模块没有安装,那解决该问题的方法就是安装对应的模块。
但是,我遇到的问题并不是模块未未安装。因为运行python wxwork-notify.py命令是正常的,只有使用pypy时是错误的。
之所以出现该问题,是因为有些东西我不清楚,没有了解到。在PyPy中,它有自己的site-packages路径,因此需要为PyPy单独安装模块,或者单独安装pip命令来安装其他模块。
解决办法

#!/bin/sh

apt-get install pypy-setuptools

参考文献
PyPy: “ImportError: No module named xlrd”[……]

READ MORE

「jq」-

功能简述
命令行中的 JSON 处理器
常用命令
输出多个字段(使用自定义格式):

echo ‘<JOSN STRING>’ | jq ‘.item[] | .f1 + ” ” + .tags[].f2’

输出多个字段(使用 TSV 格式):

echo ‘<JOSN STRING>’ | jq ‘.item[] | [.f1, .tags[].f2] | @tsv’ # 制表符分隔

对字段名中的进行转义处理:

echo ‘<JOSN STRING>’ | jq ‘.item[] | .data.[“tls.crt”]’

语法格式

jq [options…] filter [files…]

命令描述
jq can transform JSON in various ways, by selecting, iterating, reducing and otherwise mangling JSON documents. For instance, running the command jq ´map(.price) | add´ will take an array of JSON objects as input and return the sum of their “price” fields.
jq can accept text input as well, but by default, jq reads a stream of JSON entities (including numbers and other literals) from stdin. Whitespace is only needed to separate entities such as 1 and 2, and true and false. One or more files may be specified, in which case jq will read input from those instead.
The options are described in the INVOKING JQ section; they mostly concern input and output formatting. The filter is written in the jq language and specifies how to transform the input file or document.
命令选项
jq filters run on a s[……]

READ MORE

「Virtualization and Emulator」

计算机虚拟化技术属于计算机科学专业,具体来说,属于计算机体系结构或操作系统等相关专业方向。虚拟化技术是计算机科学领域中的一种技术,它涉及到计算机硬件、操作系统和应用程序等多个方面的知识,需要对计算机系统的整体架构和工作原理有深入的理解。因此,学习虚拟化技术需要具备计算机科学相关的知识背景和技能。
相关链接
Wikipedia/Hypervisor
Docker学习总结之Docker与Vagrant之间的特点比较
Hypervisor
Hypervisor:是一种运行在物理服务器和虚拟机操作系统之间的中间软件层,可允许多个操作系统和应用共享一套基础物理硬件。因此也可以看作是虚拟环境中的“元”操作系统,它可以协调访问服务器上的所有物理设备和虚拟机,也叫虚拟机监视器(Virtual Machine Monitor VMM)。Hypervisor是所有虚拟化技术的核心。目前主流的Hypervisor有KVM,VMWare ESXi,Xen,HyperV等。 HyperV
Xen and Xen Server
VPC – Virtual Private Cloud
Vagrant https://www.vagrantup.com/ 一个基于Ruby的工具,用于创建和部署虚拟化开发环境。它使用Oracle的开源VirtualBox虚拟化系统。
MONO 在Ubuntu操作系统上安装mono的具体方法 https://www.linuxdot.net/bbsfile-3090
参考文献
oVirt和OpenStack的区别[……]

READ MORE

「Windows」- Subsystem for Linux,WSL

问题描述
WSL:在 Windows 中,使用 GNU Linux 工具的方法。
该笔记将记录:在 Windows 中,如何使用 WSL 模块,以及相关问题的解决方法。
注意事项
# 09/13/2021
我们需要在笔记本中运行 VirtualBox 5.2 版本,但是 VirtualBox 与 Hyper-V 不能共存: 1)如果开启 Hyper-V 模块,那么 VirtualBox 将提示 VT-x is not available 错误; 2)如果关闭 Hyper-V 模块,那么 WLS 2 将提示 The specified network name is no longer available 错误;
鉴于 VirtualBox 能够将 主机文件系统挂在到 虚拟机中,所以能够在 Linux 环境下进行操作。这能够满足我们的需求,所以我们放弃使用 WSL 2 特性。
安装 WSL 模块
参考 Windows Subsystem for Linux Installation Guide for Windows 10 文档。
安装步骤: 1)在 Control Panel ⇒ Programs ⇒ Turn Windows features on or off 中, 2)启用 Windows Subsystem for Linux 选项,并重启主机; 3)在 Microsoft Store 中,搜索并安装 Ubuntu 20.04 TLS 发行版;
在安装完成后,Windows Terminal 能够快速进入 Ubuntu 20.04 中(如果需要设置,参考 Install and set up Windows Terminal 文档)
常用操作
查看当前 WSL 运行版本
WSL: Am I running version 1 or version 2?

# wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 1

挂载新磁盘
How to Mount Windows Network Drives in WSL
当主机插入 U 盘或者其他磁盘设备后,需要挂载到 WSL 中:

mount -t drvfs M: /mnt/m

常见问题处理
The specified network name is no longer available.(指定的网络名不再可用)
WSL 2 FAQs
原因分析,正如 Microsoft 官方 FAQ 所说:

Will I be able to[……]

READ MORE

「Windows Virtual PC and XP Mode」

Windows Virtual PC
引自百度百科对 Windows Virtual PC 的介绍:

Windows Virtual PC 是 Microsoft 最新的虚拟化技术。借助 Windows Virtual PC,您单击一次即可直接从基于 Windows 7 的计算机在虚拟的 Windows 环境中运行许多生产应用程序。

是不是“最新的虚拟化技术”,咱不知道。反正运行 XP Mode 需要安装该工具。
第一步、安装 Windows Virtual PC 工具
访问官网下载 Windows Virtual PC 工具。
第二步、安装 XP Mode 工具
访问官网下载 Windows XP Mode 工具。
第三步、启动并设置 XP Mode 工具
Start => Windows Virtual PC => Windows XP Mode
参考文献
百度百科/Windows Virtual PC How to install and use Windows XP Mode in Windows 7[……]

READ MORE

「Wine」- Windows Emulator But Not An Emulator

使用 Wine,能够在 Unix-like 中运行 Windows 程序。
https://wiki.winehq.org/Gecko https://wiki.winehq.org/Mono https://wiki.winehq.org/Winetricks https://www.winehq.org/
相关站点
主页:https://www.winehq.org 维基百科中有关Wine的介绍[……]

READ MORE

「Linux下」- 安装 Wine 服务

解决方案
从仓库中直接安装

# Kali GNU/Linux Rolling
apt-get install wine wine64 libwine:amd64 fonts-wine winexe

安装的可执行程序
wine
/usr/bin wine-stable msiexec-stable regedit-stable regsvr32-stablels
wineboot-stable winecfg-stable wineconsole-stable winedbg-stable winefile-stable winepath-stable wineserver-stable
wine64
wine64-stable
winexe
winexe[……]

READ MORE

「Wine」- Play On Linux

PlayOnLinux是Wine的前端工具。以一种简单的方式安装Windows中的软件。软件截图如下:
安装「Play On Linux」
从Linux发行版的源中安装

apt-get install playonlinux

直接下载软件包
从官网下载Play On Linux

PlayOnLinux是Python写的,所以必须先安装Python。
下载Play On Linux: https://www.playonlinux.com/en/download.html
运行:/path/to/package/playonlinux

从GitHub下载Play On Linux PlayOnLinux是Python写的,所以必须先安装Python。 项目地址: https://github.com/PlayOnLinux/POL-POM-4 运行程序:/path/to/package/playonlinux
安装的可执行程序
playonlinux Wine的前端程序。提供了一种简单的方式来安装和使用Windows中的软件。
playonlinux-pgk 管理playonlinux包的工具。
常见错误列表
#1 PlayOnLinux is not supposed to be run as root. Sorry
PlayOnLinux是不允许以ROOT运行的,在程序中执行用户检查。不过,还好Play On Linux是Python开发的,所以可以修改脚本文件,移除ROOT检查。一共有两处需要修改:
1)修改/usr/share/playonlinux/python/mainwindow.py文件,注释以下行:

if(os.popen(“id -u”).read() == “0\n” or os.popen(“id -u”).read() == “0”):
wx.MessageBox(_(“{0} is not supposed to be run as root. Sorry”).format(os.environ[“APPLICATION_TITLE”]),_(“Error”))
os._exit(1)

2)修改/usr/share/playonlinux/lib/sources文件,注释以下行:

if [ “$(id -u)” = “0” ]
then
echo “PlayOnLinux is not supposed to be run as root. Sorry”
exit
fi

参考文献
PlayOnLinux的官网[……]

READ MORE

「Wine」- 常见问题处理

系统图盘(Systemtray)
How to Hide Wine System Tray – ibndias
默认会自动启动 Wine System Tray 悬浮窗口。
如果想要合并到 GNOME 桌面环境的系统托盘中,需要安装 TopIcons 插件: TopIcons – GNOME Shell Extensions TopIconsFix – GNOME Shell Extensions
配置字体抗锯齿、解决字体模糊
How do I enable font anti-aliasing in Wine?
2018-04-09 PM 03:46
The easiest way is through winetricks

mkdir ~/bin
cd ~/bin
wget http://winetricks.org/winetricks
chmod +x ./winetricks

winetricks fontsmooth-rgb

In newer version of winetricks the command to use is

winetricks settings fontsmooth=rgb

There are other LCD pixel orders available. You can read about them and the rest of the impressive winetricks feature list on its WineHQ site.[……]

READ MORE

「Docker」- 操作系统层的虚拟化

Docker – OS-Level Virtualization, Enterprise Container Platform
基于LXC技术,使用AUFS文件系统。
组件:Server(Docker Engine)、Client/API、Image、Register、Container
Client/API -> Server -> Container
Image:基于联合文件系统的一种层次的结构。说人话就是,组成操作系统目录结构的一些文件,这些文件保证了系统的运行。再简单的说,就是个操作系统,只不过移除了一些不必要的文件。
Register: 用于保存镜像的仓库。公有,私有。公用,供搭建使用,Docker Hub。私有,搭建自己的Register中心。
Container:运行中的镜像。
「镜像」是Docker生命周期中的打包或构建阶段,而「容器」则是启动或执行阶段。
用户界面:shipyard, DockerUI, Kitematic
# 待办事项
TODO ! Docker是如何存储镜像的,以及镜像的大小 「Where are Docker images stored on the host machine?」 「About images, containers, and storage drivers」 「 moby/daemon/graphdriver/driver.go 」 「Docker Image Size – Does It Matter?」
参考文献
绑定Dokcer容器到主机指定网卡的方法 Docker的4种网络模式 Docker Compose安装以及入门 Docker三剑客实践之部署集群 使Docker提供对外服务的网络配置(桥接与端口) docker一个镜像创建多实例启动多个容器分配不同的端口号,达到高可用的目的 单机跑多个container实例,如何让这些实例都能使用同一端口? 不同容器之间端口通信困惑 for docker[……]

READ MORE

「DOCKER-COMPOSE」- 配置与使用

docker-compose教程(安装,使用, 快速入门)
设置 PROJECT NAME 信息
Project name in docker-compose.yml · Issue #1123 · docker/compose Set $PROJECT_NAME in docker-compose file – Stack Overflow Declare default environment variables in file | Docker Documentation
问题描述
在 Docker Compose 中,默认使用当前目录名作为应用名,并前缀到容器目录。
当我将 docker-compose.yml 文件保存在 application/ 中,导致容器被前缀 application 作为项目名。
该笔记将记录:在 Docker Compose 中,如何设置项目名。
解决方法
创建 .env 文件,定义 COMPOSE_PROJECT_NAME 变量,以此指定应用名。[……]

READ MORE

「Docker Compose」- docker-compose.yaml(学习笔记)

官方文档
Compose file version 3 reference | Docker Documentation
模板文件(docker-compose.yaml)
我们常用的 docker-compose.yaml 模板(直接复制):

version: ‘3’

services:
backend:
# 镜像配置
image: <image address>
# 容器配置
container_name: <container name>
# 网络配置
hostname: <hostname>
network_mode: host
ports:
– “<host port>:<container port>”
# 服务管理配置
restart: always
# 运行命令、及其环境信息
volumes:
– /etc/localtime:/etc/localtime
environment:
– <key>=<value>
# 覆盖 ENTRYPOINT 参数
entrypoint: /bin/entrypoint
command: [“ls”, “-l”]

运行命令
docker-compose, run a script after container has started? – Stack Overflow
运行多行命令(多行脚本):

version: ‘3’

services:
backend:

entrypoint:
– sh
– -c
command:
– |
while true
do
// do some stuff
done

环境变量(Environment)
Environment variables in Compose | Docker Documentation docker-compose invalid type, it should be a string – DevOps Stack Exchange
供 Container 使用的环境变量
这里的“环境变量”是指“在运行时传递到容器中的环境变量”,等价于 docker run –env 命令。
使用如下形式定义环境变量(注意 environment 为数组):[……]

READ MORE

「CONTAINERD」- 场景及方案

配置 Registry Mirror 服务
1)How to configure containerd to use a registry mirror? 2)containerd/registry.md at main · containerd/containerd 3)containerd/config.md at main · containerd/containerd 4)containerd/hosts.md at main · containerd/containerd

# vim /etc/containerd/config.toml

[plugins.”io.containerd.grpc.v1.cri”.registry]
config_path = “/etc/containerd/certs.d”

# mkdir -pv /etc/containerd/certs.d
# mkdir -pv /etc/containerd/certs.d/_default/

# vim /etc/containerd/certs.d/_default/hosts.toml
server = “https://docker.io”

[host.”https://registry-1.docker.io”]
capabilities = [“resolve”, “pull”][……]

READ MORE

「Kubernetes」- 企业级容器编排(Production-Grade Container Orchestration)

问题描述
该部分笔记侧重于集群的管理,不涉及使用;
解决方案
研究方法
教育培训:WIP
书籍文献 《Kubernetes: Up and Running: Dive into the Future of Infrastructure》 《Kubernetes Cookbook: Building Cloud Native Applications》 《Kubernetes Cookbook》- O’Reilly Media >> http://shop.oreilly.com/product/0636920064947.do >> https://github.com/k8s-cookbook/recipes 0voice/k8s_awesome_document: 【2021年新鲜出炉】K8s(Kubernetes)的工程师资料合辑,书籍推荐,面试题,精选文章,开源项目,PPT,视频,大厂资料
官方文档
https://kubernetes.io/docs/home 在官方主页中,主要由以下几个部分: HOME – 基本介绍,文档分类,快速入口 GETTING STARTED – 快速开始,集群部署,最佳实践 CONCEPTS – 在集群中的一些基本概念。比如,API 对象,网络,集群组件等等。; TASKS – 执行某些特定任务示例,相当于使用教程; TUTORIALS – 与 TASK 类似,该部分包含使用讲解,更加偏向一些示例; REFERENCE – 对象使用方法,调用 API 的方法。这一部分更加偏向于开发人员; CONTRIBUTE – 文档的共享方法;
博客文章:WIP
代码仓库:https://github.com/kubernetes/kubernetes 访问社区:https://github.com/kubernetes/community 相关示例:http://kubernetesbyexample.com 在线练习:https://katacoda.com/courses/kubernetes/playground[……]

READ MORE

「KUBERNETES-TROUBLESHOOT」- 排错与调试

我们从来没有遇到这种事情:以前不管使用什么系统,即使出现各种运行错误,也很容易处理。但是,现在我们需要建立专门的章节,来学习 Kubernetes 相关的排错与调试内容(也许是我们以前使用的东西太简单了)。而且在 Kubernetes 官方文档中关于排错调试的内容远多余我们用过的其他服务,从来没见过哪个工具服务有这么多排错及调试相关的文档 :-)。不过这也很正常,虽然 Kubernetes 的很多新概念,但是底层的 Docker IPVS iptables PKI Storage 等等技术都是建立在已有技术的基础之上,这么多技术粘合在一起,出现各种错误也是相当正常的。所以 Kubernetes 的使用是件简单的事情,通过阅读官方文档即可,但是维护、排错、调试可不简单;
鉴于此,我们创建该章节,专门用来学习和记录与 Kuberntes 排错及调试相关的内容。比如 Pod 为什么处于 Pending 状态、Pod 为什么会重启、apiserver 为什么会退出、etcd 为什么会突然重新选举……各种各样的问题;
集群使用感悟
# 04/10/2019 难点不在于应用,而在于问题处理;
在应用方面,由于多数东西都存在于官方文档上,在使用方面没有太大难度。通过阅读官方文档,可以顺利进行使用,无非是用的好、用的坏、是否是最佳实践方面的问题;
真正难的地方在于维护及问题处理。要想处理集群发生的问题,尤其是突发问题,就要深入理解系统各组件之间的协作关系。与以往我们使用的程序不同,它更像是一个集成系统。我们以往使用的应用,比如监控、日志等等,架构简单且常规,无非就是服务端、客户端,网络、防火墙、权限之类的技术。但是 Kubernetes 不一样,它是一个集成系统,它将很多东西柔合在一起。基础知识方面,需要掌握容器、IPVS、防火墙、证书。除了基础知识,还有 Kubernetes 内部所使用的一些概念;
随着我写下的这一段内容,我也渐渐意识到这是运维知识体系的变革。传统应用管理及问题处理,基本遵循相同的模式,客户端、服务端,不管怎么弄,都没有跳出这个模式。但是 Kubernetes 不一样,它通过各个组件来操作底层组件(防火墙、路由、存储)。以前又有多少应用程序会去操作防火墙呢?又有哪个应用程序在使用 IPVS 呢?[……]

READ MORE

「Kubernetes」- Event

问题描述
该笔记将记录:在 Kubernetes 中,借助 Event 排查问题的方法,以及相关问题的解决办法。
解决方案
Event 实际上是 Kubernetes Cluster 中的一种资源。当 Kubernetes 集群中资源状态发生变化时,可以产生新的 Event;
对不同的资源对象进行 describe 的时候,能看到的 Event 内容都是与自己有直接关联的。 Event 对象中是包含它所描述的资源对象的信息的;
在 Event.involvedObject 字段中,内容就是与该 Event 相关联的资源对象的信息。 Kubernetes 会自动将重复的 events 进行合并
常用命令

// 获取 Event

kubectl get events –namespace=my-namespace

// 查看 Event

kubectl -n moelove get events redis-687967dbc5-27vmr.16c4fb7bde8c69d2 -o yaml

// 将 Event 排序显示

kubectl -n moelove get events –sort-by='{.metadata.creationTimestamp}’

参考文献
彻底搞懂 Kubernetes 中的 Events | MoeLove[……]

READ MORE

「Kubernetes」- 网络调试(Testing,Troubleshooting)

问题描述
https://kubernetes.io/docs/concepts/cluster-administration/networking/
Networking is a central part of Kubernetes, but it can be challenging to understand exactly how it is expected to work. There are 4 distinct networking problems to address:

Highly-coupled container-to-container communications: this is solved by Pods and localhost communications.
Pod-to-Pod communications: this is the primary focus of this document.
Pod-to-Service communications: this is covered by Services.
External-to-Service communications: this is also covered by Services.
Kubernetes is all about sharing machines between applications. Typically, sharing machines requires ensuring that two applications do not try to use the same ports. Coordinating ports across multiple developers is very difficult to do at scale and exposes users to cluster-level issues outside of their control.

Dynamic port allocation brings a lot of complications to the system – every application has to take ports as flags, the API servers have to know how to insert dynamic port numbers into configuration blocks, services have to know how to find each other, etc.
解决方案
Kubernetes 网络插件是一种扩[……]

READ MORE

「Kubernetes」- 配置 Calico 组件

解决方案
Install Calico networking and network policy for on-premises deployments Troubleshoot and diagnostics/Configure NetworkManager

cat > /etc/NetworkManager/conf.d/calico.conf <<EOF
[keyfile]
unmanaged-devices=interface-name:cali*;interface-name:tunl*;interface-name:vxlan.calico
EOF

参考文献
About Calico About Kubernetes Networking[……]

READ MORE

「Calico」- 常见问题处理

问题描述
该笔记将记录:在 Kubernetes Cluster 中,与 Calico 有关的常用设置,以及相关问题处理。
解决方案
FIXME Kubernetes Calico 在 ARM64 中,经常重启无法成功运行;
calico/node is not ready: BIRD is not ready: BGP not established with 172.21.0.1
Calico readiness and liveliness probe fails · Issue #2042 · projectcalico/calico Configuring calico/node calico/node is not ready: BIRD is not ready: BGP not established (Calico 3.6 / k8s 1.14.1) #2561
问题描述
在集群中的 calico-node 处于 Ready 0/1 状态,并且 Events 显示 calico/node is not ready: BIRD is not ready: BGP not established with 172.21.0.1 消息:

# kubectl get pods -n kube-system -o wide

calico-node-77gbb 0/1 Running 0 25s 172.16.187.21 k8scp-01 <none> <none>
calico-node-p6g6x 0/1 Running 0 25s 172.16.159.15 cita-cloud-staging <none> <none>

# kubectl describe pods -n kube-system calico-node-77gbb

Normal Started 102s kubelet Started container calico-node
Normal Pulled 102s kubelet Container image “docker.io/calico/node:v3.18.1” already present on machine
Normal Created[……]

READ MORE

「Kubernetes」- 使用calico插件时,拉取pause镜像失败

问题描述
在部署Calico网络组件时,它会拉取k8s.gcr.io/pause镜像。
即使初始化时指定私有镜像仓库,它还是会拉取k8s.gcr.io/pause镜像。(可能这与初始化并无关系)
问题原因
该镜像(pause)用于使多个容器运行在壹个POD中。该容器持有POD的网络命令空间,使用该容器获取各自POD的IP地址,并设置加入该POD的其他容器的网络命名空间。
解决办法
使用kubelet的–pod-infra-container-image选项指定pause镜像地址。
在CentOS 7中,可以修改/etc/sysconfig/kubelet配置文件,内容大致如下:

KUBELET_EXTRA_ARGS=”–pod-infra-container-image=’private-registry/foo/pause:<tag>'”

参考文献
bootstrap kubernetes from private registry #76155 What is the use of a pause image in Kubernetes? Kubernetes/REFERENCE/kubelet[……]

READ MORE

「12.Maintenance and Troubleshooting」

在本章的各节中,我们将介绍「应用级别」和「集群级别」的维护。
我们还将从多个角度介绍「故障排除」,包括调试pod和容器,测试服务的连接性,解读资源的状态,以及节点维护。
最后我们还将介绍如何使用etcd,即 Kubernetes的控制层面的存储组件。
本章主要面向集群管理员和应用开发人员。
12.2. Removing a Pod from a Service
对于定义良好并由几个pod支持的服务(请参阅5.1节),如果其中一个pod出现了问题,如何将这个pod从访问点列表中移除,以便稍后再进行检查?
可以使用–overwrite-参数重新标记该pod,通过该参数可以改写pod上run命令的标签。通过改写标签,可以确保该pod不会被服务选择器(请参阅5.1节)选中,并从访问点列表中移除该pod同时,负责监视pod的副本集会发现一个pod消失不见了,从而启动一个新的副本。
(1)首先使用 kubectl run(参阅4.4节)生成一个简单的部署: kubectl run nginx –image nginx –replicas 4
(2)当查看pod时,请注意观察字段run中显示的标签,你会看到有4个pod的值为 nginx (run=nginx是 kubectl run命令自动生成的标签):

# kubectl get pods -Lrun

(3)然后为这个部署建立一个服务并查看访问点(每个访问点对应于各自的podIP地址):

# kubectl expose deployments nginx –port 80
# kubectl get endpoints

(4)接下来,可以通过一个简单的命令将第一个pod从服务列表中删除:

# kubectl label pods “nginx-d5dc44cf7-5845r” run=notworking –overwrite

(!!!本质上就是修改了LABEL,使得Service不再选择该Pod!!!)
为了找到pod的IP地址,你可以通过JSON格式查看pod清单文件并运行一个 JQuery查询:

#kubectl get pods nginx-d5dc44cf7-5845r -o json | jq-r. status.podIP

一个新的标记为run=nginx的Pod出现在列表中, notworking的pod依然存在,但是不会再出现在服务访问点列表中:
12.3. Accessing a ClusterIP Service Outside the Cluster
如果内部服务[……]

READ MORE

「Kubernetes」- 使用DaemonSet时,主节点没有运行Pod实例

内容简介
处理「当使用DaemonSet时,没有在主节点创建Pod实例」问题。
问题描述
在以DaemonSet方式部署Traefik Ingress Controller之后,没有在Master节点上创建Pod实例。因此不能通过Master节点来访问服务,但是我们希望Master节点中也运行Pod实例。
经过一番Google查找,学习「Taints and Tolerations」文档。
问题原因(正常情况)
因为从1.6开始,不会再将DaemonSet调度到主节点上。由于主节点上有node-role.kubernetes.io/master及NoSchedule污点,而Pod没有容忍该污点,所以不会调度到主节点上。
!!!既然官方已经不建议这么做了,如果没有必要就不要向主机调度Pod了,除非是出于监控或者指标收集等原因。
解决办法(正常情况)
我参考了「Kubernetes ds won’t run pod on master node」与「Scheduler is not scheduling Pod for DaemonSet in Master node」这两个问题。
正确的解决办法其实是在DaemonSets的Pod定义中添加如下配置:

tolerations:
– key: node-role.kubernetes.io/master
effect: NoSchedule

问题原因(我的情况)
我的情况有点特殊:症状是常见的症状,但是成因却稍微有所不同。
因为在第一次遇到这个问题之后,由于不懂,我一顿搜索搜索之后,执行了kubectl taint nodes k8s-master key=value:NoSchedule与kubectl taint nodes –all node-role.kubernetes.io/master-命令。当执行第一条命令之后,将不会有Pod调度到主节点上。之后,执行第二条命令,虽然删除了node-role.kubernetes.io/master污点,但是依旧不能调度,因为Pod不能容忍第一个污点。
解决办法(我的情况)
不是常规成因,所以也不是常规的解决办法。
最后我也发现:由于之前的测试,在Master节点上添加了Taint的NoSchedule标记,从而导致后面创建的Pod示例无法调度到该节点上。因此去掉该Taint即可。(而最好的解决办法是把Master的node-role.kubernetes.io/master污点还给人家,然后运行正常的解决办法。)
注意事项
由于主节点具有一定的特殊性,出于安全及角色的原因,其实不建议在Master节点上运行Pod实例。[……]

READ MORE

「Kubernetes」- etcd-k8scp-01

[……]

READ MORE

「Kubernetes」- 无法从主节点访问 NodePort 服务

# 10/01/2019 我们首次遇见该问题 # 05/08/2021 从那以后我们未再遇到该问题,当时是因为 Docker 的版本过旧(完全能够这样理解)。如果再次遇到该问题,很可能是因为其他原因导致的; # 04/14/2022 我们再次遇到类似问题,除了 Pod 所在节点能够通过 NodePort 访问,而无法从其他节点通过 NodePort 访问;
问题描述
定义 Deployment 资源,定义 Service 资源,并且 Selector 与 Label 都是正确的。启动 Service 的 NodePort 为 32340 端口。
正常结果:在正常情况下,不管是通过 Master 还是 Node 节点,都可以访问 NodePort 服务。
问题状况:我们无法通过 Master 节点的 IP 地址来访问 NodePort 服务。通过 http://node-address:32340/ 正常访问服务,但是通过 http://master-address:32340/ 只会得到超时。
系统环境
CentOS Linux release 7.5.1804 (Core) Docker version 1.13.1, build b2f74b2/1.13.1 Kubernetes v1.14.0
原因分析
这个问题已经有人遇到过了:Handle nodes with iptables FORWARD DROP better #39823
这个问题是由 Docker 导致的。如「vendor libnetwork \@1861587 #28257」所述: 1)如果 net.ipv4.ip_forward=1 参数是由 Docker 所设置,则 iptables 的 FORWARD 会被设置为 DORP 策略。 2)如果是由用户设置 net.ipv4.ip_forward=1 参数,则用户可能会进行某些意图需要 FORWARD 为 ACCEPT 策略,这时候 Docker 就不会去修改 FORWARD 策略。
解决办法
设置 net.ipv4.ip_forward=1 参数:

cat > /etc/sysctl.d/99-ipv4_forward.conf <<EOF
net.ipv4.ip_forward=1
EOF

sysctl –load=/etc/sysctl.d/99-ipv4_forward.conf

虽然我们用的是 Docker CE 版本,但是 moby 是 Docker 的”始祖“,并且那个 PR 已经合并到 Docker CE 了,所以上面的修改才生效。
相关链接
Kubernetes/Tasks/Debu[……]

READ MORE

「KUBERNETES-TROUBLESHOOT」- kube-controller-manager

[……]

READ MORE

「Kubernetes」- kube-scheduler-k8scp-01

当将节点加入集群时,主节点的 kube-scheduler-k8scp-01 发生重启。日志如下:

I0408 10:23:44.110342 1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::client-ca-file
I0408 10:23:44.110368 1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::client-ca-file
I0408 10:23:44.110404 1 configmap_cafile_content.go:202] Starting client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file
I0408 10:23:44.110424 1 shared_informer.go:240] Waiting for caches to sync for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file
I0408 10:23:44.209318 1 shared_informer.go:247] Caches are synced for RequestHeaderAuthRequestController
I0408 10:23:44.209532 1 leaderelection.go:243] attempting to acquire leader lease kube-system/kube-scheduler…
I0408 10:23:44.210501 1 shared_informer.go:247] Caches are synced for client-ca::kube-system::extension-apiserver-authentication::requestheader-client-ca-file
I0408 10:23:44.210578 1 shared_informer.go:247] Caches are synced for client-ca::kube-system::exten[……]

READ MORE

「Kubernetes Troubleshoot」- 删除 CRD 资源

删除 CRD 资源
kubeless – Not able to completely remove Kubernetes CustomResource – Stack Overflow Custom resources with finalizers can “deadlock” customresourcecleanup.apiextensions.k8s.io finalizer · Issue #60538 · kubernetes/kubernetes
问题描述:部分 CRD 资源无法删除
原因分析:

So it turns out , the root cause was that Custom resources with finalizers can “deadlock”. The CustomResource “functions.kubeless.io” had a

Finalizers:
customresourcecleanup.apiextensions.k8s.io

and this is can leave it in a bad state when deleting.

https://github.com/kubernetes/kubernetes/issues/60538

解决方案:类似 Workaround 方案

# kubectl –kubeconfig /tmp/config get customresourcedefinitions.apiextensions.k8s.io | grep cattle

for i in $(kubectl –kubeconfig /tmp/config get customresourcedefinitions.apiextensions.k8s.io 2>/dev/null | grep cattle | awk ‘{print $1}’)
do
echo “# ———— $i ”
kubectl –kubeconfig /tmp/config patch crd/${i} -p ‘{“metadata”:{“finalizers”:[]}}’ –type=merge
kubectl –kubeconfig /tmp/config delete customresourcedefinitions.apiextensions.k8s.io ${i}
done[……]

READ MORE

「Kubernetes Debugging」- node XXX already cordoned

在执行 kubectl drain node1 –ignore-daemonsets 剔除节点时卡住
参考文献
When you try to drain a Kubernetes node but it blocks ?[……]

READ MORE

「Kubernetes」- Namespace 卡在 Terminating 状态

解决方案

# kubectl get namespace <terminating-namespace> -o json >tmp.json

{
“apiVersion”: “v1”,
“kind”: “Namespace”,
“metadata”: {
“creationTimestamp”: “2018-11-19T18:48:30Z”,
“deletionTimestamp”: “2018-11-19T18:59:36Z”,
“name”: “<terminating-namespace>”,
“resourceVersion”: “1385077”,
“selfLink”: “/api/v1/namespaces/<terminating-namespace>”,
“uid”: “b50c9ea4-ec2b-11e8-a0be-fa163eeb47a5”
},
“spec”: {
“finalizers”: []
},
“status”: {
“phase”: “Terminating”
}
}

kubectl proxy

curl -k -H “Content-Type: application/json” -X PUT –data-binary @tmp.json http://127.0.0.1:8001/api/v1/namespaces/<terminating-namespace>/finalize

临时记录
删除其他资源:

kubectl -n rook-ceph patch cephclusters.ceph.rook.io rook-ceph -p ‘{“metadata”:{“finalizers”: []}}’ –type=merge

参考文献
A namespace is stuck in the Terminating state – IBM Documentation rook-ceph stuck in Terminating state : unable to delete · Issue #2668 · rook/rook · GitHub[……]

READ MORE