0
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?

ConsulでDNSが解決できないけど、digは通るとき

Posted at

はじめに

今回は、ConsulのDNSについて紹介します。やや備忘録的に、または誰かの知見になればと思い、残します。

やりたいこと

以下を実現したい。

サービスA:Pythonのflaskで、APIを公開。healthメソッドを公開する
サービスB:ConsulのDNSを使用して、サービスAのAPIをコールしたい

課題

digは通るが、curlが通らない。

# NOERRORで大丈夫
dig @localhost -p 8600 a.service.consul

しかし、curlがDNSを解決できない。

curl http://a.service.consul:5000/health
結果
curl: (6) Could not resolve host: a.service.consul

解決策

dig +shortでIPだけ取得できる。

dig +short @localhost -p 8600 a.service.consul
結果
172.18.0.4

つまり、以下が成立する。

curl http://$(dig +short @localhost -p 8600 a.service.consul):5000/health

考察

  • この方法は、たぶん正攻法ではないです
  • DNSの設定を何か失敗していると思います。急ぎで修正するための突貫だと思ってください

余談

Dockerコンテナのインスタンスを動的にスケールするような場面では、IPアドレスもダイナミックに割り当てられるため、サービスメッシュは欠かせません。私は、自宅に子サーバーを何台か設置し、親サーバーで集権的に管理したかったので、Consulのサービスメッシュが必要でした。DNSだけならConsul不要じゃないか...という気もしますが、ツール自体の勉強も兼ねてConsulを使用しました。

まとめ

いかがだったでしょうか。今回は、なぜかdigは通っているのに、curlがDNSを解決できない場合の(裏技的な)解決方法を紹介しました。

このように、consulやterraformといったインフラ周りのツール紹介から、Unity, AWS, 量子コンピューティングなど、幅広いジャンルを取り扱っています。お役に立てましたら、いいね, フォローなどよろしくお願いします!!

0
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
0
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?