k8s问题汇总

作者前言

本文章为记录使用k8s遇到的问题和解决方法,文章持续更新中...


目录

正常配置ingress,但是访问错误

curl: (7) Failed connect to test.com:8080; Connection refused

bash 复制代码
在/etc/hosts加下记录
ip 域名

添加工作节点报错

error execution phase kubelet-start: error uploading crisocket: Unauthorized To see the stack trace

bash 复制代码
rm -rf $HOME/.kube/config
kubeadm reset

安装k8s报错

bash 复制代码
情况一:
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
[ERROR Port-10250]: Port 10250 is in use
[ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[preflight] If you know what you are doing, you can make a check non-fatal with --ignore-preflight-errors=...
To see the stack trace of this error execute with --v=5 or higher

先删除文件
rm -rf  /etc/kubernetes/kubelet.conf
rm -rf /etc/kubernetes/pki/ca.crt
lsof -i :10250 
kill -9 进程号


情况2:
[ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
rm -rf /var/lib/etcd

使用kubectl命令报错

bash 复制代码
The connection to the server 本机ip:6443 was refused - did you specify the right host or port?

排错思路
1、集群硬件时间和系统时间不同步
hwclock和data查看后修改

2、查看端口是否被占用或被防火墙拦截
netstat -antup | grep 端口号
firewalld --list-zones
iptables -nL

3、更改主机名了、重启服务器了
hostnamectl set-hostname 原名
重启kubelet服务

4、查看服务是否正常,重启服务
kubelet、containerd、docker等

container没有运行

bash 复制代码
container runtime is not running: output: time="2023-08-11T15:37:57+08:00" l

解决:
vim /etc/containerd/config.toml
#disabled_plugins = ["cri"]

安装会出现kubelet异常,无法识别

bash 复制代码
--node-labels 字段问题,原因如下。
将 --node-labels=node.kubernetes.io/node='' 替换为 --node-labels=node.kubernetes.io/node= 将 '' 删除

删除k8s集群

bash 复制代码
先停服
systemctl stop kubelet etcd docker containerd

卸载k8s
kubeadm reset -f

删除k8s相关目录
rm -rf ~/.kube/
rm -rf /etc/kubernetes/
rm -rf /etc/systemd/system/kubelet.service.d
rm -rf /etc/systemd/system/kubelet.service
rm -rf /usr/bin/kube*
rm -rf /etc/cni
rm -rf /opt/cni
rm -rf /var/lib/etcd
rm -rf /var/etcd

卸载k8s软件包
yum -y remove kubeadm-1.xxx kubelet-1.xxx kubectl-1.xxx 

更新yum源
yum clean all
yum -y update
yum makecache

访问dashboard报错

网页提示信息Client sent an HTTP request to an HTTPS server.

原因:

因为直接使用ip:端口的方式是http协议

解决方法:

访问需要加上https

https://ip:端口

如果还是无法访问提示此报错

原因:被浏览器安全阻拦了

点击页面空白处,键盘输入thisunsafe就可以正常连接了


k8s服务器重启后kubectl命令使用不了

bash 复制代码
重启前需要配置自启动
systemctl enable docker &&systemctl start docker 
systemctl enable kubelet && sytemctl start kubelet
systemctl enable containerd && sytemctl start containerd
systemctl daemon-reload

重启后kubectl命令不了,一般重启器kubelet服务就可以了
sytemctl restart kubelet

k8s手动卸载不干净

bash 复制代码
使用以下命令进行操作
kubeadm reset -f

kubectl get pods 失败

bash 复制代码
E0816 23:01:08.370695    3256 memcache.go:265] couldn't get current server API group list: Get "https://ip/api?timeout=32s": dial tcp ip:6443: connect: connection refused

查看kubelet服务状态
systemctl status kubelet
$KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

网上查阅后是k8s集群的版本问题,因为不小心升级了yum update
kubelet --version查看版本是1.28的,之前安装是1.25的

#解决方法,降级
查看包
rpm -qa | grep kube 
删除包
yum remove -y kubeadm-1.28.0-0.x86_64 kubernetes-cni-1.2.0-0.x86_64 kubectl-1.28.0-0.x86_64 kubelet-1.28.0-0.x86_64

yum install -y kubelet-1.25.0 kubeadm-1.25.0 kubectl-1.25.0
systemctl enable kubelet

再次kubectl get pods显示正常了

安装k8s加载内核模块报错

bash 复制代码
加载内核参数net.bridge.bridge-nf-call-ip6tables和net.bridge.bridge-nf-call-iptables
报错cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directoryfcannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory

#解决方法
modeprobe br_netfilter

相关推荐
富士康质检员张全蛋2 分钟前
云原生|kubernetes|kubernetes的etcd集群备份策略
云原生·kubernetes·etcd
慧一居士17 分钟前
Kubernetes 中kind类型和各类型详细配置完整示例介绍
云原生·kubernetes·yaml配置
云手机管家2 小时前
CDN加速对云手机延迟的影响
运维·服务器·网络·容器·智能手机·矩阵·自动化
孤的心了不冷2 小时前
【Docker】CentOS 8.2 安装Docker教程
linux·运维·docker·容器·eureka·centos
头疼的程序员3 小时前
docker学习与使用(概念、镜像、容器、数据卷、dockerfile等)
学习·docker·容器
淡水猫.3 小时前
hbit资产收集工具Docker(笔记版)
运维·docker·容器
水淹萌龙8 小时前
k8s 中使用 Service 访问时NetworkPolicy不生效问题排查
云原生·容器·kubernetes
alden_ygq11 小时前
K8S cgroups详解
容器·贪心算法·kubernetes
旧故新长12 小时前
访问 Docker 官方镜像源(包括代理)全部被“重置连接”或超时
运维·docker·容器
matrixlzp12 小时前
K8S Gateway AB测试、蓝绿发布、金丝雀(灰度)发布
kubernetes·gateway·ab测试