Kubernetes API Server如何启用性能分析

Kubernetes
问题描述

对 Kubernetes APIserver 进行优化的时候,需要查看其性能指标,如何开启性能指标分析。

问题分析

Kubernetes APIserver 提供了参数,可以确定是否开启了性能分析。

问题解决

1.查看是否开启用性能分析

ps aux |grep kube-apiserver |grep profiling
# output:(显示为空即为默认开启)

2.安装go

$ wget -P /usr/local/src/ https://go.dev/dl/go1.17.5.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.17.5.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin

3.开启代理

$ kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'

4.查看

$ go tool pprof http://192.168.0.170:8001/debug/pprof/heap
Fetching profile over HTTP from http://192.168.0.170:8001/debug/pprof/heap
Saved profile in /root/pprof/pprof.kube-apiserver.alloc_objects.alloc_space.inuse_objects.inuse_space.006.pb.gz
File: kube-apiserver
Type: inuse_space
Time: Mar 4, 2022 at 2:50pm (CST)
Entering interactive mode (type "help" for commands, "o" for options)

# 进入交互界面后,输入top 20查看内存使用前20的函数调用
(pprof) top 20   
Showing nodes accounting for 80.29MB, 64.17% of 125.12MB total
Dropped 265 nodes (cum <= 0.63MB)
Showing top 20 nodes out of 407
      flat  flat%   sum%        cum   cum%
   33.01MB 26.38% 26.38%    33.01MB 26.38%  k8s.io/kubernetes/vendor/go.uber.org/zap/zapcore.newCounters
    6.38MB  5.10% 31.48%     6.38MB  5.10%  k8s.io/kubernetes/vendor/google.golang.org/grpc/internal/transport.newBufWriter
    5.51MB  4.41% 35.89%     5.51MB  4.41%  regexp.onePassCopy
    4.50MB  3.60% 39.49%     5.50MB  4.40%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/schemaconv.(*convert).VisitKind
    4.07MB  3.25% 42.74%     4.07MB  3.25%  encoding/json.Marshal
    3.09MB  2.47% 45.22%     3.09MB  2.47%  bufio.NewReaderSize
    3.01MB  2.41% 47.62%     3.01MB  2.41%  k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/server/mux.(*PathRecorderMux).trackCallers
    2.51MB  2.00% 49.63%     6.51MB  5.20%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/builder.(*openAPI).buildOperations
    2.50MB  2.00% 51.63%     2.50MB  2.00%  reflect.mapassign
       2MB  1.60% 53.23%        2MB  1.60%  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1.(*FieldsV1).Unmarshal
       2MB  1.60% 54.83%        3MB  2.40%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/builder.(*openAPI).toSchema
    1.53MB  1.22% 56.05%     1.53MB  1.22%  bytes.makeSlice
    1.52MB  1.21% 57.26%     1.52MB  1.21%  k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/storage/cacher.NewCacherFromConfig
    1.51MB  1.20% 58.47%     8.01MB  6.41%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/builder.(*openAPI).buildPaths
    1.50MB  1.20% 59.67%     1.50MB  1.20%  encoding/json.(*decodeState).literalStore
    1.50MB  1.20% 60.87%     1.50MB  1.20%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/handler.PruneDefaultsSchema
    1.08MB  0.87% 61.73%     1.08MB  0.87%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/aggregator.mergeSpecs
    1.04MB  0.83% 62.56%     1.04MB  0.83%  k8s.io/kubernetes/vendor/google.golang.org/protobuf/internal/strs.(*Builder).AppendFullName
    1.01MB  0.81% 63.37%     1.01MB  0.81%  k8s.io/kubernetes/vendor/github.com/beorn7/perks/quantile.newStream
       1MB   0.8% 64.17%        1MB   0.8%  regexp/syntax.(*compiler).inst
(pprof)

如果您有其他问题,欢迎您联系火山引擎技术支持服务

50
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论