LoginSignup
18
10

2023/06/22 更新: VPN問題は解決した様です。

VPNで問題になっていた以下のIssueがクローズになってます。

Windows(10 Pro 22H2)環境下でも以下の手順でVPN利用してもnerdctlでコンテナがrun出来ました。

  • Rancher Desktop v1.9.0 をインストール
  • Rancher DesktopのGUIからFactory Resetを実施して環境をリセット
  • Rancher DesktopのGUIからPreferences > WSL > Proxy にあるようにVPN利用時に使うProxyを設定

Enjoy!

以下は当時の記事


会社PCのローカル環境で何かしら開発する際に困るのがProxy…。
Rancher Desktop を使う際にも同様にハマったのでその回避方法を紹介。

おそらく、Docker Desktopにも関連するのでProxy周りで困っていれば参考になるかも?

前提

  • Rancher Desktop 1.1.1
    • CLIはdockerではなく、nerdctlを利用
  • 確認環境
    • Ubuntu 20.04.4 LTS
    • macOS Catalina 10.15.7

現象

状況説明

環境変数にはproxyの設定済み。

$ env | grep proxy
https_proxy=http://proxy.example.com:8080
http_proxy=http://proxy.example.com:8080
no_proxy=127.0.0.1,localhost,registry.example.com

クライアント設定も以下の通り設定している。

$ cat ~/.docker/config.json
{
    :
	"proxies": {
		"default": {
			"httpProxy": "http://proxy.example.com:8080/",
			"httpsProxy": "http://proxy.example.com:8080/",
			"noProxy": "127.0.0.1,localhost,registry.example.com"
		}
	}
}

Proxyを設定しているはずなのに何故かうまく行かないコマンドたち

💀レジストリにlogin出来ない

$ nerdctl login --debug registry.example.com
Enter Username: yassan
Enter Password:
 :
FATA[0038] failed to call rh.Client.Do: Get "https://registry.example.com/v2/": dial tcp 203.0.113.23:443: i/o timeout

💀イメージがpull出来ない

$ nerdctl pull --debug registry.example.com/monitoring/base-kafka-aggregator:0.0.1
 :
FATA[0030] failed to resolve reference "registry.example.com/monitoring/base-kafka-aggregator:0.0.1": failed to do request: Head "https://registry.example.com/v2/monitoring/base-kafka-aggregator/manifests/0.0.1": dial tcp 203.0.113.23:443: i/o timeout

💀イメージのbuildが出来ない

$ nerdctl build --debug --namespace k8s.io \
  --build-arg http_proxy=http://proxy.example.com:8080 \
  --build-arg https_proxy=http://proxy.example.com:8080 \
  --build-arg no_proxy=127.0.0.1,localhost,registry.example.com \
  -t kafka-access-log:0.0.1 -f docker/kafka-access-log.Dockerfile .
 :
error: failed to solve: registry.example.com/monitoring/base-kafka-aggregator:0.0.1: failed to do request: Head "https://registry.example.com/v2/monitoring/base-kafka-aggregator/manifests/0.0.1": dial tcp 203.0.113.23:443: i/o timeout
FATA[0030] unrecognized image format

203.0.113.23registry.example.comのIPアドレス

何がいけなかったのか?🤔

いずれも dial tcp 203.0.113.23:443: i/o timeout となっていて、プライベートレジストリとの通信に失敗しているのがポイント。この手のパターンはProxyな事が多々あります。

ただ、環境変数もクライアント設定にもProxyの設定があるのになぜうまく行かないのか?

では何がいけなかったのか見ていきます。

(しくじりポイント その1)Rancher DesktopのProxyの設定ポイントが違う😩

下図の通り、Rancher Desktopは Lima といLinux VMを利用しています(Windowsの場合は、Hyper-VというVM)。
その影響でProxyなどの設定がホスト側ではなく、Rancher Desktopの設定として設定しなければいけないのです。

how-it-works-rancher-desktop

https://rancherdesktop.io/ より引用

参考: Proxy variables not set in alpine VM /etc/environment · Issue #1267 · rancher-sandbox/rancher-desktop

Docker Desktopの場合は、GUIにProxyの設定1がResourcesのNETWORKにありますが、今の所、Rancher Desktopにはありません。
そこで、以下のようにProxyの設定をいれます。

Rancher DesktopをメニューからExit選んで正しく停止して後、override.yamlを以下の様に作成

env:
  http_proxy: http://proxy.example.com:8080
  https_proxy: http://proxy.example.com:8080
  • Mac: ~/Library/Application Support/rancher-desktop/lima/_config/override.yaml
  • Ubuntu: ~/.local/share/rancher-desktop/lima/_config/override.yaml

ただし、Windowsは前述の通り、WSL2ではHyper-Vを使うので設定するポイントも異なります。
未検証ですが、以下が参考になると思います(確認出来たら追記します)。
Rancher doesn't work on VPN / Corporate Proxy · Issue #995 · rancher-sandbox/rancher-desktop

(しくじりポイント その2)Proxyの指定はVPNのエンドポイントにしないとダメだった😩(但し、環境による)

実はProxyに設定していた proxy.example.com ですが、これは社内のサーバで利用するProxyサーバでした。
VPN利用して接続している場合、すべてのネットワークをVPNのエンドポイント(例えばVPN利用時に指定されているIPアドレスとやホスト。proxy.pacとかを指定するやつ)を経由する仕様にしていたので、Proxyには、VPNのエンドポイントを指定するのが正しいかったのです。

※社内ポリシーによりどういった仕様でVPNを構成しているのかによるので注意

(しくじりポイント その3)no_proxyの指定にプライベートレジストリなど社内のホストを入れてはダメ😩(但し、環境による)

その2と同様に「VPN利用して接続している場合、すべてのネットワークをVPNのエンドポイントを経由する」仕様であるので、no_proxyにプライベートレジストリや社内のホストを入れてしまうとProxyを経由しなくなるので入れてはダメ。

※社内ポリシーによりどういった仕様でVPNを構成しているのかによるので注意

補足

レジストリへのログインについて、dockerコマンドでは上記の対応をしても回避出来ませんでした。
特にdockerコマンドよりもnerdctlを使いたいので詳しくは調べてません。

さいごに

うっかりやらかして時間溶かしちゃったので、これで誰かの時間が少しでも溶かさずに済んだら幸いです。
Rancher Desktop良いよ。nerdctl使ってコンテナいじるだけであっても使うのはありだし、ローカルでKubernetes使うときもK3sが軽いのでPCリソースの消費も抑えられます。

  1. Windowsはこっち。Macはこっち

18
10
1

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
18
10