openfaas / faas

OpenFaaS - Serverless Functions Made Simple
https://www.openfaas.com
MIT License
24.75k stars 1.92k forks source link

Function failed to deploy with status code: 500 #1831

Closed springCozyRock closed 5 months ago

springCozyRock commented 5 months ago

I was deploying my first python function with OpenFaas, but failed.

my environment: k3d + openFaas on Mac

What I've got --

beatles@xxxxxsMBP openfaas % faas-cli deploy -f ./cpu.yml          
Deploying: float-operation.
WARNING! You are not using an encrypted connection to the gateway, consider using HTTPS.

Is OpenFaaS deployed? Do you need to specify the --gateway flag?
Put "http://gateway.openfaas:8080/system/functions": dial tcp: lookup gateway.openfaas: no such host

Function 'float-operation' failed to deploy with status code: 500

I have checked stack overflow, and troubleshooting handbook, but still not work. Following are some information I got.

beatles@xxxxsMBP openfaas % faas-cli logs float-operation 
Cannot connect to OpenFaaS on URL: http://127.0.0.1:8080
beatles@xxxxMBP openfaas % kubectl get service -n openfaas

NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
alertmanager       ClusterIP   10.43.116.214   <none>        9093/TCP         15d
gateway-external   NodePort    10.43.191.86    <none>        8080:31112/TCP   15d
gateway            ClusterIP   10.43.216.241   <none>        8080/TCP         15d
nats               ClusterIP   10.43.163.95    <none>        4222/TCP         15d
prometheus         ClusterIP   10.43.131.242   <none>        9090/TCP         15d

I supposed it might be a gateway problem, but I don't know how it actually works. I also have checked @alexellis 's tutorial video, I saw he used -g https://openfaas.o6s.io but I don't know what this string supposed to be in my case?

springCozyRock commented 5 months ago

update: I am so excited that my error message changed! I was so depressed (even cried yesterday) these days because of my noncommittal program and something else~

so what I've done is digging in the reference of gateway. I found that to access ui (http://localhost:31112/ui/) before, I followed a tutorial on the internet, and port Forwarding from 127.0.0.1:31112 -> 8080, basically run --

kubectl port-forward svc/gateway -n openfaas 31112:8080 &
export OPENFAAS_URL=http://127.0.0.1:31112
echo $PASSWORD | faas-cli login --password-stdin

then I got the light, and tried faas-cli deploy -f ./cpu.yml --gateway=http://localhost:31112

the error message changed!!!!

beatles@xxxxxsMBP openfaas % faas-cli deploy -f ./cpu.yml --gateway=http://localhost:31112
Deploying: float-operation.

unauthorized access, run "faas-cli login" to setup authentication for this server

Function 'float-operation' failed to deploy with status code: 401

I suppose I almost succeed. Let me fix it, and I will close the issue.

springCozyRock commented 5 months ago

very easy then!!

beatles@xxxxxsMBP openfaas % faas-cli login --username admin --password=681d0e42c1506c260eba6cc73ad61b3330276302 --gateway=http://localhost:31112

WARNING! Using --password is insecure, consider using: cat ~/faas_pass.txt | faas-cli login -u user --password-stdin
Calling the OpenFaaS server to validate the credentials...
credentials saved for admin http://localhost:31112
beatles@xxxxxxsMBP openfaas % faas-cli deploy -f ./cpu.yml --gateway=http://localhost:31112
Deploying: float-operation.

Deployed. 202 Accepted.
URL: http://localhost:31112/function/float-operation

cheers!!!