记一次 controller manager and scheduler 重复重启问题分析

 首先发现的报错讯息:

 Aug 10 15:43:53 hetu-fr-2d kubelet[1586]: E0810 15:43:53.135619    1586 controller.go:178] failed to update node lease, error: Put https://kapi-xxx-xx:6443/apis/coordination.k8s.io/v1/namespaces/kube-node-lease/leases/node02?timeout=10s: read tcp 192.168.111.104:35660->192.168.111.100:6443: read: connection reset by peer

 Aug 10 15:43:53 hetu-fr-2d kubelet[1586]: E0810 15:43:53.135619    1586 controller.go:178] failed to update node lease, error: Put https://kapi-xxx-xx:6443/apis/coordination.k8s.io/v1/namespaces/kube-node-lease/leases/node02?timeout=10s: read tcp 192.168.111.104:35660->192.168.111.100:6443: read: connection reset by peer

然后看k8s组件有重启现象

 看apiserver的日志,发现有可能是etcd的问题,

 查这个报错:watch chan error: etcdserver: mvcc: required revision has been compacted,有可能是因为ectd压缩问题,可能涉及磁盘

etcd is the Kubernetes’ backing store for all cluster data, it has a history compaction mechanism to avoid performance degradation and eventual storage space exhaustion, here are some docs on etcd repo.

"watch chan error: etcdserver: mvcc: required revision has been compacted" literally means the watched revision is compacted. This is working as designed, when attempts to re-establish a watch from a resourceVersion that is no longer available would prompt the caller to re-list objects and obtain a new current resourceVersion to watch from..

For your comment "and When I perform "kubectl get cs" it shows "unknown" both etcd and kube-controller-manager and kube-scheduler ", what does that mean? Could you paste the output of "kubectl get cs" here?

看etcd日志:"msg":"leader failed to send out heartbeat on time; took too long, leader is overloaded likely from slow disk"

Aug 11 18:00:02 etcd-1 etcd[1592]: {"level":"warn","ts":"2021-08-11T18:00:02.888+0800","caller":"etcdserver/raft.go:390","msg":"leader failed to send out heartbeat on time; took too long, leader is overloaded likely from slow disk","to":"566bb4bcdc8f3e93","heartbeat-interval":"100ms","expected-duration":"200ms","exceeded-duration":"18.959836ms"}

报错信息主要为:

心跳检测报错主要与以下因素有关(磁盘速度、cpu性能和网络不稳定问题):

  • etcd使用了raft算法,leader会定时地给每个follower发送心跳,如果leader连续两个心跳时间没有给follower发送心跳,etcd会打印这个log以给出告警。通常情况下这个issue是disk运行过慢导致的,leader一般会在心跳包里附带一些metadata,leader需要先把这些数据固化到磁盘上,然后才能发送。写磁盘过程可能要与其他应用竞争,或者因为磁盘是一个虚拟的或者是SATA类型的导致运行过慢,此时只有更好更快磁盘硬件才能解决问题。etcd暴露给Prometheus的metrics指标walfsyncduration_seconds就显示了wal日志的平均花费时间,通常这个指标应低于10ms。

  • 第二种原因就是CPU计算能力不足。如果是通过监控系统发现CPU利用率确实很高,就应该把etcd移到更好的机器上,然后通过cgroups保证etcd进程独享某些核的计算能力,或者提高etcd的priority。

  • 第三种原因就可能是网速过慢。如果Prometheus显示是网络服务质量不行,譬如延迟太高或者丢包率过高,那就把etcd移到网络不拥堵的情况下就能解决问题。但是如果etcd是跨机房部署的,长延迟就不可避免了,那就需要根据机房间的RTT调整heartbeat-interval,而参数election-timeout则至少是heartbeat-interval的5倍。

可能是超时了,检查下etcd的配置,为默认100ms,报错显示都大于100ms

于是准备调整etcd 配置的参数重启etcd试试

加上这俩参数:
心跳保持时间
heartbeat-interval: 1000
选举超时的时间
election-timeout: 10000

附录etcd 的推荐配置以及说明

!!!注:参数key: value中key之后":" 与value之间必须有一个空格
 
 
 
#[Member]
# This is the configuration file for the etcd server.
 
# Human-readable name for this member.
#含义:此成员的名称。
#默认值:default
#环境变量:ETCD_NAME
#作用:此配置值作为此节点在--initial-cluster标志中列出的条目(例如,default=http://localhost:2380)引用。
#      若使用静态引导,则需要匹配标志中使用的密钥。使用发现时,每个成员必须具有唯一的名称。
#      建议使用Hostname或者machine-id。
#注意:使用发现时,每个成员必须具有唯一的名称。
name: 'ptest01'
 
# Path to the data directory.
#含义:服务运行数据保存的路径。
#默认值:${name}.etcd
#环境变量:ETCD_DATA_DIR
#作用:设置数据保存的目录。
data-dir: /data/db/etcd
 
# Path to the dedicated wal directory.
#含义:专用wal目录的路径。
#默认值:--data-dir的路径下
#环境变量:ETCD_WAL_DIR
#作用:独立设置wal目录,etcd会将WAL文件写入--wal-dir而不是--data-dir。独立的wal路径,有助于避免日志记录和其他IO操作之间的竞争。
wal-dir: /data/log/etcd
 
# Number of committed transactions to trigger a snapshot to disk.
#含义:触发快照到磁盘的已提交事务数。
#默认值:100000
#环境变量:ETCD_SNAPSHOT_COUNT
#作用:指定有多少事务(transaction)被提交时,触发截取快照保存到磁盘。
snapshot-count: 10000
 
# Time (in milliseconds) of a heartbeat interval.
#含义:心跳间隔的时间(以毫秒为单位)
#默认值:100
#环境变量:ETCD_HEARTBEAT_INTERVAL
#作用:leader 多久发送一次心跳到 followers。
heartbeat-interval: 1000
 
# Time (in milliseconds) for an election to timeout.
#含义:选举超时的时间(以毫秒为单位)
#默认值:1000
#环境变量:ETCD_ELECTION_TIMEOUT
#作用:重新投票的超时时间,如果 follow 在该时间间隔没有收到心跳包,会触发重新投票,默认为 1000 ms。
election-timeout: 10000
 
# Raise alarms when backend size exceeds the given quota. 0 means use the
# default quota.
#含义:当后端大小超过给定配额时(0默认为低空间配额),引发警报。
#默认值:0
#环境变量:ETCD_QUOTA_BACKEND_BYTES
quota-backend-bytes: 0
 
# List of comma separated URLs to listen on for peer traffic.
#含义:和成员之间通信的地址。
#默认值:http://localhost:2380
#环境变量:ETCD_LISTEN_PEER_URLS
#作用:用于监听其他etcd member的url
#提示:域名为无效值,如http://example.com:2380为错误配置。
listen-peer-urls: http://10.122.48.232:2380
 
# List of comma separated URLs to listen on for client traffic.
#含义:对外提供服务的地址
#默认值:http://localhost:2379
#环境变量:ETCD_LISTEN_CLIENT_URLS
#作用:对外提供服务的地址。
#提示:域名为无效值,如http://example.com:2379为错误配置。
listen-client-urls: "http://10.122.48.232:2379,https://127.0.0.1:2379"
 
# Maximum number of snapshot files to retain (0 is unlimited).
#含义:要保留的最大快照文件数(0表示不受限制)。
#默认值:5
#环境变量:ETCD_MAX_SNAPSHOTS
#作用:
#提示:Windows上的用户默认值不受限制,建议手动清除至5。
max-snapshots: 0
 
# Maximum number of wal files to retain (0 is unlimited).
#含义:要保留的最大wal文件数(0表示不受限制)。
#默认值:5
#环境变量:ETCD_MAX_WALS
#作用:
#提示:Windows上的用户默认值不受限制,建议手动清除至5。
max-wals: 0
 
# Comma-separated white list of origins for CORS (cross-origin resource sharing).
#含义:逗号分隔的CORS原始白名单(跨源资源共享)
#默认值:
#环境变量:ETCD_CORS
cors:
 
#[Clustering]
# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
#含义:该节点成员对等URL地址,且会通告群集的其余成员节点。
#默认值:http://localhost:2380
#环境变量:ETCD_INITIAL_ADVERTISE_PEER_URLS
#作用:
initial-advertise-peer-urls: http://10.122.48.232:2380
 
# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
#含义:此成员的客户端URL列表,用于通告群集的其余部分。这些URL可以包含域名。
#默认值:http://localhost:2379
#环境变量:ETCD_ADVERTISE_CLIENT_URLS
#作用:对外公告的该节点客户端监听地址。
advertise-client-urls: http://10.122.48.232:2379
 
# Discovery URL used to bootstrap the cluster.
#含义:用于引导群集的发现URL。
#默认值:
#环境变量:ETCD_DISCOVERY
#作用:
discovery:
 
# Valid values include 'exit', 'proxy'
#含义:发现服务失败时的预期行为(“退出”或“代理”)。“proxy”仅支持v2 API。
#默认值:proxy
#环境变量:ETCD_DISCOVERY_FALLBACK
#作用:
discovery-fallback: 'proxy'
 
# HTTP proxy to use for traffic to discovery service.
#含义:用于流量到发现服务的HTTP代理。
#默认值:
#环境变量:ETCD_DISCOVERY_PROXY
#作用:
discovery-proxy:
 
# DNS domain used to bootstrap initial cluster.
#含义:DNS srv域用于引导群集。
#默认值:
#环境变量:ETCD_DISCOVERY_SRV
#作用:
discovery-srv:
 
# Initial cluster configuration for bootstrapping.
#含义:集群中所有节点的信息。
#默认值:default=http://localhost:2380
#环境变量:ETCD_INITIAL_CLUSTER
#作用:
#注意:此处default为节点的--name指定的名字;localhost:2380为--initial-advertise-peer-urls指定的值。
initial-cluster: "ptest01=http://10.122.48.232:2380,ptest02=http://10.122.48.233:2380,ptest03=http://10.122.48.234:2380"
 
# Initial cluster token for the etcd cluster during bootstrap.
#含义:创建集群的 token,这个值每个集群保持唯一。
#默认值:etcd-cluster
#环境变量:ETCD_INITIAL_CLUSTER_TOKEN
#作用:此配置可使重新创建集群,即使配置和之前一样,也会再次生成新的集群和节点 uuid;否则会导致多个集群之间的冲突,造成未知的错误。
initial-cluster-token: 'p-etcd-cluster'
 
# Initial cluster state ('new' or 'existing').
#含义:初始集群状态
#默认值:new
#环境变量:ETCD_INITIAL_CLUSTER_STATE
#作用:设置new为初始静态或DNS引导期间出现的所有成员。如果将此选项设置为existing,则etcd将尝试加入现有群集。
initial-cluster-state: 'new'
 
# Reject reconfiguration requests that would cause quorum loss.
#含义:拒绝可能导致仲裁丢失的重新配置请求。
#默认值:false
#环境变量:ETCD_STRICT_RECONFIG_CHECK
#作用:
strict-reconfig-check: false
 
# Accept etcd V2 client requests
#含义:接受etcd V2客户端请求
#默认值:true
#环境变量:ETCD_ENABLE_V2
#作用:
#2.3 代理相关标识
#提示:--proxy配置etcd以在代理模式下运行,“proxy”仅支持v2 API。
enable-v2: true
 
# Enable runtime profiling data via HTTP server
#含义:通过HTTP服务器启用运行时分析数据。地址位于客户端URL+"/debug/pprof/"
#默认值:false
#环境变量:
#作用:
enable-pprof: true
 
# Valid values include 'on', 'readonly', 'off'
#含义:代理模式设置,("off", "readonly" or "on")
#默认值:off
#环境变量:ETCD_PROXY
#作用:
proxy: 'off'
 
# Time (in milliseconds) an endpoint will be held in a failed state.
#含义:在重新考虑代理请求之前,endpoints 将处于失败状态的时间(以毫秒为单位)。
#默认值:5000
#环境变量:ETCD_PROXY_FAILURE_WAIT
#作用:
proxy-failure-wait: 5000
 
# Time (in milliseconds) of the endpoints refresh interval.
#含义:endpoints 刷新间隔的时间(以毫秒为单位)。
#默认值:30000
#环境变量:ETCD_PROXY_REFRESH_INTERVAL
#作用:
proxy-refresh-interval: 30000
 
# Time (in milliseconds) for a dial to timeout.
#含义:拨号超时的时间(以毫秒为单位)或0表示禁用超时
#默认值:1000
#环境变量:ETCD_PROXY_DIAL_TIMEOUT
#作用:
proxy-dial-timeout: 1000
 
# Time (in milliseconds) for a write to timeout.
#含义:写入超时的时间(以毫秒为单位)或0以禁用超时。
#默认值:5000
#环境变量:ETCD_PROXY_WRITE_TIMEOUT
#作用:
proxy-write-timeout: 5000
 
# Time (in milliseconds) for a read to timeout.
#含义:读取超时的时间(以毫秒为单位)或0以禁用超时。
#默认值:0
#环境变量:ETCD_PROXY_READ_TIMEOUT
#作用:
proxy-read-timeout: 0
 
#[Security]
client-transport-security:
  # Path to the client server TLS cert file.
  #含义:客户端服务器TLS证书文件的路径。
  #默认值:
  #环境变量:ETCD_CERT_FILE
  #作用:
  cert-file:
 
  # Path to the client server TLS key file.
  #含义:客户端服务器TLS密钥文件的路径。
  #默认值:
  #环境变量:ETCD_KEY_FILE
  #作用:
  key-file:
 
  # Enable client cert authentication.
  #含义:启用客户端证书验证。
  #默认值:false
  #环境变量:ETCD_CLIENT_CERT_AUTH
  #作用:
  client-cert-auth: false
 
  # Path to the client server TLS trusted CA cert file.
  #含义:客户端服务器的路径TLS可信CA证书文件。
  #默认值:
  #环境变量:ETCD_TRUSTED_CA_FILE
  #作用:
  trusted-ca-file:
 
  # Client TLS using generated certificates
  #含义:客户端TLS使用生成的证书
  #默认值:false
  #环境变量:ETCD_AUTO_TLS
  #作用:
  auto-tls: false
 
peer-transport-security:
  # Path to the peer server TLS cert file.
  #含义:对等服务器TLS证书文件的路径。这是对等流量的证书,用于服务器和客户端。
  #默认值:
  #环境变量:ETCD_PEER_CERT_FILE
  #作用:
  cert-file:
 
  # Path to the peer server TLS key file.
  #含义:对等服务器TLS密钥文件的路径。这是对等流量的关键,用于服务器和客户端。
  #默认值:
  #环境变量:ETCD_PEER_KEY_FILE
  #作用:
  key-file:
 
  # Enable peer client cert authentication.
  #含义:启用对等客户端证书验证。
  #默认值:false
  #环境变量:ETCD_PEER_CLIENT_CERT_AUTH
  #作用:
  client-cert-auth: false
 
  # Path to the peer server TLS trusted CA cert file.
  #含义:对等服务器TLS可信CA文件的路径。
  #默认值:
  #环境变量:ETCD_PEER_TRUSTED_CA_FILE
  #作用:
  trusted-ca-file:
 
  # Peer TLS using generated certificates.
  #含义:Peer TLS使用自动生成的证书
  #默认值:false
  #环境变量:ETCD_PEER_AUTO_TLS
  #作用:
  auto-tls: false
 
# Enable debug-level logging for etcd.
#含义:将所有子包的默认日志级别设置为DEBUG。
#默认值:false(所有包的INFO)
#环境变量:ETCD_DEBUG
#作用:
debug: false
 
含义:将单个etcd子包设置为特定的日志级别。一个例子是etcdserver=WARNING,security=DEBUG
默认值:(所有包的INFO)
环境变量:ETCD_LOG_PACKAGE_LEVELS
作用:
log-package-levels: 'etcdserver=ERROR,security=DEBUG,auth=ERROR'
 
#含义:为结构化日志记录指定'zap'或'capnslog'。
#默认值:capnslog
#环境变量:ETCD_LOGGER
#作用:
logger: zap
 
# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
#含义:指定'stdout'或'stderr'以跳过日志记录,即使在systemd或逗号分隔的输出目标列表下运行也是如此。
#默认值:default
#环境变量:ETCD_LOG_OUTPUT
#作用:
log-outputs: [stderr]
 
# Force to create a new one member cluster.
#含义:强制创建新的单成员群集。它提交配置更改,强制删除集群中的所有现有成员并添加自身。需要将其设置为还原备份。
#默认值:false
#环境变量:ETCD_FORCE_NEW_CLUSTER
#作用:
force-new-cluster: false
 
#含义:说明--auto-compaction-retention配置的基于时间保留的三种模式:periodic, revision. periodic
#默认值:periodic
#环境变量:ETCD_AUTO_COMPACTION_MODE
#作用:
auto-compaction-mode: periodic
 
#含义:在一个小时内为mvcc键值存储的自动压实保留。0表示禁用自动压缩。
#默认值:0
#环境变量:ETCD_AUTO_COMPACTION_RETENTION
#作用:
auto-compaction-retention: "1"
 
# Auth flags
auth-token-ttl: 3600000

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值