CentOS Stream 9
Sponsored Link

Kubernetes : Metrics Server の設定2023/10/20

 
Metrics Server を設定して、Kubernetes クラスターの CPU/メモリー リソースのメトリクスを収集/監視します。
当例では以下のように 4 台のノードを使用して Kubernetes クラスターを構成しています。
+----------------------+   +----------------------+
|   [ mgr.srv.world ]  |   |   [ dlp.srv.world ]  |
|     Manager Node     |   |     Control Plane    |
+-----------+----------+   +-----------+----------+
        eth0|10.0.0.25             eth0|10.0.0.30
            |                          |
------------+--------------------------+-----------
            |                          |
        eth0|10.0.0.51             eth0|10.0.0.52
+-----------+----------+   +-----------+----------+
| [ node01.srv.world ] |   | [ node02.srv.world ] |
|     Worker Node#1    |   |     Worker Node#2    |
+----------------------+   +----------------------+

[1] Metrics Server を設定します。
[root@mgr ~]#
git clone https://github.com/kubernetes-sigs/metrics-server

[root@mgr ~]#
vi ./metrics-server/manifests/base/deployment.yaml
.....
.....
      containers:
      - name: metrics-server
        image: gcr.io/k8s-staging-metrics-server/metrics-server:master
        imagePullPolicy: IfNotPresent
        args:
          - --cert-dir=/tmp
          - --secure-port=10250
          - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
          - --kubelet-use-node-status-port
          - --metric-resolution=15s
          # 29行目 : 追記
          - --kubelet-insecure-tls

[root@mgr ~]#
kubectl apply -k ./metrics-server/manifests/base/

serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created

[root@mgr ~]#
kubectl get pods -n kube-system

NAME                                       READY   STATUS    RESTARTS   AGE
calico-kube-controllers-57758d645c-ws2gd   1/1     Running   4          26h
calico-node-6cxp9                          0/1     Running   4          26h
calico-node-8cdds                          1/1     Running   4          25h
calico-node-p7t9r                          1/1     Running   4          25h
coredns-5dd5756b68-rn87g                   1/1     Running   4          27h
coredns-5dd5756b68-zmsks                   1/1     Running   4          27h
etcd-dlp.srv.world                         1/1     Running   4          27h
kube-apiserver-dlp.srv.world               1/1     Running   4          27h
kube-controller-manager-dlp.srv.world      1/1     Running   6          27h
kube-proxy-486n6                           1/1     Running   4          25h
kube-proxy-5w2fk                           1/1     Running   4          25h
kube-proxy-ktlgl                           1/1     Running   4          27h
kube-scheduler-dlp.srv.world               1/1     Running   4          27h
metrics-server-5b948694c5-ztl6d            1/1     Running   0          79s
# [metrics-server] pod が新規にデプロイされる
[2] Control Plane ノードで Firewalld を有効にしている場合は、BGP (Border Gateway Protocol) ポートの許可が必要です。
[root@dlp ~]#
firewall-cmd --add-port=179/tcp

success
[root@dlp ~]#
firewall-cmd --runtime-to-permanent

success
[3] CPU や メモリー の使用状況は以下のように確認できます。
[root@mgr ~]#
kubectl top node

NAME               CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
dlp.srv.world      105m         1%     1383Mi          8%
node01.srv.world   21m          0%     735Mi           9%
node02.srv.world   27m          0%     868Mi           5%

[root@mgr ~]#
kubectl top pod

NAME                         CPU(cores)   MEMORY(bytes)
test-nginx-f5c579c7d-kt5jv   0m           7Mi
test-nginx-f5c579c7d-q5c6d   0m           7Mi
test-nginx-f5c579c7d-w2hvb   0m           11Mi
関連コンテンツ