<p>In order to apply Kubernetis for the first time as a backend developer of a startup, I looked for AWS' guide to EKS and found a good document and followed it.</p>
<p>The link to the guide is as follows.
<a href="https://aws-eks-web-application.workshop.aws/en/10-intro.html" rel="nofollow noreferrer">https://aws-eks-web-application.workshop.aws/en/10-intro.html</a></p>
<p>Here, I proceeded with the start with an AWS Account method on 2-1, and I'm omitting all the previous options.</p>
<p>ex. 5-2. (Option) Add Console Credential</p>
<p>In the initial attempt, we proceeded with the process with Option, because we continued to fail in the progress application stage and are trying new things.</p>
<p>All processes were easy until &quot;10-1. Apply HPA stage&quot;.</p>
<p>However, when I checked the HPA Status through the kubectl get hpa command, CPU usage was marked as unknown.</p>
<p>The guide said that if you try a little later, it will come out properly, so I tried it an hour later, but it was the same.</p>
<p>So, when I checked the status through the kubectl describe hpa command, I found that there was an error due to the missing cpu request as below.</p>
<pre><code>Name:                                                  demo-flask-backend-hpa
Namespace:                                             default
Labels:                                                &lt;none&gt;
Annotations:                                           &lt;none&gt;
CreationTimestamp:                                     Tue, 14 Sep 2021 09:03:53 +0000
Reference:                                             Deployment/demo-flask-backend
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  &lt;unknown&gt; / 30%
Min replicas:                                          1
Max replicas:                                          5
Deployment pods:                                       1 current / 0 desired
Conditions:
  Type           Status  Reason                   Message
  ----           ------  ------                   -------
  AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetResourceMetric  the HPA was unable to compute the replica count: failed to get cpu utilization: missing request for cpu
Events:
  Type     Reason                        Age   From                       Message
  ----     ------                        ----  ----                       -------
  Warning  FailedGetResourceMetric       5s    horizontal-pod-autoscaler  failed to get cpu utilization: missing request for cpu
  Warning  FailedComputeMetricsReplicas  5s    horizontal-pod-autoscaler  invalid metrics (1 invalid out of 1), first error is: failed to get cpu utilization: missing request for cpu
</code></pre>
<p>To solve this problem, we looked in many ways, but we haven't found a suitable solution because we still have little knowledge about Kubernetis.</p>
<p>The yaml setting files created so far are as follows.</p>
<p>All the instructions used in the Bashshell followed the guide, and there were no critical errors other than deprecated errors.</p>
<p>How could I solve this error?</p>
<hr />
<p><strong>flask-hpa.yaml</strong></p>
<pre><code>---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: demo-flask-backend-hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: demo-flask-backend
  minReplicas: 1
  maxReplicas: 5
  targetCPUUtilizationPercentage: 30
</code></pre>
<hr />
<p><strong>flask-deployment.yaml</strong></p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-flask-backend
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-flask-backend
  template:
    metadata:
      labels:
        app: demo-flask-backend
    spec:
      containers:
        - name: demo-flask-backend
          image: $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/demo-flask-backend:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          resources:
            requests:
              cpu: 250m
            limits:
              cpu: 500m
</code></pre>
<hr />
<p><strong>ingress.yaml</strong></p>
<pre><code>---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: &quot;backend-ingress&quot;
  namespace: default
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
    - http:
        paths:
          - path: /contents
            pathType: Prefix
            backend:
              service:
                name: &quot;demo-flask-backend&quot;
                port:
                  number: 8080
          - path: /services
            pathType: Prefix
            backend:
              service:
                name: &quot;demo-nodejs-backend&quot;
                port:
                  number: 8080
          - path: /
            pathType: Prefix
            backend:
              service:
                name: &quot;demo-frontend&quot;
                port:
                   number: 80
</code></pre>

Jun
<p>HPA works on the Metrics server data to scale POD or not.</p>
<pre><code>kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
</code></pre>
<p>installation : <a href="https://docs.aws.amazon.com/eks/latest/userguide/metrics-server.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/eks/latest/userguide/metrics-server.html</a></p>
<p>In AWS you have to install it first, which in GKE it's come already installed by default.</p>
<p><a href="https://aws.amazon.com/premiumsupport/knowledge-center/eks-metrics-server/" rel="nofollow noreferrer">https://aws.amazon.com/premiumsupport/knowledge-center/eks-metrics-server/</a></p>
<p>You can check if metrics server running or not using</p>
<pre><code>kubectl top pods
</code></pre>
<p>if output comes with resource usage your metrics server is up &amp; running, there is some another issue with HPA.</p>
