Bobcares

Kubectl top Node “Metrics API Not Available” Error in Amazon EKS

by | Dec 12, 2024

Learn how to fix Kubectl top Node “Metrics API Not Available” error in Amazon EKS. Our Kubernetes Support team is here to help you with your questions and concerns.

Kubectl top Node “Metrics API Not Available” Error in Amazon EKS

Kubectl top Node "Metrics API Not Available" Error in Amazon EKSRecently, one of our customers ran into the “Metrics API not available” error after running these commands:

kubectl apply -f metrics-server.yaml
kubectl top node

According to our experts, this error occurs when the Kubernetes Metrics Server is either not running or is inaccessible.

The Kubernetes Metrics Server is critical for collecting and serving resource metrics.

The `kubectl top` command uses the Kubernetes Metrics API to display real-time CPU and memory usage statistics. However, in Amazon EKS clusters, the Metrics API may not be available by default or may not be configured properly.

An Overview:

Common Causes of the Error

  1. In many EKS clusters, the Metrics Server is not deployed by default, making it impossible for `kubectl top` to retrieve metrics.
  2. Incorrect configurations can prevent the Metrics Server from collecting data or communicating with the Kubernetes API server.
  3. Misconfigured RBAC can block the Metrics Server from accessing the required node and pod data.
  4. Security groups, firewalls, or network policies may restrict communication between the Metrics Server and cluster components.
  5. Older Kubernetes versions or custom EKS configurations might face compatibility challenges with the Metrics Server.

Steps to Troubleshoot and Resolve

  1. If the Metrics Server is missing, install it manually:

    kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
    This command deploys the Metrics Server with its default configuration.

  2. Amazon EKS often requires specific configurations for the Metrics Server. So, modify its deployment to include EKS-compatible flags by opening the Metrics Server deployment:

    kubectl edit deployment metrics-server -n kube-system

    Then, add the following flags under `spec.containers.args`:

    --kubelet-preferred-address-types=InternalIP
    --kubelet-insecure-tls

    These flags ensure the Metrics Server uses internal IPs for communication and bypass TLS verification.

  3. Next, ensure the Metrics Server is deployed and running:

    kubectl get deployment metrics-server -n kube-system

    Check that the deployment status shows as AVAILABLE. Additionally, confirm that no pods are in a `CrashLoopBackOff` or `Error` state:

    kubectl get pods -n kube-system | grep metrics-server

  4. If the Metrics Server pods are not functioning as expected, review their logs for errors:

    kubectl logs -n kube-system -l k8s-app=metrics-server

  5. Also, ensure the Metrics Server has the required RBAC permissions. Apply the following configuration if needed:


    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
    name: metrics-server:system:auth-delegator
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: system:auth-delegator
    subjects:
    - kind: ServiceAccount
    name: metrics-server
    namespace: kube-system

  6. After verifying the Metrics Server setup, test its functionality:

    kubectl top nodes
    kubectl top pods

    If configured correctly, these commands will display resource usage metrics. If the error persists, the server might still be initializing or require further adjustments.

  7. Finally, verify that the network policies, security groups, or firewall rules allow communication between the Metrics Server and Kubernetes nodes and adjust these settings as necessary.

Additional Tips

  1. After deploying or restarting the Metrics Server, give it a few minutes to initialize.
  2. Use `kubectl logs` to analyze any underlying errors related to the Metrics Server.
  3. If `kubectl top nodes` fails, use `kubectl top pods` to check resource usage for individual pods.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Following these steps, we can resolve the “Metrics API not available” error and ensure our EKS cluster provides accurate resource metrics for effective monitoring and management.

In brief, our Support Experts demonstrated how to fix the Kubectl top Node “Metrics API Not Available” error in Amazon EKS.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF