首页 > 其他分享 >分析kube-apiserver单次创建namespace耗时

分析kube-apiserver单次创建namespace耗时

时间:2024-02-21 23:45:03浏览次数:42  
标签:k8s namespace apt apiserver io docker kube config

日志输出

# 业务日志
I0220 22:12:39.149364   40965 multi_config_multi_clientset.go:63] begin to wait cache sync
I0220 22:12:39.250461   40965 multi_config_multi_clientset.go:67] wait cache sync end
I0220 22:12:39.256440   40965 multi_config_multi_clientset.go:90] create ns test success
I0220 22:12:39.256459   40965 multi_config_multi_clientset.go:92] cost time 5 ms

# kube-apiserver日志
I0220 22:12:39.252062   40933 handler.go:153] kube-aggregator: POST "/api/v1/namespaces" satisfied by nonGoRestful
I0220 22:12:39.252216   40933 pathrecorder.go:253] kube-aggregator: "/api/v1/namespaces" satisfied by NotFoundHandler
I0220 22:12:39.252234   40933 handler.go:143] kube-apiserver: POST "/api/v1/namespaces" satisfied by gorestful with webservice /api/v1
I0220 22:12:39.255738   40933 httplog.go:89] "HTTP" verb="POST" URI="/api/v1/namespaces" latency="3.902358ms" userAgent="test/v0.0.0 (linux/amd64) kubernetes/$Format" srcIP="192.168.0.105:57696" resp=201
I0220 22:12:39.263293   40933 shared_informer.go:270] caches populated

不足以确定详细流程,后面通过kube-apiserver和etcd tracing来分析。

安装k8s v1.27.0

准备

查看k8s v1.27.0镜像版本
kubeadm config images list --kubernetes-version=v1.27.0

registry.k8s.io/kube-apiserver:v1.27.0
registry.k8s.io/kube-controller-manager:v1.27.0
registry.k8s.io/kube-scheduler:v1.27.0
registry.k8s.io/kube-proxy:v1.27.0
registry.k8s.io/pause:3.9
registry.k8s.io/etcd:3.5.7-0
registry.k8s.io/coredns/coredns:v1.10.1

安装Docker

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

# Add Docker's official GPG key:
apt-get update
apt-get install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update

apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

安装k8s

cat <<EOF | kind create cluster --config -
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  image: kindest/node:v1.27.0
- role: worker
  image: kindest/node:v1.27.0
EOF

启动分布式追踪UI jaeger容器

docker run -d --name jaeger \
  --network host \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.43

配置kube-apiserver

vim /etc/kubernetes/pki/apitracing-config.yaml
apiVersion: apiserver.config.k8s.io/v1beta1
kind: TracingConfiguration
endpoint: <JaegerIP:4317>
samplingRatePerMillion: 100000

特性门控APIServerTracing从1.27开始默认是true。

kube-apiserver启动参数增加--tracing-config-file=/etc/kubernetes/pki/apitracing-config.yaml

配置etcd

etcd启动参数增加
--experimental-distributed-tracing-address=<JaegerIP:4317>
--experimental-distributed-tracing-service-name=etcd
--experimental-enable-distributed-tracing=true

获取kind k8s的kubeconfig文件

kubectl config view --raw

打开jaeger页面查看

业务日志

etcd耗时很少,主要时间花费在kube-apiserver。

参考资料

https://blog.csdn.net/DaoCloud_daoke/article/details/131174429

 

标签:k8s,namespace,apt,apiserver,io,docker,kube,config
From: https://www.cnblogs.com/WJQ2017/p/18026428

相关文章

  • KubeSphere 镜像构建器(S2I)服务证书过期解决方案
    目前KubeSphere所有3.x.x版本,如果开启了DevOps模块并使用了镜像构建器功能(S2I)都会遇到证书过期问题。解决方法已开启DevOps模块下载这个更新S2I服务证书压缩包,上传到任一可以访问K8s集群的节点;把上传的压缩包解压进入解压后的目录执行更新证书的脚本./update......
  • 云原生周刊:在 Kubernetes 集群中使用通配符证书 | 2024.2.19
    开源项目推荐kube-fledgedkube-fledged是一个KubernetesOperator,用于直接在Kubernetes集群的工作节点上创建和管理容器映像的缓存。它允许用户定义图像列表以及这些图像应缓存(即拉取)到哪些工作节点上。因此,应用程序Pod几乎立即启动,因为不需要从注册表中提取映像。kube-f......
  • "浅尝"Kubernetes
    kubernetesGoogle旗下的容器跨主机编排工具,占据了80%以上的市场份额,已经成为容器编排工具的事实标准,简称K8S。K8S与docker的区别:ansible#应用级别的跨主机编排工具docker#容器引擎容器运行时dockerfile#构建镜像docker-swarm#docker旗下的容器跨主机编排工具,是实现......
  • Kubernetes (K8S) 一
    K8Sansible#应用级别的跨主机编排工具docker#容器引擎容器运行时dockerfile#构建镜像docker-compose#单机容器集群编排工具docker-swarm#Docker旗下的容器跨主机编排工具,是实现在多级上Docker容器集群管理调度的工具mosos|marathonmosos:分布式资......
  • kubernetes创建的ingress规则不生效
    kubernetes创建的ingress规则不生效解决方法一:给创建ingress的yaml文件添加ingressClassName参数:​ 查看ingressclass[root@k8s-master012-4]#kubectlgetingressclassNAMECONTROLLERPARAMETERSAGEnginxk8s.io/ingress-nginx<none>22h......
  • kubespray部署kubernetes集群【转】
    kubespray部署kubernetes集群1、kubespray简介Kubespray是开源的部署生产级别Kubernetes集群的项目,它整合了Ansible作为部署的工具。可以部署在AWS,GCE,Azure,OpenStack,vSphere,Packet(Baremetal),OracleCloudInfrastructure(Experimental)或Baremetal上。高可用集群可组......
  • 二机制安装Kubernetes 1.29 高可用集群(5)--node节点配置
    1.1所有k8s-node节点安装cri-dockerrpm-ivhcri-dockerd-0.3.10-3.el8.x86_64.rpm1.2修改cri-docker启动文件,将默认的pod启动镜像地址修改为国内仓库源#vi/usr/lib/systemd/system/cri-docker.service将如下部分ExecStart=/usr/bin/cri-dockerd--container-runtime-en......
  • 二机制安装Kubernetes 1.29 高可用集群(4)--master节点配置
    1.1在k8s-master01上解压kubernetes可执行文件到/usr/local/bin目录tar-zxfkubernetes-server-linux-amd64.tar.gz--strip-components=3-C/usr/local/binkubernetes/server/bin/kube{let,ctl,-apiserver,-controller-manager,-scheduler,-proxy}注:--strip-components=3......
  • 二机制安装Kubernetes 1.29 高可用集群(3)--etcd集群配置
    1.在所有etcd节点解压安装包tar-zxfetcd-v3.5.12-linux-amd64.tar.gzcpetcd-v3.5.12-linux-amd64/etcd/usr/local/bin/&&cpetcd-v3.5.12-linux-amd64/etcdctl/usr/local/bin/#查看版本信息#etcdctlversionetcdctlversion:3.5.12APIversion:3.52.1在所有et......
  • 二机制安装Kubernetes 1.29 高可用集群(2)--haproxy节点配置
    1.1在所有haproxy节点安装haproxyyum-yinstallhaproxy1.2在所有haproxy节点创建haproxy配置文件cat>/etc/haproxy/haproxy.cfg<<EOFglobalmaxconn3000ulimit-n16384log127.0.0.1local0errstatstimeout30sde......