kubecost / kubectl-cost

CLI for determining the cost of Kubernetes workloads
Apache License 2.0
924 stars 60 forks source link

kubecost cost cli predict fails on 2.2.x #172

Open dazmc opened 5 months ago

dazmc commented 5 months ago

Kubecost Version

2.2.5

Kubernetes Version

1.28

Kubernetes Platform

EKS

Description

kubectl plugin for kubecost (aka cost) errors when executing predict subcommand.

EKS 1.28.8 kubecost UI Version 2.2.5 (c0726bff) kubectl cost version info Git Commit: d675760 Git Branch: HEAD Git State: clean Git Summary: v0.6.2 Build Date: 2024-03-19T16:32:10Z

if i use the yaml example here

read -r -d '' DEF << EndOfMessage
 apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: nginx-deployment
   namespace: default
   labels:
     app: nginx
 spec:
   replicas: 3
   selector:
     matchLabels:
       app: nginx
   template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       - name: nginx
         image: nginx:1.14.2
         resources:
           requests:
             cpu: "3"
             memory: "2Gi"
 EndOfMessage
 echo "$DEF" | kubectl cost predict -f -

 Error: Failed querying the speccost API. This API requires a version of Kubecost >= 1.101, which may be why this query failed. If running Kubecost v1.100, you can downgrade kubectl cost to v0.4 for old-style prediction. Error: failed to port forward query: received non-200 status code 502 and data: <html>
 <head><title>502 Bad Gateway</title></head>
 <body>
 <center><h1>502 Bad Gateway</h1></center>
 <hr><center>nginx/1.25.5</center>
 </body>
 </html>

Steps to reproduce

  1. Deploy kubecost version 2.2.5
  2. Install cost plugin - kubectl krew install cost
  3. Use predict subcommand
    read -r -d '' DEF << EndOfMessage
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: nginx-deployment
    namespace: default
    labels:
     app: nginx
    spec:
    replicas: 3
    selector:
     matchLabels:
       app: nginx
    template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       - name: nginx
         image: nginx:1.14.2
         resources:
           requests:
             cpu: "3"
             memory: "2Gi"
    EndOfMessage
    echo "$DEF" | kubectl cost predict -f -

Expected behavior

It should work

 OBJECT                      Δ QTY  RESOURCE UNIT  COST PER UNIT    Δ COST/MO  % CHANGE 
────────────────────────────────────────────────────────────────────────────────────────
 default deployment             +9  CPU cores          23.27 USD  +209.47 USD           
 nginx-deployment                                                                       
                                +6  RAM GiB             3.12 USD   +18.72 USD           

────────────────────────────────────────────────────────────────────────────────────────
 TOTAL MONTHLY COST CHANGE                                        +228.18 USD           

But it doesn't

Error: Failed querying the speccost API. This API requires a version of Kubecost >= 1.101, which may be why this query failed. If running Kubecost v1.100, you can downgrade kubectl cost to v0.4 for old-style prediction. Error: failed to port forward query: received non-200 status code 502 and data: <html>
 <head><title>502 Bad Gateway</title></head>
 <body>
 <center><h1>502 Bad Gateway</h1></center>
 <hr><center>nginx/1.25.5</center>
 </body>
 </html>

Impact

We want to use kubectl cost predict subcommand as part of CI/CD process this hinders end to end benefit of kubecost. Monitoring and adjusting what has already been deployed works, but blocking it being created in the first place fails.

Using version 1.x is not a valid approach

Screenshots

No response

Logs

No response

Slack discussion

https://kubecost.slack.com/archives/CE76NJE6S/p1717166927611369?thread_ts=1717166927.611369&cid=CE76NJE6S

Troubleshooting

chipzoller commented 5 months ago

cc @AjayTripathy and @teevans. Do we intend to keep this extension up-to-date?

cliffcolvin commented 2 months ago

@dazmc will include this in my eng ticket with related gh issue. Will get you an update soon.

dazmc commented 1 week ago

@cliffcolvin any update on this?

cliffcolvin commented 1 week ago

@dazmc https://github.com/kubecost/kubectl-cost/issues/176#issuecomment-2378980993 I've added this to the ticket so that I can understand why we have a need for 3d of data before offering this data, but I'm assuming it was in the original design. I would say she used kubecost 2.4 (use 2.4.3) which does have many other issues fixed between your version and that. Let me know if it works for you after and I'll update the ticket on our side.

dazmc commented 6 days ago

@cliffcolvin no problem. I generate kubecost environments for very short periods 8-10 hrs to showcase the deployment and initial building of kubecost and some basic features.

So I am ok, ideally I would like this to work straight away but if the answer is 3 days then as long as I know I am okay with that