美文网首页Docker&Kubernetes
kubernetes(K8S)性能与监控

kubernetes(K8S)性能与监控

作者: 一个小运维 | 来源:发表于2021-07-07 08:54 被阅读0次

    部署metrics-server

    开启apiserver聚合服务
    [root@master ~]# vim /etc/kubernetes/manifests/kube-apiserver.yaml
    # spec.containers.command 最下面手动添加如下一行
        - --enable-aggregator-routing=true
    [root@master ~]# systemctl restart kubelet
    [root@master ~]# kubectl -n kube-system get pod kube-apiserver-master -o yaml |grep enable-aggregator-routing
        - --enable-aggregator-routing=true
    
    证书的申请与签发

    要在所有节点执行(master,node-0001,node-0002,node-0003)

    申请的多余证书可以使用 (kubectl delete certificatesigningrequests 证书名称) 删除

    [root@node-0001 ~]# vim /var/lib/kubelet/config.yaml
    # 在文件的最后一行添加
    serverTLSBootstrap: true
    [root@node-0001 ~]# systemctl restart kubelet
    #-------------------------签发证书必须在 master 上执行 ------------------------------------
    [root@master ~]# kubectl get certificatesigningrequests
    NAME        AGE   REQUESTOR            CONDITION
    csr-wsfz7   8s    system:node:master   Pending
    [root@master ~]# kubectl certificate approve csr-wsfz7
    [root@master ~]# kubectl get certificatesigningrequests
    NAME        AGE   REQUESTOR            CONDITION
    csr-wsfz7   86s   system:node:master   Approved,Issued
    
    安装mertics插件
    [root@master metrics]# docker load -i metrisc-server.tar.gz
    [root@master metrics]# docker tag gcr.io/k8s-staging-metrics-server/metrics-server:master 192.168.1.100:5000/metrics-server:master
    [root@master metrics]# docker push 192.168.1.100:5000/metrics-server:master
    [root@master metrics]# vim deployment.yaml
    29: image: 192.168.1.100:5000/metrics-server:master
    [root@master metrics]# kubectl apply -f rbac.yaml
    [root@master metrics]# kubectl apply -f pdb.yaml
    [root@master metrics]# kubectl apply -f deployment.yaml
    [root@master metrics]# kubectl apply -f service.yaml
    [root@master metrics]# kubectl apply -f apiservice.yaml
    #-------------------------------- 查询验证 ----------------------------------------------
    [root@master metrics]# kubectl -n kube-system get pod
    NAME                              READY   STATUS    RESTARTS   AGE
    metrics-server-78dfb54777-4dcjl   1/1     Running   0          116s
    [root@master metrics]# kubectl -n kube-system get apiservices
    NAME                                   SERVICE                      AVAILABLE   AGE
    v1beta1.metrics.k8s.io                 kube-system/metrics-server   True        2m20s
    [root@master metrics]# kubectl top node
    NAME        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
    master      95m          4%     840Mi           48%       
    node-0001   24m          1%     266Mi           15%       
    node-0002   24m          1%     270Mi           15%       
    node-0003   26m          1%     280Mi           16%   
    

    监控容器资源利用率

    [root@master ~]# kubectl apply -f myapache.yaml 
    deployment.apps/myapache created
    [root@master ~]# kubectl top pod
    error: metrics not available yet
    # 等待大约 30 秒
    [root@master ~]# kubectl top pod
    NAME                       CPU(cores)   MEMORY(bytes)   
    myapache-7d689bf8f-lfr5h   0m           0Mi   
    [root@master ~]# curl http://10.244.2.17/info.php?id=5000000
    <pre>
    Array
    (
        [REMOTE_ADDR] => 10.244.0.0
        [REQUEST_METHOD] => GET
        [HTTP_USER_AGENT] => curl/7.29.0
        [REQUEST_URI] => /info.php?id=5000000
        [id] => 5000000
    )
    php_host:   myapache-7d689bf8f-lfr5h
    [root@master ~]# kubectl top pod
    NAME                       CPU(cores)   MEMORY(bytes)   
    myapache-7d689bf8f-w4rtt   1000m        8Mi  
    [root@master ~]# 
    

    相关文章

      网友评论

        本文标题:kubernetes(K8S)性能与监控

        本文链接:https://www.haomeiwen.com/subject/wkdgultx.html