1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

k8sでAPIに対してfetchしたがInvalid URLエラーが出る

Last updated at Posted at 2024-04-05

はじめに

kubernetesの他のポッドで立てているAPIにリクエストするのにすこしはまったので一応書いておきます

問題

以下のようにfetchをjsで行いました

  const response = await fetch(`${process.env.HOST}/api/users/login`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },

ここでHOSTはdeploymentにvaluesで渡していました

values.yaml
HOST=hoge.hoge.svc.cluster.local

しかしfetchでエラーが出ました

TypeError: Invalid URL
    at new URL (node:internal/url:775:36)
    at new Request (/usr/src/app/node_modules/@remix-run/web-fetch/src/request.js:81:16)
    at /usr/src/app/node_modules/@remix-run/web-fetch/src/fetch.js:43:19
    at new Promise (<anonymous>)

解決方法

慣れないk8sなのでそもそも名前解決できてないのではと思っていましたが、よくエラーをみるとURL形式で怒られていました

つまりhttp://が存在していなかったのが問題でした

ちゃんとエラーをみていけばすぐ解決できました

おわりに

k8sにかなり慣れてきたので楽しくなってきました

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?