I am creating an upload file function for my website. When a user clicks upload then my web page will call API that has a function to upload the file into minIO node on my Kubernetes and store metadata of that file into cockroachDB node on my Kubernetes
Problem is when I test this on my local environment it works fine:
- (web URL:
http://localhost:5000
, API URL:http://localhost:8080/upload
)
but when I create pod and run it on Kubernetes it causes the error [503 service unavailable]
- (web URL:
https://[myWebName].com
, API URL:https://[myWebName].com/upload
)
After I try to debug this problem I know that cause of the problem is the code that I use to INSERT data into cockroachDB but I don't know how to fix this problem and I don't know why it works on my local environment but when it uploads it to Kubernetes this function causes the error.
function that cause problem:
func cockroachUpload(data Workspace ,w http.ResponseWriter){
//Work Fine
db, err := sql.Open("postgres",
"postgresql://root@128.199.248.147:31037/goliath?ssl=true&sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.root.key&sslcert=certs/client.root.crt")
if err != nil {
w.Write([]byte(err.Error()))
log.Fatal("error connecting to the database: ", err)
}
defer db.Close()
//cause error
query:="INSERT INTO workspace(name,permission) VALUES ($1,$2)"
rows, err := db.Query(query,"test",true)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
fmt.Println("done workspace")
}
PS: I use nodeport to connect to my minIO and CockroachDB service on my Kubernetes.